Search in sources :

Example 21 with TextField

use of com.vaadin.ui.TextField 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 22 with TextField

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

the class WallboardConfigView method addNewTabComponent.

/**
 * This method is used to add a new {@link TabSheet.Tab} component. It creates a new window querying the user for the name of the new {@link Wallboard}.
 */
protected void addNewTabComponent() {
    final Window window = new Window("New Ops Board");
    window.setModal(true);
    window.setClosable(false);
    window.setResizable(false);
    window.addCloseListener(new Window.CloseListener() {

        @Override
        public void windowClose(Window.CloseEvent e) {
            m_dashboardOverview.refreshTable();
        }
    });
    getUI().addWindow(window);
    window.setContent(new VerticalLayout() {

        TextField name = new TextField("Ops Board Name");

        {
            addComponent(new FormLayout() {

                {
                    setSizeUndefined();
                    setMargin(true);
                    String newName = "Untitled";
                    int i = 1;
                    if (WallboardProvider.getInstance().containsWallboard(newName)) {
                        do {
                            i++;
                            newName = "Untitled #" + i;
                        } while (WallboardProvider.getInstance().containsWallboard(newName));
                    }
                    name.setValue(newName);
                    addComponent(name);
                    name.focus();
                    name.selectAll();
                    name.addValidator(new AbstractStringValidator("Title must be unique") {

                        @Override
                        protected boolean isValidValue(String s) {
                            return (!WallboardProvider.getInstance().containsWallboard(s) && !"".equals(s));
                        }
                    });
                }
            });
            addComponent(new HorizontalLayout() {

                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");
                    Button cancel = new Button("Cancel");
                    cancel.setDescription("Cancel editing");
                    cancel.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            // NMS-7560: Toggle the tab in order to allow us to click it again
                            m_tabSheet.togglePlusTab();
                            window.close();
                        }
                    });
                    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
                    addComponent(cancel);
                    setExpandRatio(cancel, 1);
                    setComponentAlignment(cancel, Alignment.TOP_RIGHT);
                    Button ok = new Button("Save");
                    ok.setDescription("Save configuration");
                    ok.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            if (name.isValid()) {
                                Wallboard wallboard = new Wallboard();
                                wallboard.setTitle(name.getValue());
                                WallboardProvider.getInstance().addWallboard(wallboard);
                                WallboardProvider.getInstance().save();
                                WallboardEditor wallboardEditor = new WallboardEditor(m_dashletSelector, wallboard);
                                TabSheet.Tab tab = m_tabSheet.addTab(wallboardEditor, wallboard.getTitle());
                                wallboardEditor.setTab(tab);
                                m_wallboardEditorMap.put(wallboard, tab);
                                tab.setClosable(true);
                                m_tabSheet.setSelectedTab(tab);
                                window.close();
                            }
                        }
                    });
                    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
                    addComponent(ok);
                }
            });
        }
    });
}
Also used : Window(com.vaadin.ui.Window) FormLayout(com.vaadin.ui.FormLayout) AbstractStringValidator(com.vaadin.data.validator.AbstractStringValidator) Wallboard(org.opennms.features.vaadin.dashboard.model.Wallboard) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Tab(com.vaadin.ui.TabSheet.Tab) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField)

Example 23 with TextField

use of com.vaadin.ui.TextField 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.netmgt.config.collectd.jmx.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 24 with TextField

use of com.vaadin.ui.TextField in project Java-Vaadin-and-Spring-Framework by Jahidul007.

the class MyUI method init.

@Override
protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout layout = new VerticalLayout();
    final TextField name = new TextField();
    name.setCaption("Type your name here:");
    Button button = new Button("Press Me");
    button.addClickListener(e -> {
        layout.addComponent(new Label("Thanks " + name.getValue() + ", it works!"));
    });
    layout.addComponents(name, button);
    setContent(layout);
}
Also used : Button(com.vaadin.ui.Button) Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField)

Example 25 with TextField

use of com.vaadin.ui.TextField in project linkki by linkki-framework.

the class UIDoubleFieldIntegrationTest method testSetValueWithObjectDoubleInModelObject.

@Test
public void testSetValueWithObjectDoubleInModelObject() {
    TestModelObjectWithObjectDouble modelObject = new TestModelObjectWithObjectDouble();
    TextField textField = createFirstComponent(modelObject);
    assertThat(textField.getValue(), is(emptyString()));
    textField.setValue(formatter.format(1.0));
    assertThat(modelObject.getValue(), is(1.0));
    modelObject.setValue(2.0);
    assertThat(textField.getValue(), is(formatter.format(2.0)));
    textField.setValue(null);
    assertThat(modelObject.getValue(), is(nullValue()));
}
Also used : TextField(com.vaadin.ui.TextField) Test(org.junit.Test)

Aggregations

TextField (com.vaadin.ui.TextField)79 Test (org.junit.Test)22 Button (com.vaadin.ui.Button)15 Label (com.vaadin.ui.Label)15 HorizontalLayout (com.vaadin.ui.HorizontalLayout)12 VerticalLayout (com.vaadin.ui.VerticalLayout)10 ClickListener (com.vaadin.ui.Button.ClickListener)7 ComboBox (com.vaadin.ui.ComboBox)7 GridLayout (com.vaadin.ui.GridLayout)7 SplitTextField (au.com.vaadinutils.crud.splitFields.SplitTextField)6 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)6 ClickEvent (com.vaadin.ui.Button.ClickEvent)6 PasswordField (com.vaadin.ui.PasswordField)6 CheckBox (com.vaadin.ui.CheckBox)4 Form (com.vaadin.ui.Form)4 TextArea (com.vaadin.ui.TextArea)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Property (com.vaadin.data.Property)3 Validator (com.vaadin.data.Validator)3