Example usage for com.vaadin.ui ComboBox ComboBox

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

Introduction

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

Prototype

public ComboBox() 

Source Link

Document

Constructs an empty combo box without a caption.

Usage

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

License:Apache License

private void initSystemToolbar() {
    desktop_canvas.setSizeFull();//from  w  ww.  jav a2 s. co m
    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.lunarray.model.generation.vaadin.render.factories.form.vaadin.components.MenuSelectPropertyStrategy.java

License:Open Source License

/** {@inheritDoc} */
@Override
protected Component createSelectComponent() {
    return new ComboBox();
}

From source file:org.lunifera.runtime.web.ecview.presentation.vaadin.internal.ComboBoxPresentation.java

License:Open Source License

/**
 * {@inheritDoc}//from  ww  w  .j a v  a 2  s. c  o m
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Component doCreateWidget(Object parent) {
    if (componentBase == null) {
        componentBase = new CssLayout();
        componentBase.addStyleName(CSS_CLASS_CONTROL_BASE);
        if (modelAccess.isCssIdValid()) {
            componentBase.setId(modelAccess.getCssID());
        } else {
            componentBase.setId(getEditpart().getId());
        }

        associateWidget(componentBase, modelAccess.yCombo);

        combo = new ComboBox();
        combo.addStyleName(CSS_CLASS_CONTROL);
        combo.setImmediate(true);

        associateWidget(combo, modelAccess.yCombo);

        property = new ObjectProperty(null, modelAccess.yCombo.getType());
        combo.setPropertyDataSource(property);

        // creates the binding for the field
        createBindings(modelAccess.yCombo, combo);

        componentBase.addComponent(combo);

        if (modelAccess.isCssClassValid()) {
            combo.addStyleName(modelAccess.getCssClass());
        }

        applyCaptions();

        initializeField(combo);
    }
    return componentBase;
}

From source file:org.lunifera.runtime.web.vaadin.components.fields.search.BooleanSearchField.java

License:Open Source License

@Override
protected Component initContent() {

    ComboBox combo = new ComboBox();
    combo.setImmediate(true);// w ww . j a va 2  s. co m
    combo.setNullSelectionAllowed(false);
    combo.setItemCaptionPropertyId("description");

    // Create the container
    BeanItemContainer<BooleanFilterProperty.OptionBean> container = new BeanItemContainer<BooleanFilterProperty.OptionBean>(
            BooleanFilterProperty.OptionBean.class);
    container.addAll(filterProperty.getOptions());
    combo.setContainerDataSource(container);

    // Create the property
    ObjectProperty<BooleanFilterProperty.OptionBean> property = new ObjectProperty<BooleanFilterProperty.OptionBean>(
            filterProperty.getDefaultOption(), BooleanFilterProperty.OptionBean.class, false);
    combo.setPropertyDataSource(property);

    // Create the bindings
    DataBindingContext dbContext = getDbContext();
    selectionBinding = dbContext.bindValue(VaadinObservables.observeValue(combo),
            PojoObservables.observeValue(filterProperty, IFilterProperty.PROP_SELECTION));
    collectionBinding = dbContext.bindList(
            VaadinObservables.observeContainerItemSetContents(combo, OptionBean.class),
            PojoObservables.observeList(filterProperty, IFilterProperty.PROP_OPTIONS));

    return combo;
}

From source file:org.lunifera.vaaclipse.ui.preferences.addon.internal.ComboFieldEditorRenderer.java

License:Open Source License

@Override
public AbstractSelect createSelect() {
    return new ComboBox();
}

From source file:org.lunifera.web.ecp.uimodel.presentation.vaadin.internal.ComboBoxPresentation.java

License:Open Source License

/**
 * {@inheritDoc}/*from  ww w.  ja v  a2s. com*/
 */
@Override
public Component createWidget(Object parent) {
    if (componentBase == null) {
        componentBase = new CssLayout();
        componentBase.addStyleName(CSS_CLASS__CONTROL_BASE);
        if (modelAccess.isCssIdValid()) {
            componentBase.setId(modelAccess.getCssID());
        } else {
            componentBase.setId(getEditpart().getId());
        }

        combo = new ComboBox();
        combo.addStyleName(CSS_CLASS__CONTROL);
        combo.setSizeFull();
        componentBase.addComponent(combo);

        if (modelAccess.isCssClassValid()) {
            combo.addStyleName(modelAccess.getCssClass());
        }

        if (modelAccess.isLabelValid()) {
            combo.setCaption(modelAccess.getLabel());
        }
    }
    return componentBase;
}

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

License:Open Source License

/**
 * Initializes the form fields.<p>
 *
 * @return the form component//  w w  w. j  av a  2s  .  c  om
 */
private FormLayout initForm() {

    FormLayout form = new FormLayout();
    form.setWidth("100%");
    m_targetPath = new CmsPathSelectField();
    m_targetPath.setCaption(
            CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_TARGET_0));
    m_targetPath.setFileSelectCaption(
            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_SELECT_TARGET_CAPTION_0));
    m_targetPath.setResourceFilter(CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireFolder());
    m_targetPath.setWidth("100%");
    form.addComponent(m_targetPath);

    if (m_dialogMode != DialogMode.move) {
        m_actionCombo = new ComboBox();
        m_actionCombo
                .setCaption(CmsVaadinUtils.getMessageText(org.opencms.ui.Messages.GUI_COPYPAGE_COPY_MODE_0));
        m_actionCombo.setNullSelectionAllowed(false);
        m_actionCombo.setNewItemsAllowed(false);
        m_actionCombo.setWidth("100%");
        //            m_actionCombo.addItem(Action.automatic);
        //            m_actionCombo.setItemCaption(
        //                Action.automatic,
        //                CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_AUTOMATIC_0));
        //            m_actionCombo.setValue(Action.automatic);
        if (m_context.getResources().size() == 1) {
            if (m_context.getResources().get(0).isFile()) {
                m_actionCombo.addItem(Action.copy_all);
                m_actionCombo.setItemCaption(Action.copy_all, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_AS_NEW_0));
                m_actionCombo.addItem(Action.copy_sibling_all);
                m_actionCombo.setItemCaption(Action.copy_sibling_all, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_CREATE_SIBLING_0));
                if (m_dialogMode == DialogMode.copy_and_move) {
                    m_actionCombo.addItem(Action.move);
                    m_actionCombo.setItemCaption(Action.move, CmsVaadinUtils
                            .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_MOVE_FILE_0));
                }
            } else {
                CmsResource folder = m_context.getResources().get(0);
                m_hasContainerPageDefaultFile = hasContainerPageDefaultFile(folder);
                if (m_hasContainerPageDefaultFile) {
                    m_actionCombo.addItem(Action.container_page_automatic);
                    m_actionCombo.setItemCaption(Action.container_page_automatic,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_AUTOMATIC_0));
                    m_actionCombo.addItem(Action.container_page_copy);
                    m_actionCombo.setItemCaption(Action.container_page_copy,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_CONTAINERPAGE_COPY_0));
                    m_actionCombo.addItem(Action.container_page_reuse);
                    m_actionCombo.setItemCaption(Action.container_page_reuse,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_CONTAINERPAGE_REUSE_0));
                }
                if (CmsResourceTypeFolderSubSitemap.isSubSitemap(folder)) {
                    m_actionCombo.addItem(Action.sub_sitemap);
                    m_actionCombo.setItemCaption(Action.sub_sitemap,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_SUBSITEMAP_0));
                }
                m_actionCombo.addItem(Action.copy_sibling_mixed);
                m_actionCombo.setItemCaption(Action.copy_sibling_mixed, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_NO_SIBLINGS_0));
                m_actionCombo.addItem(Action.copy_all);
                m_actionCombo.setItemCaption(Action.copy_all,
                        CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_0));
                m_actionCombo.addItem(Action.copy_sibling_all);
                m_actionCombo.setItemCaption(Action.copy_sibling_all, CmsVaadinUtils.getMessageText(
                        org.opencms.workplace.commons.Messages.GUI_COPY_MULTI_CREATE_SIBLINGS_0));
                if (m_dialogMode == DialogMode.copy_and_move) {
                    m_actionCombo.addItem(Action.move);
                    m_actionCombo.setItemCaption(Action.move, CmsVaadinUtils.getMessageText(
                            org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_MOVE_FOLDER_0));
                }
            }
        } else {
            m_actionCombo.addItem(Action.copy_sibling_mixed);
            m_actionCombo.setItemCaption(Action.copy_sibling_mixed, CmsVaadinUtils
                    .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_NO_SIBLINGS_0));
            m_actionCombo.addItem(Action.copy_all);
            m_actionCombo.setItemCaption(Action.copy_all,
                    CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_0));
            m_actionCombo.addItem(Action.copy_sibling_all);
            m_actionCombo.setItemCaption(Action.copy_sibling_all, CmsVaadinUtils
                    .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MULTI_CREATE_SIBLINGS_0));
            if (m_dialogMode == DialogMode.copy_and_move) {
                m_actionCombo.addItem(Action.move);
                m_actionCombo.setItemCaption(Action.move, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_MOVE_RESOURCES_0));
            }
        }
        m_actionCombo.setItemStyleGenerator(new ItemStyleGenerator() {

            private static final long serialVersionUID = 1L;

            public String getStyle(ComboBox source, Object itemId) {

                String style = null;
                if (m_defaultActions.contains(itemId)) {
                    style = "bold";
                }
                return style;
            }
        });
        form.addComponent(m_actionCombo);
    }
    if (m_context.getResources().size() > 1) {
        m_overwriteExisting = new CheckBox(CmsVaadinUtils
                .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MULTI_OVERWRITE_0));
        m_overwriteExisting.setValue(Boolean.FALSE);
        form.addComponent(m_overwriteExisting);
    }

    return form;
}

