Example usage for com.vaadin.ui ComboBox setTextInputAllowed

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

Introduction

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

Prototype

public void setTextInputAllowed(boolean textInputAllowed) 

Source Link

Document

Sets whether it is possible to input text into the field or whether the field area of the component is just used to show what is selected.

Usage

From source file:org.jumpmind.metl.ui.views.design.EditScriptPanel.java

License:Open Source License

@SuppressWarnings("serial")
protected void buildUI() {
    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);//from   w ww.  j a va 2  s . co m

    editor = CommonUiUtils.createAceEditor();
    editor.setTextChangeEventMode(TextChangeEventMode.LAZY);
    editor.setTextChangeTimeout(200);

    editor.setMode(AceMode.java);

    final ComboBox select = new ComboBox();
    select.setWidth(40, Unit.EM);
    select.setTextInputAllowed(false);

    select.addItem(Script.IMPORTS);
    select.setItemCaption(Script.IMPORTS, SCRIPT_IMPORTS);
    select.addItem(Script.METHODS);
    select.setItemCaption(Script.METHODS, SCRIPT_METHODS);
    select.addItem(Script.INIT_SCRIPT);
    select.setItemCaption(Script.INIT_SCRIPT, SCRIPT_ON_INIT);
    select.addItem(Script.HANDLE_SCRIPT);
    select.setItemCaption(Script.HANDLE_SCRIPT, SCRIPT_ON_HANDLE);
    select.addItem(Script.ON_FLOW_SUCCESS);
    select.setItemCaption(Script.ON_FLOW_SUCCESS, SCRIPT_ON_SUCCESS);
    select.addItem(Script.ON_FLOW_ERROR);
    select.setItemCaption(Script.ON_FLOW_ERROR, SCRIPT_ON_ERROR);

    select.setImmediate(true);
    select.setNullSelectionAllowed(false);
    select.setNewItemsAllowed(false);
    select.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            String key = (String) select.getValue();
            editor.setReadOnly(false);
            editor.setValue(EditScriptPanel.this.component.get(key,
                    componentDefinition.findXMLSetting(key).getDefaultValue()));
            editor.setReadOnly(readOnly);
        }
    });
    select.setValue(Script.HANDLE_SCRIPT);
    buttonBar.addLeft(select);

    if (!readOnly) {
        editor.addTextChangeListener(new TextChangeListener() {

            @Override
            public void textChange(TextChangeEvent event) {
                String key = (String) select.getValue();
                EditScriptPanel.this.component.put(key, event.getText());
                EditScriptPanel.this.context.getConfigurationService()
                        .save(EditScriptPanel.this.component.findSetting(key));
            }
        });
    }

    addComponent(editor);
    setExpandRatio(editor, 1);

}

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

License:Apache License

private void initSystemToolbar() {
    desktop_canvas.setSizeFull();//  ww w  . j  av  a  2s.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:org.opencms.ui.apps.CmsFileExplorer.java

License:Open Source License

/**
 * Creates the site selector combo box.<p>
 *
 * @param cms the current cms context//from www. j  a  v  a  2 s  .c  o m
 *
 * @return the combo box
 */
private ComboBox createSiteSelect(CmsObject cms) {

    final IndexedContainer availableSites = CmsVaadinUtils.getAvailableSitesContainer(cms, SITE_CAPTION);
    ComboBox combo = new ComboBox(null, availableSites);
    combo.setTextInputAllowed(true);
    combo.setNullSelectionAllowed(false);
    combo.setWidth("200px");
    combo.setInputPrompt(
            Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_CLICK_TO_EDIT_0));
    combo.setItemCaptionPropertyId(SITE_CAPTION);
    combo.select(cms.getRequestContext().getSiteRoot());
    combo.setFilteringMode(FilteringMode.CONTAINS);
    combo.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) event.getProperty().getValue();
            if (availableSites.containsId(value)) {
                changeSite(value, null);
                m_appContext.updateOnChange();
                availableSites.removeAllContainerFilters();
            }
        }
    });
    if (Page.getCurrent().getBrowserWindowHeight() > 650) {
        combo.setPageLength(20);
    }
    return combo;
}

From source file:org.opencms.ui.dialogs.CmsProjectSelectDialog.java

License:Open Source License

/**
 * Prepares a combo box.<p>/* w w w . j  a v a  2 s. com*/
 *
 * @param container the indexed item container
 * @param captionKey the caption message key
 *
 * @return the combo box
 */
private ComboBox prepareComboBox(IndexedContainer container, String captionKey) {

    ComboBox result = new ComboBox(CmsVaadinUtils.getWpMessagesForCurrentLocale().key(captionKey), container);
    result.setTextInputAllowed(true);
    result.setNullSelectionAllowed(false);
    result.setWidth("100%");
    result.setInputPrompt(
            Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_CLICK_TO_EDIT_0));
    result.setItemCaptionPropertyId(CAPTION_PROPERTY);
    result.setFilteringMode(FilteringMode.CONTAINS);
    return result;
}

