List of usage examples for com.vaadin.ui TextField addBlurListener
@Override
public Registration addBlurListener(BlurListener listener)
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public InterestProfileView() { User user = UserUtils.getCurrent();/*from w w w . j a v a2s. c o m*/ Set<InterestProfile> profiles = UserUtils.getAllInterestProfiles(user); CssLayout newProfileGroup = new CssLayout(); newProfileGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldNewProfileName = new TextField(); Language.setCustom(Word.PROFILE_NAME, s -> textFieldNewProfileName.setPlaceholder(s)); textFieldNewProfileName.setWidth("260px"); textFieldNewProfileName.setMaxLength(255); newProfileGroup.addComponent(textFieldNewProfileName); Button buttonNewProfile = new Button(); buttonNewProfile.setIcon(VaadinIcons.PLUS); buttonNewProfile.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonNewProfile.addClickListener(e -> { Tab newTab = accordion.addTab(createTab(createEmptyProfile(textFieldNewProfileName.getValue())), textFieldNewProfileName.getValue()); accordion.setSelectedTab(newTab); accordion.setWidth("100%"); textFieldNewProfileName.clear(); }); newProfileGroup.addComponent(buttonNewProfile); textFieldNewProfileName .addFocusListener(f -> buttonNewProfile.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldNewProfileName.addBlurListener(f -> buttonNewProfile.removeClickShortcut()); profiles.forEach((InterestProfile profile) -> { accordion.addTab(createTab(profile), profile.getName()); }); addComponents(newProfileGroup, accordion); SESSIONS.put(user, this); }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
private Component getAddTagGroup(InterestProfile profile, boolean included) { CssLayout newTagGroup = new CssLayout(); newTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldTag = new TextField(); textFieldTag.setWidth("325px"); textFieldTag.setMaxLength(255);// ww w. j ava 2s . c o m Language.setCustom(Word.NEW_TAG, s -> textFieldTag.setPlaceholder(s)); Button buttonAddTag = new Button(VaadinIcons.PLUS); buttonAddTag.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonAddTag.addClickListener(event -> { addRow(profile, included, textFieldTag.getValue()); profile.getTags().put(textFieldTag.getValue(), included); textFieldTag.clear(); }); textFieldTag.addFocusListener(f -> buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldTag.addBlurListener(f -> buttonAddTag.removeClickShortcut()); newTagGroup.addComponents(textFieldTag, buttonAddTag); newTagGroup.setWidth("100%"); return newTagGroup; }
From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java
private Component getAddTagGroup(GroupInterestProfile profile, boolean included) { CssLayout newTagGroup = new CssLayout(); newTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldTag = new TextField(); textFieldTag.setWidth("325px"); textFieldTag.setMaxLength(255);// www .j ava 2 s. c o m Language.setCustom(Word.NEW_TAG, s -> textFieldTag.setPlaceholder(s)); Button buttonAddTag = new Button(VaadinIcons.PLUS); buttonAddTag.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonAddTag.addClickListener(event -> { addRow(profile, included, textFieldTag.getValue(), true); profile.getTags().put(textFieldTag.getValue(), included); textFieldTag.clear(); }); textFieldTag.addFocusListener(f -> buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldTag.addBlurListener(f -> buttonAddTag.removeClickShortcut()); newTagGroup.addComponents(textFieldTag, buttonAddTag); newTagGroup.setWidth("100%"); return newTagGroup; }
From source file:net.javaforge.netty.vaadin.AddressbookUI.java
License:Apache License
private void initEditor() { editorLayout.addComponent(removeContactButton); /* User interface can be created dynamically to reflect underlying data. */ for (String fieldName : fieldNames) { final TextField field = new TextField(fieldName); editorLayout.addComponent(field); field.setWidth("100%"); /*/* w ww. ja va 2s. c o m*/ * We use a FieldGroup to connect multiple components to a data * source at once. */ editorFields.bind(field, fieldName); field.addBlurListener(new FieldEvents.BlurListener() { private static final long serialVersionUID = 1L; @Override public void blur(BlurEvent event) { field.commit(); } }); } /* * Data can be buffered in the user interface. When doing so, commit() * writes the changes to the data source. Here we choose to write the * changes automatically without calling commit(). */ // editorFields.setBuffered(false); }
From source file:org.lucidj.vaadinui.Login.java
License:Apache License
@Override // LoginForm protected Component createContent(TextField userNameField, PasswordField passwordField, Button loginButton) { // Save the predefined components this.userNameField = userNameField; this.passwordField = passwordField; this.loginButton = loginButton; // Make LoginForm container full-screen setSizeFull();/* w ww . j a v a 2 s. c o m*/ VerticalLayout layout = new VerticalLayout(); layout.setSizeFull(); layout.addStyleName("login-wallpaper"); final VerticalLayout loginPanel = new VerticalLayout(); loginPanel.setSizeUndefined(); loginPanel.setMargin(true); loginPanel.setSpacing(true); Responsive.makeResponsive(loginPanel); loginPanel.addStyleName("card"); //-------- // HEADER //-------- final HorizontalLayout labels = new HorizontalLayout(); labels.setWidth("100%"); final Label title = new Label("<h3><strong>LucidJ</strong> Console</h3>", ContentMode.HTML); labels.addComponent(title); labels.setExpandRatio(title, 1); loginPanel.addComponent(labels); //-------- // FIELDS //-------- HorizontalLayout fields = new HorizontalLayout(); fields.setSpacing(true); fields.addStyleName("fields"); userNameField.setImmediate(true); userNameField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER); final ShortcutListener username_enter_listener = new ShortcutListener("Next field (Tab)", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object o, Object o1) { passwordField.setValue(""); passwordField.focus(); } }; userNameField.addTextChangeListener(new FieldEvents.TextChangeListener() { @Override public void textChange(FieldEvents.TextChangeEvent textChangeEvent) { show_default_message(); int new_username_length = textChangeEvent.getText().length(); // Check for autofill if (userNameField.isEmpty() && new_username_length > 1 && !userNameField_filling) { // This is autofill userNameField.removeShortcutListener(username_enter_listener); userNameField.setCursorPosition(new_username_length); userNameField.setSelectionRange(0, new_username_length); } else { userNameField_filling = true; passwordField.setValue(""); userNameField.addShortcutListener(username_enter_listener); } } }); userNameField.addFocusListener(new FieldEvents.FocusListener() { @Override public void focus(FieldEvents.FocusEvent focusEvent) { // Cursor on username, Enter jump to password loginButton.removeClickShortcut(); userNameField.addShortcutListener(username_enter_listener); } }); userNameField.addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(FieldEvents.BlurEvent blurEvent) { // Cursor on password or elsewhere, enter submits userNameField.removeShortcutListener(username_enter_listener); loginButton.setClickShortcut(ShortcutAction.KeyCode.ENTER); } }); passwordField.setImmediate(true); passwordField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER); passwordField.addTextChangeListener(new FieldEvents.TextChangeListener() { @Override public void textChange(FieldEvents.TextChangeEvent textChangeEvent) { show_default_message(); } }); loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY); loginButton.setDisableOnClick(true); fields.addComponents(userNameField, passwordField, loginButton); fields.setComponentAlignment(loginButton, Alignment.BOTTOM_LEFT); loginPanel.addComponent(fields); //-------- // FOOTER //-------- loginPanel.addComponent(new CheckBox("Remember me", true)); loginPanel.addComponent(message_label); show_default_message(); layout.addComponent(loginPanel); layout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER); return (layout); }
From source file:org.qa82.analyzer.ui.OnEnterKeyHandler.java
License:Open Source License
public void installOn(final TextField component) { component.addFocusListener(new FieldEvents.FocusListener() { /**/*from w w w . jav a2 s .c o m*/ * */ private static final long serialVersionUID = 1L; @Override public void focus(FieldEvents.FocusEvent event) { component.addShortcutListener(enterShortCut); } }); component.addBlurListener(new FieldEvents.BlurListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void blur(FieldEvents.BlurEvent event) { component.removeShortcutListener(enterShortCut); } }); }
From source file:zm.hashcode.mshengu.app.util.validation.OnSubmitValidationHelper.java
public void doValidation() { TextField textField = new TextField(); TextArea textArea = new TextArea(); DateField dateField = new DateField(); ComboBox comboBox = new ComboBox(); for (Field o : fields) { String currentMessage = ""; try {/* w w w . j a v a2 s. co m*/ if (o instanceof TextField) { textField = (TextField) o; textField.validate(); } else if (o instanceof TextArea) { textArea = (TextArea) o; textArea.validate(); } else if (o instanceof DateField) { dateField = (DateField) o; dateField.validate(); } else if (o instanceof ComboBox) { comboBox = (ComboBox) o; comboBox.validate(); } } catch (Validator.InvalidValueException x) { //works with vaadin required currentMessage = x.getMessage(); if (o instanceof TextField) { textField.setStyleName("invalid"); } else if (o instanceof TextArea) { textArea.setStyleName("invalid"); } else if (o instanceof DateField) { dateField.setStyleName("invalid"); } else if (o instanceof ComboBox) { comboBox.setStyleName("invalid"); } } finally { if (o instanceof TextField) { textField.addFocusListener( new LabelErrorMessageManipulator(textField, errorLabel, currentMessage)); //custom focus handler for displaying error message on a labe when you focus on an errored Textfield } else if (o instanceof TextArea) { textArea.addFocusListener( new LabelErrorMessageManipulator(textArea, errorLabel, currentMessage)); //custom focus handler for displaying error message on a labe when you focus on an errored Textfield } else if (o instanceof DateField) { dateField.addFocusListener( new LabelErrorMessageManipulator(dateField, errorLabel, currentMessage)); //custom focus handler for displaying error message on a labe when you focus on an errored Textfield } else if (o instanceof ComboBox) { comboBox.addFocusListener( new LabelErrorMessageManipulator(comboBox, errorLabel, currentMessage)); //custom focus handler for displaying error message on a labe when you focus on an errored Textfield } } if (o instanceof TextField) { textField.addBlurListener(new LabelErrorMessageManipulator(textField, errorLabel, currentMessage)); //custom blur handler for displaying error message on a labe when you blur on an errored Textfield } else if (o instanceof TextArea) { textArea.addBlurListener(new LabelErrorMessageManipulator(textArea, errorLabel, currentMessage)); //custom blur handler for displaying error message on a labe when you blur on an errored Textfield } else if (o instanceof DateField) { dateField.addBlurListener(new LabelErrorMessageManipulator(dateField, errorLabel, currentMessage)); //custom blur handler for displaying error message on a labe when you blur on an errored Textfield } else if (o instanceof ComboBox) { comboBox.addBlurListener(new LabelErrorMessageManipulator(comboBox, errorLabel, currentMessage)); //custom blur handler for displaying error message on a labe when you blur on an errored Textfield } } }