List of usage examples for com.vaadin.ui TextField TextField
public TextField(String caption, ValueChangeListener<String> valueChangeListener)
From source file:com.oodrive.nuage.webui.WebUiUtils.java
License:Apache License
/** * Create a new long text field with a given setter/getter. * /*ww w. j a v a 2 s . com*/ * @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 createFieldLong(final LongAttributeOperation operation, final String fieldName, final FormLayout rootLayout, final AbstractItemModel model) { final TextField field = new TextField(fieldName, Long.toString(operation.getLongValue())); 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 = Long.toString(operation.getLongValue()); if (!oldValue.equals(newValue)) { try { // Cast here to check format final long longNewValue = Long.valueOf(newValue); // Set value in background (could be a long operation) WaitingComponent.executeBackground(model, new Background() { @Override public void processing() { operation.setLongValue(longNewValue); } @Override public void postProcessing() { // Get the new real value set in the model (can be different) final String newValue = Long.toString(operation.getLongValue()); Notification.show(fieldName + " changed", newValue, Notification.Type.TRAY_NOTIFICATION); // Reset the field with the new value field.setValue(newValue); } }); } catch (final NumberFormatException e) { final ErrorWindow err = new ErrorWindow("You must enter a valid number"); err.add(model); // Reset the last value field.setValue(oldValue); } } } }); }
From source file:com.oodrive.nuage.webui.WebUiUtils.java
License:Apache License
/** * Create a new integer text field with a given setter/getter. * // w w w . j av a2s.co 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 createFieldInteger(final IntegerAttributeOperation operation, final String fieldName, final FormLayout rootLayout, final AbstractItemModel model, final boolean emptyAllowed) { final TextField field = new TextField(fieldName, Integer.toString(operation.getIntegerValue())); 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 = Integer.toString(operation.getIntegerValue()); if (!oldValue.equals(newValue)) { try { final int intNewValue; if (emptyAllowed && "".equals(newValue)) { // Empty equals 0 intNewValue = 0; } else { // Cast here to check format intNewValue = Integer.valueOf(newValue); } // Set value in background (could be a long operation) WaitingComponent.executeBackground(model, new Background() { @Override public void processing() { operation.setIntegerValue(intNewValue); } @Override public void postProcessing() { // Get the new real value set in the model (can be different) final String newValue = Integer.toString(operation.getIntegerValue()); Notification.show(fieldName + " changed", newValue, Notification.Type.TRAY_NOTIFICATION); // Reset the field with the new value field.setValue(newValue); } }); } catch (final NumberFormatException e) { final ErrorWindow err = new ErrorWindow("You must enter a valid number"); err.add(model); // Reset the last value field.setValue(oldValue); } } } }); }
From source file:com.wcs.wcslib.vaadin.widget.recaptcha.demo.ConfigComponent.java
License:Apache License
private Layout createThemeconfLayout() { Layout themeLayout = new FormLayout(); themeSelect = new NativeSelect("theme", Arrays.asList("red", "white", "blackglass", "clean", "custom")); themeSelect.setImmediate(true);//from ww w .j a va2 s.co m themeSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { customHtmlArea.setEnabled(isCustomTheme()); customThemeWidgetField.setEnabled(isCustomTheme()); } }); themeLayout.addComponent(themeSelect); customHtmlArea = new TextArea("custom HTML", CUSTOM_HTML_SAMPLE); customHtmlArea.setEnabled(false); customHtmlArea.setRows(15); customHtmlArea.setColumns(40); themeLayout.addComponent(customHtmlArea); customThemeWidgetField = new TextField("custom_theme_widget", CUSTOM_THEME_WIDGET); customThemeWidgetField.setEnabled(false); themeLayout.addComponent(customThemeWidgetField); return themeLayout; }
From source file:de.fatalix.app.view.login.LoginView.java
private Component buildLoginForm() { FormLayout loginForm = new FormLayout(); loginForm.addStyleName("login-form"); loginForm.setSizeUndefined();/*from w w w . j a v a 2s .c o m*/ 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() { @Override public void buttonClick(Button.ClickEvent event) { try { presenter.doLogin(username.getValue(), password.getValue()); } catch (AuthenticationException ex) { LoginView.this.showNotification( new Notification("Wrong login", Notification.Type.ERROR_MESSAGE), ValoTheme.NOTIFICATION_FAILURE); } 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() { @Override public void buttonClick(Button.ClickEvent event) { showNotification(new Notification("Hint: Try anything", Notification.Type.HUMANIZED_MESSAGE), ValoTheme.NOTIFICATION_SUCCESS); } }); forgotPassword.addStyleName(ValoTheme.BUTTON_LINK); return loginForm; }
From source file:de.fatalix.bookery.view.admin.AdminView.java
License:Open Source License
public VerticalLayout createServerSettings() { VerticalLayout layout = new VerticalLayout(); layout.setMargin(true);//from www. jav a 2s .c o m Label titleLabel = new Label("General Settings"); titleLabel.addStyleName(ValoTheme.LABEL_H2); //layout.addComponent(titleLabel); layout.addComponent(serverSettingsLayout); Button resetIndex = new Button("reset Index", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { presenter.resetIndex(); Notification.show("Succesfully reset Index", Notification.Type.HUMANIZED_MESSAGE); } catch (IOException | SolrServerException ex) { Notification.show(ex.getMessage(), Notification.Type.ERROR_MESSAGE); } } }); resetIndex.addStyleName(ValoTheme.BUTTON_DANGER); final TextField eMailAdress = new TextField(null, "felix.husse@medavis.de"); eMailAdress.setColumns(35); Button testMail = new Button("Test Mail", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { presenter.sendEmail(eMailAdress.getValue()); Notification.show("Mail succesfully sent!", Notification.Type.HUMANIZED_MESSAGE); } catch (MessagingException ex) { Notification.show("Mail failed!" + ex.getMessage(), Notification.Type.ERROR_MESSAGE); } } }); testMail.setEnabled(true); Button resetBatchJobs = new Button("reset BatchJobs", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { presenter.resetBatchJobs(); Notification.show("Succesfully reset Batchjobs", Notification.Type.HUMANIZED_MESSAGE); } }); resetBatchJobs.addStyleName(ValoTheme.BUTTON_DANGER); HorizontalLayout mailLayout = new HorizontalLayout(eMailAdress, testMail, resetBatchJobs); layout.addComponents(resetIndex, mailLayout); return layout; }
From source file:de.fatalix.bookery.view.admin.AppUserCard.java
License:Open Source License
private FormLayout createContent() { usernameField = new TextField("Username", "some.user"); passwordField = new PasswordField("Password", "password"); fullnameField = new TextField("Fullname", "Some User"); eMailField = new TextField("EMail", "user@some.de"); roles = new TextField("Roles", "user"); FormLayout userCardContent = new FormLayout(usernameField, passwordField, fullnameField, eMailField, roles); userCardContent.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); userCardContent.setMargin(true);//from w ww .ja v a 2 s . c om return userCardContent; }
From source file:de.fatalix.bookery.view.admin.BatchJobCard.java
private FormLayout createContent() { batchJobTypeCombo = new ComboBox("Batch Type"); for (BatchJobType type : BatchJobType.values()) { batchJobTypeCombo.addItem(type); }/*from www .j a v a 2 s .c o m*/ batchJobTypeCombo.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { if (!noUpdate) { BatchJobType newType = ((BatchJobType) batchJobTypeCombo.getValue()); batchJobConfiguration.setValue(newType.getDefaultConfig()); updateBean(); setFields(); } } }); description = new Label("description"); nextRuntime = new Label("---"); batchJobActive = new CheckBox("active", false); cronjobExpression = new TextField("Cronjob", "*******"); status = new TextField("Status", "-"); batchJobConfiguration = new TextArea("Configuration"); Button updateButton = new Button("update", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { updateBean(); jobConfig = presenter.updateBatchJob(jobConfig); setFields(); logger.debug("Updated Batch Job..."); } }); updateButton.addStyleName(ValoTheme.BUTTON_FRIENDLY); FormLayout batchJobCardContent = new FormLayout(batchJobTypeCombo, description, cronjobExpression, batchJobActive, batchJobConfiguration, nextRuntime, status, updateButton); batchJobCardContent.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); batchJobCardContent.setMargin(true); return batchJobCardContent; }
From source file:de.fatalix.bookery.view.login.LoginView.java
License:Open Source License
private Component buildLoginForm() { FormLayout loginForm = new FormLayout(); loginForm.addStyleName("login-form"); loginForm.setSizeUndefined();/* w w w . java2s. c o m*/ 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(""); CssLayout buttons = new CssLayout(); buttons.setStyleName("buttons"); loginForm.addComponent(buttons); login = new Button("login"); buttons.addComponent(login); login.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { presenter.doLogin(username.getValue(), password.getValue()); } catch (AuthenticationException ex) { LoginView.this.showNotification( new Notification("Wrong login", Notification.Type.ERROR_MESSAGE), ValoTheme.NOTIFICATION_FAILURE); } finally { login.setEnabled(true); } } }); login.addStyleName(ValoTheme.BUTTON_FRIENDLY); buttons.addComponent(forgotPassword = new Button("Forgot password?")); forgotPassword.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { showNotification(new Notification("Hint: Ask me", Notification.Type.HUMANIZED_MESSAGE), ValoTheme.NOTIFICATION_SUCCESS); } }); forgotPassword.addStyleName(ValoTheme.BUTTON_LINK); Panel loginPanel = new Panel(loginForm); loginPanel.setWidthUndefined(); loginPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); loginPanel.addAction(new ShortcutListener("commit", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { try { presenter.doLogin(username.getValue(), password.getValue()); } catch (AuthenticationException ex) { LoginView.this.showNotification( new Notification("Wrong login", Notification.Type.ERROR_MESSAGE), ValoTheme.NOTIFICATION_FAILURE); } } }); return loginPanel; }