Advertisement
LaCaraDeLaVerga

Elegir Tags

Jun 30th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. package presentacion;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import com.vaadin.navigator.View;
  6. import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.HorizontalLayout;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.Notification;
  11. import com.vaadin.ui.Tree;
  12.  
  13. import domain.model.Campania;
  14.  
  15. import domain.model.Tag;
  16.  
  17. @SuppressWarnings("serial")
  18. public class ElegirTags extends HorizontalLayout implements View {
  19.     static final String NAME = "elegirTags";
  20.     ArrayList <String> tagsElegidos = new ArrayList();
  21.  
  22.     public ElegirTags() {
  23.         setSizeFull();
  24.         final HorizontalLayout layout = new HorizontalLayout();
  25.         Label titulo = new Label();
  26.         titulo.setCaption("Elija un tag para asociar a la campaña");
  27.  
  28.         // ********************************************************************************************
  29.         Tree tree = new Tree("Mi aplicación");
  30.  
  31.         // Creamos los nodos del árbol
  32.         tree.addItem("Arte");
  33.         tree.addItem("Ciencia");
  34.         tree.addItem("Deportes");
  35.         tree.addItem("Entretenimiento");
  36.         tree.addItem("Geografia");
  37.         tree.addItem("Historia");
  38.         tree.addItem("Medio Ambiente");
  39.         tree.addItem("Tecnologia");
  40.         tree.addItem("Politica");
  41.  
  42.         // ********************************************************************************************
  43.  
  44.         Button crearTag = new Button("Agregar Tag", new Button.ClickListener() {
  45.             @Override
  46.             public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
  47.                 if (tree.getValue() == null) {
  48.                     Notification.show("Atencion!", "Debe seleccionar un tag", Notification.Type.HUMANIZED_MESSAGE);
  49.                 } else {
  50.                     System.out.println(tree.getValue());
  51.                    
  52.                     agregarTagElegido(tree.getValue());
  53.                    
  54.                     Tag t = new Tag((String) tree.getValue());
  55.                     t.toString();
  56.                     System.out.println("soy" + t.toString());
  57.  
  58.                     tree.clear();
  59.                     Notification.show("LISTO", "Su Tag se ha agregado", Notification.Type.HUMANIZED_MESSAGE);
  60.                 }
  61.             }
  62.  
  63.             private void agregarTagElegido(Object value) {
  64.                
  65.                
  66.                 //       Codigo para evitar repetidos aqui  TODO
  67.                
  68.                 tagsElegidos.add((String) tree.getValue());
  69.             }
  70.         });
  71.  
  72.         Button volver = new Button("Volver a cracion de Campaña", new Button.ClickListener() {
  73.             @Override
  74.             public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
  75.                
  76.                
  77.                
  78.                
  79.                
  80.                
  81.                 getUI().getNavigator().navigateTo(CrearCampania.NAME);
  82.             }
  83.         });
  84.  
  85.         layout.setMargin(true);
  86.         layout.setSpacing(true);
  87.         layout.addComponent(titulo);
  88.         layout.addComponent(tree);
  89.         layout.addComponent(crearTag);
  90.         layout.addComponent(volver);
  91.  
  92.         addComponent(layout);
  93.     }
  94.  
  95.     // -----------------------------------------------
  96.  
  97.     @Override
  98.     public void enter(ViewChangeEvent event) {
  99.         // TODO Auto-generated method stub
  100.  
  101.     }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement