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"));
}
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;
}
}
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;
}
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);
}
}
}
}
Aggregations