From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorOptions.java

License:Open Source License

/**
 * Initializes the language switcher UI Component {@link #m_languageSwitch}, including {@link #m_languageSelect}.
 * @param locales the locales that can be selected.
 * @param current the currently selected locale.
 *///from  w  ww. ja va2s  . c o m
private void initLanguageSwitch(Collection<Locale> locales, Locale current) {

    FormLayout languages = new FormLayout();
    languages.setHeight("100%");
    languages.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    ComboBox languageSelect = new ComboBox();
    languageSelect.setCaption(m_messages.key(Messages.GUI_LANGUAGE_SWITCHER_LABEL_0));
    languageSelect.setNullSelectionAllowed(false);

    // set Locales
    for (Locale locale : locales) {
        languageSelect.addItem(locale);
        String caption = locale.getDisplayName(UI.getCurrent().getLocale());
        if (CmsLocaleManager.getDefaultLocale().equals(locale)) {
            caption += " ("
                    + Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_DEFAULT_LOCALE_0)
                    + ")";
        }
        languageSelect.setItemCaption(locale, caption);
    }
    languageSelect.setValue(current);
    languageSelect.setNewItemsAllowed(false);
    languageSelect.setTextInputAllowed(false);
    languageSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            m_listener.handleLanguageChange((Locale) event.getProperty().getValue());

        }
    });

    if (locales.size() == 1) {
        languageSelect.setEnabled(false);
    }
    languages.addComponent(languageSelect);
    m_languageSwitch = languages;
}

From source file:org.ow2.sirocco.cloudmanager.MyUI.java

License:Open Source License

@Override
protected void init(final VaadinRequest request) {
    this.userName = request.getUserPrincipal().getName();
    this.identityContext.setUserName(this.userName);

    this.getPage().setTitle("Sirocco Dashboard");
    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();//w  ww.  j a va 2  s .c o m
    this.setContent(layout);

    // Top header *********************
    HorizontalLayout header = new HorizontalLayout();
    header.setMargin(true);
    header.setWidth("100%");
    header.setHeight("70px");
    header.setStyleName("topHeader");

    // logo
    Image image = new Image(null, new ThemeResource("img/sirocco_small_logo.png"));
    header.addComponent(image);

    // spacer
    Label spacer = new Label();
    spacer.setWidth("100%");
    header.addComponent(spacer);
    header.setExpandRatio(spacer, 1.0f);

    HorizontalLayout rightButtons = new HorizontalLayout();
    rightButtons.setStyleName("topHeader");
    rightButtons.setSpacing(true);

    this.userName = request.getUserPrincipal().getName();
    User user = null;
    try {
        user = this.userManager.getUserByUsername(this.userName);
    } catch (CloudProviderException e) {
        e.printStackTrace();
    }

    Label label = new Label("Tenant:");
    label.setStyleName("topHeaderLabel");
    rightButtons.addComponent(label);
    final ComboBox tenantSelect = new ComboBox();
    tenantSelect.setTextInputAllowed(false);
    tenantSelect.setNullSelectionAllowed(false);
    for (Tenant tenant : user.getTenants()) {
        tenantSelect.addItem(tenant.getName());
    }
    tenantSelect.setValue(user.getTenants().iterator().next().getName());
    tenantSelect.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(final ValueChangeEvent event) {
            Notification.show("Switching to tenant " + tenantSelect.getValue());

        }
    });
    tenantSelect.setImmediate(true);
    rightButtons.addComponent(tenantSelect);

    this.tenantId = user.getTenants().iterator().next().getUuid();
    this.identityContext.setTenantId(this.tenantId);

    // logged user name

    label = new Label("Logged in as: " + this.userName);
    label.setStyleName("topHeaderLabel");
    rightButtons.addComponent(label);

    // sign out button
    Button button = new Button("Sign Out");
    // button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            MyUI.this.logout();
        }
    });
    rightButtons.addComponent(button);

    header.addComponent(rightButtons);
    layout.addComponent(header);

    // Split view
    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    splitPanel.setSizeFull();
    splitPanel.setFirstComponent(this.createLeftMenu());

    this.inventoryContainer = new VerticalLayout();
    this.inventoryContainer.setSizeFull();

    this.inventoryContainer.addComponent(this.machineView);

    splitPanel.setSecondComponent(this.inventoryContainer);
    splitPanel.setSplitPosition(15);

    layout.addComponent(splitPanel);
    layout.setExpandRatio(splitPanel, 1.0f);

    this.listenToNotifications();

}