Search in sources :

Example 1 with FieldGroup

use of com.vaadin.data.fieldgroup.FieldGroup in project opennms by OpenNMS.

the class EventFormTest method testGroupField.

/**
     * Test the group field.
     *
     * @throws Exception the exception
     */
@Test
public void testGroupField() throws Exception {
    EventForm form = new EventForm();
    FieldGroup group = form.eventEditor;
    Field<?> uei = group.getField("uei");
    Assert.assertTrue(uei instanceof TextField);
    Assert.assertEquals("uei.opennms.org/newEvent", uei.getValue());
    Field<?> logMsgDest = group.getField("logmsg.dest");
    Assert.assertNotNull(logMsgDest);
    Assert.assertTrue(logMsgDest instanceof ComboBox);
    Assert.assertEquals(LogDestType.LOGNDISPLAY, logMsgDest.getValue());
    String eventUei = "uei.opennms.org/ietf/mplsTeStdMib/traps/mplsTunnelUp";
    Event event = dao.findByUei(eventUei);
    Assert.assertNotNull(event);
    form.setEvent(event);
    logMsgDest = group.getField("logmsg.dest");
    Assert.assertNotNull(logMsgDest);
    Assert.assertTrue(logMsgDest instanceof ComboBox);
    Assert.assertEquals(event.getLogmsg().getDest(), logMsgDest.getValue());
}
Also used : FieldGroup(com.vaadin.data.fieldgroup.FieldGroup) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Example 2 with FieldGroup

use of com.vaadin.data.fieldgroup.FieldGroup in project opennms by OpenNMS.

the class NameEditForm method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent changeEvent) {
    if (parameter != null) {
        try {
            blockListenerOrValidators = true;
            setData(changeEvent.getSelectedBean());
            setItemId(changeEvent.getSelectedItemId());
            final BeanItem beanItem = new BeanItem(changeEvent.getSelectedBean(), parameter.getEditablePropertyName(), parameter.getNonEditablePropertyName());
            // this is a hack, but we need to know if the selection changed
            beanItem.addItemProperty("selected", changeEvent.getSelectedItem().getItemProperty("selected"));
            captionLabel.setValue(String.format("<b>%s</b>", parameter.getCaption()));
            fieldGroup = new FieldGroup();
            fieldGroup.setBuffered(false);
            fieldGroup.bind(selectedField, "selected");
            fieldGroup.bind(editableField, parameter.getEditablePropertyName());
            fieldGroup.bind(nonEditableField, parameter.getNonEditablePropertyName());
            fieldGroup.setItemDataSource(beanItem);
            fieldGroup.getField(parameter.getNonEditablePropertyName()).setCaption(parameter.getNonEditablePropertyCaption());
            fieldGroup.getField(parameter.getNonEditablePropertyName()).setReadOnly(true);
            fieldGroup.getField(parameter.getEditablePropertyName()).setCaption(parameter.getEditablePropertyCaption());
            fieldGroup.getField(parameter.getEditablePropertyName()).setReadOnly(false);
            updateEnabledState();
            UIHelper.validateField(editableField, true);
        } finally {
            blockListenerOrValidators = false;
        }
    }
}
Also used : FieldGroup(com.vaadin.data.fieldgroup.FieldGroup) BeanItem(com.vaadin.data.util.BeanItem)

Aggregations

FieldGroup (com.vaadin.data.fieldgroup.FieldGroup)2 BeanItem (com.vaadin.data.util.BeanItem)1 ComboBox (com.vaadin.ui.ComboBox)1 TextField (com.vaadin.ui.TextField)1 Test (org.junit.Test)1 Event (org.opennms.netmgt.xml.eventconf.Event)1