From source file:org.opencms.ui.dialogs.permissions.CmsPrincipalSelect.java

License:Open Source License

/**
 * Constructor.<p>/*from  w w  w .ja v  a  2  s .  c o  m*/
 */
public CmsPrincipalSelect() {

    m_main = new HorizontalLayout();
    m_main.setSpacing(true);
    m_main.setWidth("100%");
    setCompositionRoot(m_main);

    m_widgetType = WidgetType.principalwidget;

    m_principalTypeSelect = new ComboBox();
    m_principalTypeSelect.setWidth("150px");
    Map<String, String> principalTypes = new LinkedHashMap<String, String>();
    principalTypes.put(I_CmsPrincipal.PRINCIPAL_USER,
            CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_USER_0));
    principalTypes.put(I_CmsPrincipal.PRINCIPAL_GROUP,
            CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_GROUP_0));
    CmsVaadinUtils.prepareComboBox(m_principalTypeSelect, principalTypes);

    m_principalTypeSelect.setNewItemsAllowed(false);
    m_principalTypeSelect.setNullSelectionAllowed(false);
    m_principalTypeSelect.select(I_CmsPrincipal.PRINCIPAL_USER);
    m_main.addComponent(m_principalTypeSelect);

    m_principalName = new TextField();
    m_principalName.setWidth("100%");
    m_main.addComponent(m_principalName);
    m_main.setExpandRatio(m_principalName, 2);

    m_selectPrincipalButton = new Button(FontAwesome.USER);
    m_selectPrincipalButton.addStyleName(OpenCmsTheme.BUTTON_ICON);
    m_selectPrincipalButton.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            openPrincipalSelect();
        }
    });
    m_main.addComponent(m_selectPrincipalButton);
}

