List of usage examples for com.vaadin.ui TextField TextField
public TextField(String caption, ValueChangeListener<String> valueChangeListener)
From source file:com.lst.deploymentautomation.vaadin.popup.TodoAnnotation.java
License:Open Source License
@Override public void attach() { super.attach(); LspsUI ui = (LspsUI) getUI();//ww w . j ava2s . co m setCaption(ui.getMessage("todo.annotationTitle")); VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); layout.setSizeFull(); setContent(layout); Label help = new Label(ui.getMessage("todo.annotationHelp")); help.setStyleName("form-help"); layout.addComponent(help); priorityField = new TextField(ui.getMessage("todo.priority"), priority); //TODO forbid negative priorities priorityField.setConverter(Integer.class); priorityField.setConversionError(ui.getMessage("app.invalidValueMessage")); priorityField.setNullRepresentation(""); priorityField.setNullSettingAllowed(true); layout.addComponent(priorityField); TextArea notesField = new TextArea(ui.getMessage("todo.notes"), notes); notesField.setMaxLength(1024); notesField.setNullRepresentation(""); priorityField.setNullSettingAllowed(true); notesField.setSizeFull(); layout.addComponent(notesField); layout.setExpandRatio(notesField, 1); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); layout.addComponent(buttons); @SuppressWarnings("serial") Button submitButton = new Button(ui.getMessage("action.annotate"), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { annotate(); } }); buttons.addComponent(submitButton); @SuppressWarnings("serial") Button cancelButton = new Button(ui.getMessage("action.cancel"), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { close(); } }); buttons.addComponent(cancelButton); }
From source file:com.mcparland.john.vaadin_mvn_arch.samples.authentication.LoginScreen.java
License:Apache License
private Component buildLoginForm() { FormLayout loginForm = new FormLayout(); loginForm.addStyleName("login-form"); loginForm.setSizeUndefined();//from ww w. j a v a2 s .com loginForm.setMargin(false); loginForm.addComponent(username = new TextField("Username", "admin")); username.setWidth(15, Unit.EM); loginForm.addComponent(password = new PasswordField("Password")); password.setWidth(15, Unit.EM); password.setDescription("Write anything"); CssLayout buttons = new CssLayout(); buttons.setStyleName("buttons"); loginForm.addComponent(buttons); buttons.addComponent(login = new Button("Login")); login.setDisableOnClick(true); login.addClickListener(new Button.ClickListener() { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent event) { try { login(); } finally { login.setEnabled(true); } } }); login.setClickShortcut(ShortcutAction.KeyCode.ENTER); login.addStyleName(ValoTheme.BUTTON_FRIENDLY); buttons.addComponent(forgotPassword = new Button("Forgot password?")); forgotPassword.addClickListener(new Button.ClickListener() { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent event) { showNotification(new Notification("Hint: Try anything")); } }); forgotPassword.addStyleName(ValoTheme.BUTTON_LINK); return loginForm; }
From source file:com.morevaadin.vaadin.theming.ThemingContent.java
License:Apache License
public ThemingContent() { CustomLayout layout = new CustomLayout("layout"); setCompositionRoot(layout);/*from w ww . j a v a 2 s . c o m*/ layout.addComponent(menuBar, "top"); layout.addComponent(new Button("Does nothing"), "bottom"); VerticalLayout vLayout = new VerticalLayout(); vLayout.addComponent(new InlineDateField()); vLayout.addComponent(new TextField("", "Nothing to put in here")); vLayout.setSpacing(true); vLayout.setMargin(true); layout.addComponent(vLayout, "left"); }
From source file:com.mycollab.vaadin.ui.field.DateFormatField.java
License:Open Source License
public DateFormatField(final String initialFormat) { this.dateFormat = initialFormat; dateInput = new TextField(null, initialFormat); dateInput.setImmediate(true);/*from ww w . j av a 2s. co m*/ dateInput.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER); now = new DateTime(); dateExample = new Label(); dateFormatInstance = DateTimeFormat.forPattern(dateFormat); dateExample.setValue("(" + dateFormatInstance.print(now) + ")"); dateExample.setWidthUndefined(); dateInput.addTextChangeListener(textChangeEvent -> { try { String newFormat = textChangeEvent.getText(); dateFormatInstance = DateTimeFormat.forPattern(newFormat); dateExample.setValue("(" + dateFormatInstance.print(now) + ")"); } catch (Exception e) { NotificationUtil.showErrorNotification(UserUIContext.getMessage(ErrorI18nEnum.INVALID_FORMAT)); dateInput.setValue(initialFormat); dateFormatInstance = DateTimeFormat.forPattern(initialFormat); dateExample.setValue("(" + dateFormatInstance.print(now) + ")"); } }); }
From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java
License:Apache License
/** * Create the component to take a snapshot. * /*from ww w . ja v a 2 s . co m*/ * @return the component */ @SuppressWarnings("serial") private final AbstractComponent createTakeSnap() { final VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setMargin(true); final FormLayout takeSnapLayout = new FormLayout(); takeSnapLayout.setMargin(true); takeSnapLayout.setImmediate(true); takeSnapLayout.setWidth(null); layout.addComponent(takeSnapLayout); layout.setComponentAlignment(takeSnapLayout, Alignment.MIDDLE_CENTER); // Enter name final TextField vvrName = new TextField("Name", ""); takeSnapLayout.addComponent(vvrName); // take button final Button take = new Button("Take snapshot"); layout.addComponent(take); layout.setComponentAlignment(take, Alignment.MIDDLE_CENTER); take.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { model.takeDeviceSnapshot(vvrName.getValue()); Notification.show("New snapshot created", Notification.Type.TRAY_NOTIFICATION); } catch (final Exception e) { final ErrorWindow err = new ErrorWindow("Snapshot not taken: " + e.getMessage()); err.add(model); } } }); return layout; }
From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java
License:Apache License
/** * Create attributes component.// ww w . j a v a2 s .c om * * @return the component */ private final AbstractComponent createAttributes() { final VerticalLayout layout = new VerticalLayout(); final FormLayout deviceAttributesLayout = new FormLayout(); deviceAttributesLayout.setMargin(true); deviceAttributesLayout.setWidth(null); deviceAttributesLayout.setImmediate(true); layout.addComponent(deviceAttributesLayout); layout.setComponentAlignment(deviceAttributesLayout, Alignment.MIDDLE_CENTER); // Enter NAME WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceName(value); } @Override public String getStringValue() { return model.getDeviceName(); } }, "Name", deviceAttributesLayout, model); // Enter DESCRIPTION WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceDescription(value); } @Override public String getStringValue() { return model.getDeviceDescription(); } }, "Description", deviceAttributesLayout, model); // Enter UUID (not editable) final TextField deviceUUID = new TextField("UUID", model.getItemUuid().toString()); deviceUUID.setReadOnly(true); deviceUUID.setWidth("300px"); deviceAttributesLayout.addComponent(deviceUUID); // Enter active final TextField deviceActive = new TextField("Active"); if (model.isDeviceActive()) { deviceActive.setValue("yes"); } else { deviceActive.setValue("no"); } deviceActive.setReadOnly(true); deviceActive.setSizeFull(); deviceAttributesLayout.addComponent(deviceActive); // Enter read only final TextField deviceReadOnly = new TextField("Read Only"); if (model.isDeviceReadOnly()) { deviceReadOnly.setValue("yes"); } else { deviceReadOnly.setValue("no"); } deviceReadOnly.setReadOnly(true); deviceReadOnly.setSizeFull(); deviceAttributesLayout.addComponent(deviceReadOnly); // Enter size WebUiUtils.createFieldLong(new LongAttributeOperation() { @Override public void setLongValue(final long value) { model.setDeviceSize(value); } @Override public long getLongValue() { return model.getDeviceSize(); } }, "Size", deviceAttributesLayout, model); // Enter IQN WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceIqn(value); } @Override public String getStringValue() { return model.getDeviceIqn(); } }, "IQN", deviceAttributesLayout, model); // Enter Alias WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceIscsiAlias(value); } @Override public String getStringValue() { return model.getDeviceIscsiAlias(); } }, "iSCSI Alias", deviceAttributesLayout, model); // Enter iscsi block size WebUiUtils.createFieldInteger(new IntegerAttributeOperation() { @Override public void setIntegerValue(final int value) { model.setDeviceIscsiBlockSize(value); } @Override public int getIntegerValue() { return model.getDeviceIscsiBlockSize(); } }, "iSCSI Block Size", deviceAttributesLayout, model, true); return layout; }
From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java
License:Apache License
/** * Create the component to create a device. * /*from w ww .j av a 2 s .c om*/ * @return the component */ @SuppressWarnings("serial") private final AbstractComponent createDevice() { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); final FormLayout createDeviceLayout = new FormLayout(); createDeviceLayout.setMargin(true); createDeviceLayout.setWidth(null); createDeviceLayout.setImmediate(true); layout.addComponent(createDeviceLayout); layout.setComponentAlignment(createDeviceLayout, Alignment.MIDDLE_CENTER); // Enter name final TextField deviceName = new TextField("Name", ""); createDeviceLayout.addComponent(deviceName); // Enter size final TextField deviceSize = new TextField("Size", ""); createDeviceLayout.addComponent(deviceSize); // Create button final Button create = new Button("Create device"); layout.addComponent(create); layout.setComponentAlignment(create, Alignment.MIDDLE_CENTER); create.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { model.createDevice(deviceName.getValue(), Long.valueOf(deviceSize.getValue())); Notification.show("New device created", Notification.Type.TRAY_NOTIFICATION); } catch (final NumberFormatException e) { final ErrorWindow err = new ErrorWindow("Size must be a valid number"); err.add(model); } catch (final Exception e) { final ErrorWindow err = new ErrorWindow("Device not created: " + e.getMessage()); err.add(model); } } }); return layout; }
From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java
License:Apache License
/** * Create the component for the snapshot attributes * /*ww w . j av a2 s .c om*/ * @return the component */ private final AbstractComponent createAttributes() { final VerticalLayout layout = new VerticalLayout(); final FormLayout snapshotAttributesLayout = new FormLayout(); snapshotAttributesLayout.setMargin(true); snapshotAttributesLayout.setWidth(null); snapshotAttributesLayout.setImmediate(true); layout.addComponent(snapshotAttributesLayout); layout.setComponentAlignment(snapshotAttributesLayout, Alignment.MIDDLE_CENTER); // Enter NAME WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setSnapshotName(value); } @Override public String getStringValue() { return model.getSnapshotName(); } }, "Name", snapshotAttributesLayout, model); // Enter DESCRIPTION WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setSnapshotDescription(value); } @Override public String getStringValue() { return model.getSnapshotDescription(); } }, "Description", snapshotAttributesLayout, model); // Enter UUID (not editable) final TextField snapUUID = new TextField("UUID", model.getItemUuid().toString()); snapUUID.setReadOnly(true); snapUUID.setWidth("300px"); snapshotAttributesLayout.addComponent(snapUUID); return layout; }
From source file:com.oodrive.nuage.webui.component.window.VvrAttributesWindow.java
License:Apache License
@SuppressWarnings("serial") @Override/*from w w w . java 2s .c om*/ public final Window init(final AbstractItemModel model) { // Cast model in vvrModel final VvrModel vvrModel = (VvrModel) model; // Add new window final Window vvrAttributesWindow = new Window("VVR Attributes"); vvrAttributesWindow.center(); vvrAttributesWindow.setWidth("400px"); vvrAttributesWindow.setResizable(false); final VerticalLayout layout = new VerticalLayout(); vvrAttributesWindow.setContent(layout); layout.setMargin(true); final FormLayout vvrAttributesLayout = new FormLayout(); layout.addComponent(vvrAttributesLayout); vvrAttributesLayout.setMargin(true); // Enter NAME String value = vvrModel.getVvrName(); if (value == null) { value = ""; } final TextField name = new TextField("Name", value); name.setSizeFull(); vvrAttributesLayout.addComponent(name); // Enter description value = vvrModel.getVvrDescription(); if (value == null) { value = ""; } final TextField desc = new TextField("Description", value); desc.setSizeFull(); vvrAttributesLayout.addComponent(desc); // Enter name final TextField vvrUUID = new TextField("UUID"); vvrUUID.setValue(vvrUuid.toString()); vvrUUID.setReadOnly(true); vvrUUID.setSizeFull(); vvrAttributesLayout.addComponent(vvrUUID); // OK button final HorizontalLayout hzlayout = new HorizontalLayout(); layout.addComponent(hzlayout); hzlayout.setSizeFull(); final Button okButton = new Button("OK"); hzlayout.addComponent(okButton); hzlayout.setComponentAlignment(okButton, Alignment.MIDDLE_CENTER); okButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { WaitingComponent.executeBackground(vvrModel, new Background() { @Override public void processing() { vvrModel.setVvrName(name.getValue()); vvrModel.setVvrDescription(desc.getValue()); } @Override public void postProcessing() { } }); vvrAttributesWindow.close(); } }); // Cancel button final Button cancelButton = new Button("Cancel"); hzlayout.addComponent(cancelButton); hzlayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER); cancelButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { // Just close the window vvrAttributesWindow.close(); } }); return vvrAttributesWindow; }
From source file:com.oodrive.nuage.webui.WebUiUtils.java
License:Apache License
/** * Create a new String text field with a given setter/getter. * /*from www . ja v a 2 s . c o m*/ * @param operation * the operation to get/set the value contains in the text field. * @param fieldName * the name of the field * @param rootLayout * the layout to add the text field * @param model * the model used to get/set the value */ @SuppressWarnings({ "serial" }) public static final void createFieldString(final StringAttributeOperation operation, final String fieldName, final FormLayout rootLayout, final AbstractItemModel model) { String value = operation.getStringValue(); // Display empty string if value is null if (value == null) { value = ""; } final TextField field = new TextField(fieldName, value); field.setWidth("250px"); field.setImmediate(true); rootLayout.addComponent(field); field.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent event) { final String newValue = String.valueOf(event.getProperty().getValue()); final String oldValue = operation.getStringValue(); if (!newValue.equals(oldValue)) { // Set value in background (could be a long operation) WaitingComponent.executeBackground(model, new Background() { @Override public void processing() { operation.setStringValue(newValue); } @Override public void postProcessing() { Notification.show(fieldName + " changed", newValue, Notification.Type.TRAY_NOTIFICATION); } }); } } }); }