Esempio n. 1
0
  /**
   * Instantiates a new collect field.
   *
   * @param caption the caption
   * @param groups the available groups
   */
  public CollectField(String caption, List<String> groups) {
    setCaption(caption);
    selectField.setRows(10);
    selectField.setLeftColumnCaption("Available");
    selectField.setRightColumnCaption("Selected");

    for (String group : groups) {
      selectField.addItem(group);
    }
  }
  void css(VerticalLayout layout) {
    // BEGIN-EXAMPLE: component.select.twincolselect.css
    // BOOK: components.selecting#twincolselect
    final TwinColSelect select = new TwinColSelect("Select Targets to Destroy");

    select.addStyleName("twincolselectexample");

    // Set the column captions (optional)
    select.setLeftColumnCaption("These are left");
    select.setRightColumnCaption("These are done for");

    // Put some data in the select
    String planets[] = {
      "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"
    };
    for (int pl = 0; pl < planets.length; pl++) select.addItem(planets[pl]);

    // Set the number of visible items
    select.setHeight("200px");
    select.setRows(6);

    // Set width by the number of character columns
    select.setColumns(10);

    // Preselect a few items
    HashSet<String> preselected = new HashSet<String>();
    Collections.addAll(preselected, "Venus", "Earth", "Mars");
    select.setValue(preselected);

    select.addListener(
        new Property.ValueChangeListener() {
          private static final long serialVersionUID = 6081009810084203857L;

          public void valueChange(ValueChangeEvent event) {
            System.out.println(event.getProperty().getType().getName());
            if (event.getProperty().getValue() != null)
              System.out.println(event.getProperty().getValue().getClass().getName());
          }
        });
    select.setImmediate(true);

    layout.addComponent(select);
    // END-EXAMPLE: component.select.twincolselect.css
  }