Example usage for com.vaadin.ui ComboBox addFocusListener

List of usage examples for com.vaadin.ui ComboBox addFocusListener

Introduction

In this page you can find the example usage for com.vaadin.ui ComboBox addFocusListener.

Prototype

@Override
    public Registration addFocusListener(FocusListener listener) 

Source Link

Usage

From source file:org.lucidj.vaadinui.BaseVaadinUI.java

License:Apache License

private void initSystemToolbar() {
    desktop_canvas.setSizeFull();/*  ww w .ja v a 2  s. com*/
    desktop_canvas.setWidth("100%");

    ui_header = new HorizontalLayout();
    {
        ui_header.setStyleName("ui-header-area");
        ui_header.setWidth(100, Sizeable.Unit.PERCENTAGE);
        ui_header.setHeightUndefined();
        ui_header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

        Label logo = new Label(" ", ContentMode.HTML);
        {
            logo.addStyleName("ui-header-logo");
            logo.setWidth(default_sidebar_width_pixels, Sizeable.Unit.PIXELS);
        }
        ui_header.addComponent(logo);

        HorizontalLayout header_components = new HorizontalLayout();
        {
            header_components.setWidth(100, com.vaadin.server.Sizeable.Unit.PERCENTAGE);
            header_components.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
            header_components.setSpacing(true);

            // Search component
            CssLayout search_component = new CssLayout();
            {
                search_component.setWidth(100, com.vaadin.server.Sizeable.Unit.PERCENTAGE);
                search_component.setWidthUndefined();
                search_component.addStyleName("v-component-group");
                search_component.addStyleName("ui-header-search");
                final ComboBox search_text = new ComboBox();
                {
                    search_text.setInputPrompt("Search or paste URL...");
                    //combo.setContainerDataSource(StringGenerator.generateContainer(200, false));
                    search_text.setNullSelectionAllowed(true);
                    search_text.setTextInputAllowed(true);
                    search_text.setNewItemsAllowed(true);
                    //combo.select(combo.getItemIds().iterator().next());
                    //combo.setItemCaptionPropertyId(StringGenerator.CAPTION_PROPERTY);
                    //combo.setItemIconPropertyId(StringGenerator.ICON_PROPERTY);

                    // TODO: SOMEDAY DISCOVER HOW TO EXPAND THIS GROUPED COMPONENT, AND THE CURE FOR CANCER
                    search_text.setWidth("480px");
                    search_text.addStyleName("invisible-focus");
                    search_text.addValueChangeListener(new Property.ValueChangeListener() {
                        @Override
                        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                            String search_args = (String) search_text.getValue();

                            if (search_args != null) {
                                fireEvent("search", search_text.getValue());
                                value_change_button_quirk = true;
                            }
                        }
                    });

                    // Handles the Enter key by activating on focus and deactivating on blur
                    final ShortcutListener handle_enter = new ShortcutListener("Enter",
                            ShortcutAction.KeyCode.ENTER, null) {
                        @Override
                        public void handleAction(Object o, Object o1) {
                            value_change_button_quirk = false;
                            fireEvent("search", search_text.getValue());
                        }
                    };

                    search_text.addFocusListener(new FieldEvents.FocusListener() {
                        @Override
                        public void focus(FieldEvents.FocusEvent focusEvent) {
                            if (nested_focus_blur_bug_count++ == 0) {
                                search_text.addShortcutListener(handle_enter);
                            }
                        }
                    });

                    search_text.addBlurListener(new FieldEvents.BlurListener() {
                        @Override
                        public void blur(FieldEvents.BlurEvent blurEvent) {
                            if (--nested_focus_blur_bug_count == 0) {
                                search_text.removeShortcutListener(handle_enter);
                            }
                        }
                    });

                }
                search_component.addComponent(search_text);

                Button search_button = new Button();
                {
                    search_button.setIcon(FontAwesome.SEARCH);
                    search_button.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            if (!value_change_button_quirk) {
                                fireEvent("search", search_text.getValue());
                            }
                            value_change_button_quirk = false;
                        }
                    });
                    search_button.addStyleName("invisible-focus");
                }
                search_component.addComponent(search_button);
            }
            header_components.addComponent(search_component);

            // User component
            user_component = new HorizontalLayout();
            {
                user_component.setStyleName("ui-header-user");
                user_component.setWidthUndefined();
            }
            header_components.addComponent(user_component);

            // I swear someday I'll learn CSS, AFTER implementing my own distributed
            // operating system with augmented reality interface and a machine learning kernel,
            // all written in Z80 assembly, as a preparation for the task.
            Label spacer = new Label();
            spacer.setWidthUndefined();
            header_components.addComponent(spacer);

            // Search expands
            header_components.setExpandRatio(search_component, 1.0f);
        }
        ui_header.addComponent(header_components);
        ui_header.setExpandRatio(header_components, 1.0f);
    }

    desktop_canvas.addComponent(ui_header);
    desktop_canvas.addComponent(empty_desktop);
    desktop_canvas.setExpandRatio(empty_desktop, 1.0f);
    setContent(desktop_canvas);
}

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 {/*from  ww w. jav a  2s  .  com*/
            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
        }
    }

}