Search in sources :

Example 1 with Field

use of com.vaadin.ui.Field in project opennms by OpenNMS.

the class UniqueAttributeNameValidatorTest method testOverriddenByField.

/**
     * We test that the values in the fieldMap are considered while validating the uniqueness of aliases.
     */
@Test
public void testOverriddenByField() {
    // simulate a user input in a text field bound to the MBeans only CompAttrib's CompMember (see method before/setUp)
    Field<String> dummyField = new TextField();
    dummyField.setValue("attrib1");
    CompMember compMember = selectionManager.getSelectedCompositeMembers(null).iterator().next();
    final Map<Object, Field<String>> fieldMap = new HashMap<>();
    fieldMap.put(compMember, dummyField);
    // Verify nameProvider
    NameProvider nameProvider = new DefaultNameProvider(selectionManager);
    List<String> names = new ArrayList<>(nameProvider.getNamesMap().values());
    Assert.assertNotNull(names);
    Collections.sort(names);
    Assert.assertTrue(Arrays.equals(new String[] { "attrib1", "compMem1", "compMem2" }, names.toArray(new String[names.size()])));
    // Verify validator
    UniqueAttributeNameValidator validator = new UniqueAttributeNameValidator(nameProvider, new UniqueAttributeNameValidator.FieldProvider() {

        @Override
        public Map<Object, Field<String>> getObjectFieldMap() {
            return fieldMap;
        }
    });
    names = validator.getNames();
    Assert.assertNotNull(names);
    Collections.sort(names);
    Assert.assertTrue(Arrays.equals(new String[] { "attrib1", "attrib1", "compMem2" }, names.toArray(new String[names.size()])));
    Assert.assertEquals(false, validator.isValid("attrib1"));
    Assert.assertEquals(true, validator.isValid("compMem2"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember) Field(com.vaadin.ui.Field) TextField(com.vaadin.ui.TextField) DefaultNameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider) NameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider) TextField(com.vaadin.ui.TextField) DefaultNameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Field

use of com.vaadin.ui.Field in project opennms by OpenNMS.

the class AttributesTable method modelChanged.

public void modelChanged(Item parentItem, Object parentData, SelectableBeanItemContainer<T> container) {
    try {
        blockValidation = true;
        if (getParentItem() == parentItem)
            return;
        setParentItem(parentItem);
        setParentData(parentData);
        // we initialize the tableFieldFactory because by default pagination is enabled, which
        // causes the table not to know all fields. But the validation is bound to a field, therefore
        // we need to create all fields in advance.
        aliasFieldsMap.clear();
        fields.clear();
        for (Object eachItemId : container.getItemIds()) {
            for (Object eachPropertyId : container.getContainerPropertyIds()) {
                Field<?> eachField = tableFieldFactory.createField(container, eachItemId, eachPropertyId, this);
                if (eachField != null) {
                    fields.put(computeKey(eachItemId, eachPropertyId), eachField);
                    if (MetaAttribItem.ALIAS.equals(eachPropertyId)) {
                        aliasFieldsMap.put(eachItemId, (Field<String>) eachField);
                        // we have to set this manually, otherwise validation does not work
                        Item item = container.getItem(eachItemId);
                        Property property = item.getItemProperty(eachPropertyId);
                        ((Field<String>) eachField).setValue((String) property.getValue());
                    }
                }
            }
        }
        setContainerDataSource(container);
        setVisibleColumns(MetaAttribItem.SELECTED, MetaAttribItem.NAME, MetaAttribItem.ALIAS, MetaAttribItem.TYPE);
        // enable/disable fields according to parent selection
        Property itemProperty = parentItem.getItemProperty(MBeansTree.MetaMBeansTreeItem.SELECTED);
        enableFields(fields.values(), (Boolean) itemProperty.getValue());
        if ((Boolean) itemProperty.getValue()) {
            updateCheckBoxes();
        }
        // we initially validate to ensure the ui is ok ant not in a broken state.
        // Only to allow this validation we have to do the initialization of the fields (See above) manually.
        // This is not ideal, but it seems to be the only way.
        validateFields(true);
    } finally {
        blockValidation = false;
    }
}
Also used : MetaAttribItem(org.opennms.features.vaadin.jmxconfiggenerator.data.MetaAttribItem) Item(com.vaadin.data.Item) Field(com.vaadin.ui.Field) TextField(com.vaadin.ui.TextField) Property(com.vaadin.data.Property)

Example 3 with Field

use of com.vaadin.ui.Field in project Activiti by Activiti.

the class FormPropertiesComponent method getFormPropertyValues.

/**
   * Returns all values filled in in the writable fields on the form.
   * 
   * @throws InvalidValueException when a validation error occurs.
   */
public Map<String, String> getFormPropertyValues() throws InvalidValueException {
    // Commit the form to ensure validation is executed
    form.commit();
    Map<String, String> formPropertyValues = new HashMap<String, String>();
    // Get values from fields defined for each form property
    for (FormProperty formProperty : formProperties) {
        if (formProperty.isWritable()) {
            Field field = form.getField(formProperty.getId());
            FormPropertyRenderer renderer = getRenderer(formProperty);
            String fieldValue = renderer.getFieldValue(formProperty, field);
            formPropertyValues.put(formProperty.getId(), fieldValue);
        }
    }
    return formPropertyValues;
}
Also used : Field(com.vaadin.ui.Field) HashMap(java.util.HashMap) FormProperty(org.activiti.engine.form.FormProperty)

Example 4 with Field

use of com.vaadin.ui.Field in project Activiti by Activiti.

the class FormPropertiesComponent method setFormProperties.

public void setFormProperties(List<FormProperty> formProperties) {
    this.formProperties = formProperties;
    form.removeAllProperties();
    // Clear current components in the grid
    if (formProperties != null) {
        for (FormProperty formProperty : formProperties) {
            FormPropertyRenderer renderer = getRenderer(formProperty);
            // Be able to get the Form from any Renderer.
            renderer.setForm(form);
            Field editorComponent = renderer.getPropertyField(formProperty);
            if (editorComponent != null) {
                // Get label for editor component.
                form.addField(formProperty.getId(), editorComponent);
            }
        }
    }
}
Also used : Field(com.vaadin.ui.Field) FormProperty(org.activiti.engine.form.FormProperty)

Aggregations

Field (com.vaadin.ui.Field)4 TextField (com.vaadin.ui.TextField)2 HashMap (java.util.HashMap)2 FormProperty (org.activiti.engine.form.FormProperty)2 Item (com.vaadin.data.Item)1 Property (com.vaadin.data.Property)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Test (org.junit.Test)1 MetaAttribItem (org.opennms.features.vaadin.jmxconfiggenerator.data.MetaAttribItem)1 DefaultNameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider)1 NameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider)1 CompMember (org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)1