Search in sources :

Example 1 with NewItemHandler

use of com.vaadin.ui.AbstractSelect.NewItemHandler in project opennms by OpenNMS.

the class MibObjFieldFactory method createField.

/* (non-Javadoc)
     * @see com.vaadin.ui.TableFieldFactory#createField(com.vaadin.data.Container, java.lang.Object, java.lang.Object, com.vaadin.ui.Component)
     */
@Override
public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) {
    if (propertyId.equals("oid")) {
        final TextField field = new TextField();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.addValidator(new RegexpValidator("^\\.[.\\d]+$", "Invalid OID {0}"));
        return field;
    }
    if (propertyId.equals("instance")) {
        final ComboBox field = new ComboBox();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.setNullSelectionAllowed(false);
        field.setNewItemsAllowed(true);
        field.setNewItemHandler(new NewItemHandler() {

            @Override
            public void addNewItem(String newItemCaption) {
                if (!field.containsId(newItemCaption)) {
                    field.addItem(newItemCaption);
                    field.setValue(newItemCaption);
                }
            }
        });
        field.addItem("0");
        field.addItem("ifIndex");
        for (String rt : resourceTypes) {
            field.addItem(rt);
        }
        return field;
    }
    if (propertyId.equals("alias")) {
        final TextField field = new TextField();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.addValidator(new StringLengthValidator("Invalid alias. It should not contain more than 19 characters.", 1, 19, false));
        return field;
    }
    if (propertyId.equals("type")) {
        final TextField field = new TextField();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.addValidator(new // Based on NumericAttributeType and StringAttributeType
        RegexpValidator(// Based on NumericAttributeType and StringAttributeType
        "^(?i)(counter|gauge|timeticks|integer|octetstring|string)?\\d*$", "Invalid type {0}. Valid types are: counter, gauge, timeticks, integer, octetstring, string"));
        return field;
    }
    return null;
}
Also used : ComboBox(com.vaadin.ui.ComboBox) StringLengthValidator(com.vaadin.data.validator.StringLengthValidator) TextField(com.vaadin.ui.TextField) NewItemHandler(com.vaadin.ui.AbstractSelect.NewItemHandler) RegexpValidator(com.vaadin.data.validator.RegexpValidator)

Aggregations

RegexpValidator (com.vaadin.data.validator.RegexpValidator)1 StringLengthValidator (com.vaadin.data.validator.StringLengthValidator)1 NewItemHandler (com.vaadin.ui.AbstractSelect.NewItemHandler)1 ComboBox (com.vaadin.ui.ComboBox)1 TextField (com.vaadin.ui.TextField)1