Exemplo n.º 1
0
 /**
  * Modify available options based on the "geo department" select.
  *
  * @param currentGeoDepartment
  */
 private void filterDepartments(Department currentGeoDepartment) {
   if (currentGeoDepartment == null) {
     department.setValue(null);
     department.setEnabled(false);
   } else {
     container.removeAllContainerFilters();
     container.addContainerFilter(new Equal("parent", currentGeoDepartment));
     container.applyFilters();
     department.setValue(null);
     department.setEnabled(true);
   }
 }
  @Override
  protected void setup() {
    (getLayout()).setSpacing(true);

    ComboBox cb = getComboBox("A combobox", false);
    addComponent(cb);

    cb = getComboBox("A combobox with input prompt", false);
    cb.setInputPrompt("Please select");
    addComponent(cb);

    cb = getComboBox("A combobox with null item", true);
    addComponent(cb);

    cb = getComboBox("A combobox with null item and input prompt", true);
    cb.setInputPrompt("Please select");
    addComponent(cb);

    cb = getComboBox("A disabled combobox", true);
    cb.setEnabled(false);
    addComponent(cb);

    cb = getComboBox("A read-only combobox", true);
    cb.setReadOnly(true);
    addComponent(cb);

    cb = getComboBox("A combobox with filteringMode off", false);
    cb.setFilteringMode(FilteringMode.OFF);
  }
  @Override
  public void setInputEditView(boolean isEdit) {
    if (isEdit) {
      buttonUpdate.setVisible(true);
      buttonSubmit.setVisible(false);
      buttonReset.setVisible(false);
      inputGoodsSelect.setEnabled(false);
      layoutButtonNav.setVisible(false);

    } else {
      inputGoodsSelect.setEnabled(true);
      buttonUpdate.setVisible(false);
      buttonSubmit.setVisible(true);
      buttonReset.setVisible(true);
      layoutButtonNav.setVisible(true);
    }
  }
  /**
   * Instantiates a new include collection window.
   *
   * @param dataCollectionConfigDao the data collection configuration DAO
   * @param container the source list of elements
   * @param wrapper the current selected value
   */
  public IncludeCollectionWindow(
      final DataCollectionConfigDao dataCollectionConfigDao,
      final BeanItemContainer<IncludeCollectionWrapper> container,
      final IncludeCollectionWrapper wrapper) {

    setCaption("Include SystemDef/DataCollectionGroup");
    setModal(true);
    setWidth("400px");
    setHeight("180px");
    setResizable(false);
    setClosable(false);
    addStyleName(Runo.WINDOW_DIALOG);

    form.setImmediate(true);
    form.setWidth("100%");
    form.setWriteThrough(false);
    form.getLayout().setMargin(true);

    final ComboBox valueField = new ComboBox("Value");
    valueField.setEnabled(false);
    valueField.setRequired(true);
    valueField.setImmediate(true);
    valueField.setNewItemsAllowed(false);
    valueField.setNullSelectionAllowed(false);

    final ComboBox typeField = new ComboBox("Type");
    typeField.setRequired(true);
    typeField.setImmediate(true);
    typeField.setNewItemsAllowed(false);
    typeField.setNullSelectionAllowed(false);
    typeField.addItem(IncludeCollectionWrapper.DC_GROUP);
    typeField.addItem(IncludeCollectionWrapper.SYSTEM_DEF);
    typeField.addListener(
        new Property.ValueChangeListener() {
          @Override
          public void valueChange(Property.ValueChangeEvent event) {
            String selected = (String) typeField.getValue();
            if (selected == null) {
              return;
            }
            // Get available fields.
            // FIXME If a new dcGroup is added, DataCollectionConfigDao is not able to reach it.
            List<String> values =
                selected.equals(IncludeCollectionWrapper.SYSTEM_DEF)
                    ? dataCollectionConfigDao.getAvailableSystemDefs()
                    : dataCollectionConfigDao.getAvailableDataCollectionGroups();
            // Remove already selected
            for (IncludeCollectionWrapper obj : container.getItemIds()) {
              if (obj.getType().equals(selected)) {
                values.remove(obj.getValue());
              }
            }
            // Updating combo-box
            valueField.removeAllItems();
            for (String v : values) {
              valueField.addItem(v);
            }
            if (wrapper.getValue() != null) {
              valueField.addItem(wrapper.getValue());
            }
            valueField.setEnabled(valueField.getItemIds().size() > 1);
          }
        });

    form.setFormFieldFactory(
        new FormFieldFactory() {
          @Override
          public Field createField(Item item, Object propertyId, Component uiContext) {
            if (propertyId.equals("type")) return typeField;
            if (propertyId.equals("value")) return valueField;
            return null;
          }
        });

    okButton = new Button("Update");
    okButton.addListener(this);

    cancelButton = new Button("Cancel");
    cancelButton.addListener(this);

    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.addComponent(okButton);
    toolbar.addComponent(cancelButton);

    addComponent(form);
    addComponent(toolbar);

    ((VerticalLayout) getContent()).setComponentAlignment(toolbar, Alignment.BOTTOM_RIGHT);

    form.setItemDataSource(new BeanItem<IncludeCollectionWrapper>(wrapper));
  }