From source file:org.opencms.ui.editors.CmsSourceEditor.java

License:Open Source License

/**
 * @see org.opencms.ui.editors.I_CmsEditor#initUI(org.opencms.ui.apps.I_CmsAppUIContext, org.opencms.file.CmsResource, java.lang.String)
 *//*  w w  w .  j  a v  a 2s .  co m*/
public void initUI(I_CmsAppUIContext context, CmsResource resource, String backLink) {

    CmsMessages messages = Messages.get().getBundle(UI.getCurrent().getLocale());
    context.showInfoArea(false);
    context.setAppTitle(messages.key(Messages.GUI_SOURCE_EDITOR_TITLE_0));
    CmsAppWorkplaceUi.setWindowTitle(CmsVaadinUtils.getMessageText(
            org.opencms.ui.apps.Messages.GUI_CONTENT_EDITOR_TITLE_2, resource.getName(),
            CmsResource.getParentFolder(A_CmsUI.getCmsObject().getSitePath(resource))));
    m_backLink = backLink;
    m_codeMirror = new CmsCodeMirror();
    m_codeMirror.setSizeFull();
    context.setAppContent(m_codeMirror);
    context.enableDefaultToolbarButtons(false);
    m_saveAndExit = CmsToolBar.createButton(FontOpenCms.SAVE_EXIT,
            messages.key(Messages.GUI_BUTTON_SAVE_AND_EXIT_0), true);
    m_saveAndExit.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            saveAndExit();
        }

    });
    m_saveAndExit.setEnabled(false);
    context.addToolbarButton(m_saveAndExit);

    m_save = CmsToolBar.createButton(FontOpenCms.SAVE, messages.key(Messages.GUI_BUTTON_SAVE_0), true);
    m_save.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            save();
        }

    });
    m_save.setEnabled(false);
    context.addToolbarButton(m_save);

    Button undo = CmsToolBar.createButton(FontOpenCms.UNDO, messages.key(Messages.GUI_BUTTON_UNDO_0), true);
    context.addToolbarButton(undo);

    Button redo = CmsToolBar.createButton(FontOpenCms.REDO, messages.key(Messages.GUI_BUTTON_REDO_0), true);
    context.addToolbarButton(redo);

    m_codeMirror.registerUndoRedo(undo, redo);

    Button search = CmsToolBar.createButton(FontOpenCms.SEARCH, messages.key(Messages.GUI_BUTTON_SEARCH_0),
            true);
    context.addToolbarButton(search);

    Button replace = CmsToolBar.createButton(FontOpenCms.SEARCH_REPLACE,
            messages.key(Messages.GUI_BUTTON_REPLACE_0), true);
    context.addToolbarButton(replace);

    m_codeMirror.registerSearchReplace(search, replace);

    EditorSettings settings;
    try {
        settings = OpenCms.getWorkplaceAppManager().getAppSettings(A_CmsUI.getCmsObject(),
                EditorSettings.class);

    } catch (Exception e) {
        settings = new EditorSettings();
    }

    final Button toggleHighlight = CmsToolBar.createButton(FontOpenCms.HIGHLIGHT,
            messages.key(Messages.GUI_BUTTON_TOGGLE_HIGHLIGHTING_0));
    toggleHighlight.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setHighlighting(!pressed);
        }

    });
    if (settings.m_highlighting) {
        m_codeMirror.setHighlighting(true);
        toggleHighlight.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setHighlighting(false);
    }
    context.addToolbarButtonRight(toggleHighlight);

    final Button toggleLineWrap = CmsToolBar.createButton(FontOpenCms.WRAP_LINES,
            messages.key(Messages.GUI_BUTTON_TOGGLE_LINE_WRAPPING_0));
    toggleLineWrap.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setLineWrapping(!pressed);
        }

    });
    if (settings.m_lineWrapping) {
        m_codeMirror.setLineWrapping(true);
        toggleLineWrap.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setLineWrapping(false);
    }
    context.addToolbarButtonRight(toggleLineWrap);

    final Button toggleBrackets = CmsToolBar.createButton(FontOpenCms.BRACKETS,
            messages.key(Messages.GUI_BUTTON_TOBBLE_BRACKET_AUTOCLOSE_0));
    toggleBrackets.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setCloseBrackets(!pressed);
        }

    });
    if (settings.m_closeBrackets) {
        m_codeMirror.setCloseBrackets(true);
        toggleBrackets.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setCloseBrackets(false);
    }
    context.addToolbarButtonRight(toggleBrackets);

    final Button toggleTabs = CmsToolBar.createButton(FontOpenCms.INVISIBLE_CHARS,
            messages.key(Messages.GUI_BUTTON_TOGGLE_TAB_VISIBILITY_0));
    toggleTabs.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setTabsVisible(!pressed);
        }

    });
    if (settings.m_tabsVisible) {
        m_codeMirror.setTabsVisible(true);
        toggleTabs.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setTabsVisible(false);
    }
    context.addToolbarButtonRight(toggleTabs);

    ComboBox modeSelect = new ComboBox();
    modeSelect.setWidth("115px");
    modeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD);
    modeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON);
    modeSelect.setNullSelectionAllowed(false);
    modeSelect.setImmediate(true);
    modeSelect.setNewItemsAllowed(false);
    for (CodeMirrorLanguage lang : CodeMirrorLanguage.values()) {
        modeSelect.addItem(lang);
        modeSelect.setItemCaption(lang, lang.name());
    }
    CodeMirrorLanguage lang = getHighlightMode(resource);
    modeSelect.setValue(lang);
    m_codeMirror.setLanguage(lang);
    modeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            m_codeMirror.setLanguage((CodeMirrorLanguage) event.getProperty().getValue());
        }
    });
    context.addToolbarButtonRight(modeSelect);

    ComboBox fontSizeSelect = new ComboBox();
    fontSizeSelect.setWidth("75px");
    fontSizeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD);
    fontSizeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON);
    fontSizeSelect.setNullSelectionAllowed(false);
    fontSizeSelect.setImmediate(true);
    fontSizeSelect.setNewItemsAllowed(false);
    for (int i = 0; i < FONT_SIZES.length; i++) {
        fontSizeSelect.addItem(FONT_SIZES[i]);
    }
    fontSizeSelect.setValue(settings.m_fontSize);
    fontSizeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            m_codeMirror.setFontSize((String) event.getProperty().getValue());
        }
    });
    context.addToolbarButtonRight(fontSizeSelect);
    m_codeMirror.setFontSize(settings.m_fontSize);

    m_exit = CmsToolBar.createButton(FontOpenCms.EXIT, messages.key(Messages.GUI_BUTTON_CANCEL_0), true);
    m_exit.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            exit();
        }

    });
    context.addToolbarButtonRight(m_exit);

    try {
        m_file = LockedFile.lockResource(A_CmsUI.getCmsObject(), resource);
        String content = new String(m_file.getFile().getContents(), m_file.getEncoding());
        m_codeMirror.setValue(content);
    } catch (Exception e) {
        CmsErrorDialog.showErrorDialog(e);
    }
    m_codeMirror.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            onChange((String) event.getProperty().getValue());
        }
    });
}

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.
 */// w ww  . j a v a  2  s.  co  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;
}