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