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:com.github.carljmosca.ui.MainUI.java

private void addHeader() {
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);// w w  w .java 2 s.  co  m
    cmbWidgets = new ComboBox();
    cmbWidgets.setContainerDataSource(widgets);
    cmbWidgets.setItemCaptionPropertyId("name");
    hl.addComponent(cmbWidgets);

    Button btnUpdate = new Button("Update", FontAwesome.ADJUST);
    btnUpdate.addClickListener((Button.ClickEvent event) -> {
        cmbWidgets.select(widgets.getIdByIndex(0));
    });
    hl.addComponent(btnUpdate);

    Button btnShow = new Button("Show", FontAwesome.DASHBOARD);
    btnShow.addClickListener((Button.ClickEvent event) -> {
        try {
            fgWidget.commit();
        } catch (FieldGroup.CommitException ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println(demoAppData.getSelectedWidget().getName());
    });
    hl.addComponent(btnShow);

    Button btnChange = new Button("Change", FontAwesome.REFRESH);
    btnChange.addClickListener((Button.ClickEvent event) -> {
        Widget widget = (Widget) biDemoAppData.getItemProperty("selectedWidget").getValue();
        widget.setName("test xxxx");
        System.out.println(demoAppData.getSelectedWidget().getName());
    });
    hl.addComponent(btnChange);

    mainLayout.addComponent(hl);
}

From source file:com.github.cjm.TmdbUI.java

private void addUserGrid() {
    userSectionLayout.setSpacing(true);//from   www  .  j a v  a  2  s  .  c om
    userSectionLayout.setWidth("100%");
    username = new ComboBox();
    username.setInputPrompt("name");
    username.setNewItemsAllowed(true);
    username.setTextInputAllowed(true);
    username.addValueChangeListener((Property.ValueChangeEvent event) -> {
        userFavorites.removeAllItems();
        if (username.getValue() != null) {
            User u = (User) username.getValue();
            if (u.getFavoriteTvShows() != null) {
                for (Integer id : u.getFavoriteTvShows()) {
                    userFavorites.addItem(getTvShow(id));
                }
            }
        }
    });
    username.setNewItemHandler((String newItemCaption) -> {
        if (newItemCaption != null) {
            User u = findUser(newItemCaption);
            users.addBean(u);
            username.setValue(u);
        }
    });
    users = new BeanItemContainer<>(User.class);
    for (User user : userDao.findAll()) {
        users.addBean(user);
    }
    username.setContainerDataSource(users);
    username.setImmediate(true);
    username.setItemCaptionPropertyId("username");
    userSectionLayout.addComponent(username);
    userFavorites = new ListSelect("Favorites");
    userFavorites.setWidth("70%");
    favorites = new BeanItemContainer<>(TvShow.class);
    userFavorites.setContainerDataSource(favorites);
    userFavorites.setItemCaptionPropertyId("name");
    userSectionLayout.addComponent(userFavorites);
    userSectionLayout.setExpandRatio(username, 1.0f);
    userSectionLayout.setExpandRatio(userFavorites, 2.0f);
    mainLayout.addComponent(userSectionLayout);

}

From source file:com.github.mjvesa.herd.wordset.VaadinWordSet.java

License:Apache License

@Override
public Word[] getWords() {
    return new Word[] {

            new BaseWord("new-button", "", Word.POSTPONED) {

                private static final long serialVersionUID = -2492817908731559368L;

                @Override/*from  w  w w.j  a  v  a  2s  .  co m*/
                public void execute(final Interpreter interpreter) {

                    Button b = new Button("", new Button.ClickListener() {
                        private static final long serialVersionUID = -4622489800920283752L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            Button b = event.getButton();
                            Word command = (Word) b.getData();
                            if (command != null) {
                                interpreter.execute(command);
                            }
                        }
                    });
                    interpreter.pushData(b);
                }
            },

            new BaseWord("set-click-listener", "", Word.POSTPONED) {

                private static final long serialVersionUID = 5749856686458297558L;

                @Override
                public void execute(Interpreter interpreter) {
                    Object o = interpreter.popData();
                    Button b = (Button) interpreter.popData();
                    b.setData(o);
                    interpreter.pushData(b);
                }
            },

            new BaseWord("new-hl", "", Word.POSTPONED) {

                private static final long serialVersionUID = 8813556668649386248L;

                @Override
                public void execute(Interpreter interpreter) {
                    HorizontalLayout hl = new HorizontalLayout();
                    hl.setSpacing(true);
                    interpreter.pushData(hl);
                }
            },

            new BaseWord("new-vl", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1848213448504804229L;

                @Override
                public void execute(Interpreter interpreter) {
                    VerticalLayout vl = new VerticalLayout();
                    vl.setSpacing(true);
                    interpreter.pushData(vl);
                }
            },

            new BaseWord("new-gl", "( x y - gl )", Word.POSTPONED) {

                private static final long serialVersionUID = 4079634885691605257L;

                @Override
                public void execute(Interpreter interpreter) {
                    Integer height = (Integer) interpreter.popData();
                    Integer width = (Integer) interpreter.popData();
                    interpreter.pushData(new GridLayout(width, height));
                }
            },

            new BaseWord("gl-new-line", "", Word.POSTPONED) {

                private static final long serialVersionUID = 975877390052961807L;

                @Override
                public void execute(Interpreter interpreter) {
                    ((GridLayout) interpreter.peekData()).newLine();
                }
            },

            new BaseWord("new-window", "", Word.POSTPONED) {

                private static final long serialVersionUID = -6887364362728545090L;

                @Override
                public void execute(Interpreter interpreter) {
                    Window w = new Window();
                    VerticalLayout vl = new VerticalLayout();
                    vl.setSpacing(true);
                    w.setContent(vl);
                    interpreter.pushData(w);
                    interpreter.pushData(vl);
                }
            },

            new BaseWord("main-panel", "", Word.POSTPONED) {

                private static final long serialVersionUID = -8622281600566696475L;

                @Override
                public void execute(Interpreter interpreter) {
                    interpreter.pushData(interpreter.getMainPanel());
                }
            },

            new BaseWord("add-window", "", Word.POSTPONED) {

                private static final long serialVersionUID = 7106029415576813922L;

                @Override
                public void execute(Interpreter interpreter) {
                    Window w = (Window) interpreter.popData();
                    interpreter.getView().getUI().addWindow(w);
                }
            },

            new BaseWord("add-component", "", Word.POSTPONED) {

                private static final long serialVersionUID = 5640824046985354091L;

                @Override
                public void execute(Interpreter interpreter) {
                    Component comp = (Component) interpreter.popData();
                    ComponentContainer cc = (ComponentContainer) interpreter.popData();
                    cc.addComponent(comp);
                    interpreter.pushData(cc);
                }
            },

            new BaseWord("set-caption", "", Word.POSTPONED) {

                private static final long serialVersionUID = 5497598050469462487L;

                @Override
                public void execute(Interpreter interpreter) {
                    String s = (String) interpreter.popData();
                    Component c = (Component) interpreter.popData();
                    c.setCaption(s);
                    interpreter.pushData(c);
                }
            },

            new BaseWord("set-value", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1769743552659215058L;

                @Override
                public void execute(Interpreter interpreter) {
                    Object o = interpreter.popData();
                    Property p = (Property) interpreter.popData();
                    p.setValue(o);
                    interpreter.pushData(p);
                }
            },

            new BaseWord("get-value", "", Word.POSTPONED) {

                private static final long serialVersionUID = 8445550546521886374L;

                @Override
                public void execute(Interpreter interpreter) {
                    Field f = (Field) interpreter.popData();
                    interpreter.pushData(f);
                    interpreter.pushData(f.getValue());

                }
            },

            new BaseWord("set-size-full", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1206491811133054467L;

                @Override
                public void execute(Interpreter interpreter) {
                    Component comp = (Component) interpreter.popData();
                    comp.setSizeFull();
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("set-size-undefined", "", Word.POSTPONED) {

                private static final long serialVersionUID = -3450618729379622987L;

                @Override
                public void execute(Interpreter interpreter) {
                    Component comp = (Component) interpreter.popData();
                    comp.setSizeUndefined();
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("set-height", "", Word.POSTPONED) {

                private static final long serialVersionUID = -8426734568403715950L;

                @Override
                public void execute(Interpreter interpreter) {
                    String str = (String) interpreter.popData();
                    Component comp = (Component) interpreter.popData();
                    comp.setHeight(str);
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("set-width", "", Word.POSTPONED) {

                private static final long serialVersionUID = -4558264143049463814L;

                @Override
                public void execute(Interpreter interpreter) {
                    String str = (String) interpreter.popData();
                    Component comp = (Component) interpreter.popData();
                    comp.setWidth(str);
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("clear-container", "", Word.POSTPONED) {

                private static final long serialVersionUID = 1070175466682034329L;

                @Override
                public void execute(Interpreter interpreter) {
                    ComponentContainer cc = (ComponentContainer) interpreter.popData();
                    cc.removeAllComponents();
                }
            },

            new BaseWord("new-check-box", "", Word.POSTPONED) {

                private static final long serialVersionUID = 4018632924389912599L;

                @Override
                public void execute(Interpreter interpreter) {
                    interpreter.pushData(new CheckBox());
                }
            },

            new BaseWord("new-date-field", "", Word.POSTPONED) {

                private static final long serialVersionUID = 6313296566085274642L;

                @Override
                public void execute(final Interpreter interpreter) {
                    interpreter.pushData(new DateField());
                    final String dfCommand = (String) interpreter.popData();
                    DateField df = new DateField();
                    df.setImmediate(true);
                    df.addValueChangeListener(new ValueChangeListener() {
                        /**
                        * 
                        */
                        private static final long serialVersionUID = 1472139878970514093L;

                        public void valueChange(ValueChangeEvent event) {
                            interpreter.pushData(event.getProperty().getValue());
                            interpreter.interpret(dfCommand);
                        }

                    });
                    interpreter.pushData(df);
                }
            },

            new BaseWord("new-label", "", Word.POSTPONED) {

                private static final long serialVersionUID = -2825285195439247251L;

                @Override
                public void execute(Interpreter interpreter) {
                    interpreter.pushData(new Label());
                }
            },

            new BaseWord("new-text-field", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1064489458253275380L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String tfCommand = interpreter.getNextNonNopWord();
                    TextField tf = new TextField();
                    tf.setCaption((String) interpreter.popData());
                    tf.setValue("");
                    tf.setImmediate(true);
                    tf.addValueChangeListener(new ValueChangeListener() {
                        private static final long serialVersionUID = 4325104922208051065L;

                        public void valueChange(ValueChangeEvent event) {
                            interpreter.pushData(event.getProperty().getValue());
                            interpreter.interpret(tfCommand);
                        }
                    });
                    interpreter.pushData(tf);
                }
            },

            new BaseWord("new-table", "", Word.POSTPONED) {

                private static final long serialVersionUID = -5052653341575232035L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String tableCommand = interpreter.getParser().getNextWord();
                    Table table = new Table();
                    table.setCaption((String) interpreter.popData());
                    table.setImmediate(true);
                    table.setSelectable(true);
                    table.addItemClickListener(new ItemClickListener() {

                        /**
                        *
                        */
                        private static final long serialVersionUID = 3585546076571010729L;

                        public void itemClick(ItemClickEvent event) {

                            interpreter.pushData(event.getItem());
                            interpreter.execute(interpreter.getDictionary().get(tableCommand));
                        }
                    });
                    interpreter.pushData(table);
                }
            },

            new BaseWord("new-combo-box", "", Word.POSTPONED) {

                private static final long serialVersionUID = 3881577354424928897L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String newItemCommand = interpreter.getParser().getNextWord();
                    final String itemSelectedCommand = interpreter.getParser().getNextWord();
                    final ComboBox cb = new ComboBox();
                    String str = (String) interpreter.popData();
                    cb.setNullSelectionAllowed(false);
                    cb.setCaption(str);
                    cb.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM);
                    cb.setNewItemsAllowed(true);
                    cb.setNewItemHandler(new NewItemHandler() {

                        /**
                        *
                        */
                        private static final long serialVersionUID = 3340658590351611289L;

                        public void addNewItem(String newItemCaption) {
                            cb.setImmediate(false);
                            interpreter.pushData(newItemCaption);
                            interpreter.interpret(newItemCommand);
                            cb.setImmediate(true);
                        }
                    });

                    cb.addValueChangeListener(new ValueChangeListener() {

                        /**
                        *
                        */
                        private static final long serialVersionUID = 2706579869793251379L;

                        public void valueChange(ValueChangeEvent event) {
                            interpreter.pushData(
                                    cb.getContainerDataSource().getItem(event.getProperty().getValue()));
                            interpreter.interpret(itemSelectedCommand);
                        }
                    });
                    cb.setImmediate(true);
                    interpreter.pushData(cb);
                }
            },

            new BaseWord("new-select", "", Word.POSTPONED) {

                private static final long serialVersionUID = -6142351970812196488L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String selCommand = interpreter.getParser().getNextWord();
                    final ComboBox sel = new ComboBox();
                    sel.setCaption((String) interpreter.popData());
                    sel.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM);
                    sel.setNullSelectionAllowed(false);
                    sel.setImmediate(true);
                    sel.addValueChangeListener(new ValueChangeListener() {
                        /**
                        *
                        */
                        private static final long serialVersionUID = -7705548618092166199L;

                        public void valueChange(ValueChangeEvent event) {
                            Item item = sel.getContainerDataSource().getItem(event.getProperty().getValue());
                            interpreter.pushData(item);
                            interpreter.interpret(selCommand);
                        }
                    });
                    interpreter.pushData(sel);
                }
            },

            new BaseWord("new-list-select", "", Word.POSTPONED) {
                private static final long serialVersionUID = 8686093227035249035L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String lselCommand = interpreter.getParser().getNextWord();
                    final ListSelect lsel = new ListSelect();
                    lsel.setCaption((String) interpreter.popData());
                    lsel.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM);
                    lsel.setNullSelectionAllowed(false);
                    lsel.setImmediate(true);
                    lsel.addValueChangeListener(new ValueChangeListener() {
                        private static final long serialVersionUID = -5523488417834167806L;

                        public void valueChange(ValueChangeEvent event) {
                            Item item = lsel.getContainerDataSource().getItem(event.getProperty().getValue());
                            interpreter.pushData(item);
                            interpreter.interpret(lselCommand);
                        }
                    });
                    interpreter.pushData(lsel);
                }
            },

            new BaseWord("set-container-data-source", "", Word.POSTPONED) {
                private static final long serialVersionUID = 8644721936358613031L;

                @Override
                public void execute(Interpreter interpreter) {
                    Container cont = (Container) interpreter.popData();
                    AbstractSelect as = (AbstractSelect) interpreter.popData();
                    as.setContainerDataSource(cont);
                    interpreter.pushData(as);
                }
            },

            new BaseWord("set-column-headers", "", Word.POSTPONED) {
                private static final long serialVersionUID = -7296881714369214846L;

                @Override
                public void execute(Interpreter interpreter) {
                    Table table = (Table) interpreter.popData();
                    table.setColumnHeaders((String[]) getArrayFromList(interpreter, new String[0]));
                }
            },

            new BaseWord("set-visible-columns", "", Word.POSTPONED) {
                private static final long serialVersionUID = 5674765074478598320L;

                @Override
                public void execute(Interpreter interpreter) {
                    Table table = (Table) interpreter.popData();
                    table.setVisibleColumns((String[]) getArrayFromList(interpreter, new String[0]));
                }
            }

    };
}

From source file:com.github.moscaville.contactsdb.main.DetailView.java

private ComboBox createComboBox(String label, List<LookupBase> items, HorizontalLayout horizontalLayout) {
    ComboBox comboBox = new ComboBox();
    RepresentativeUIConverter converter = new RepresentativeUIConverter(items);
    comboBox.setConverter(converter);/*from  ww w .  j a v  a2  s. c om*/
    comboBox.setInputPrompt(label);
    comboBox.setImmediate(true);
    List<String> ids = new ArrayList<>();
    items.stream().forEach((item) -> {
        ids.add(item.getName());
    });
    comboBox.addItems(ids);
    horizontalLayout.addComponent(comboBox);
    return comboBox;
}

From source file:com.github.peholmst.i18n4vaadin.cdi.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);/*from  www . jav  a2 s  . co m*/
    content.setSpacing(true);
    content.setSizeFull();
    setContent(content);

    languageChanger = new ComboBox();
    languageChanger.setContainerDataSource(
            new BeanItemContainer<java.util.Locale>(java.util.Locale.class, i18n.getSupportedLocales()));
    languageChanger.setImmediate(true);
    languageChanger.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (languageChanger.getValue() != null) {
                i18n.setLocale((java.util.Locale) languageChanger.getValue());
            }
        }
    });
    content.addComponent(languageChanger);

    Panel viewContent = new Panel();
    viewContent.setSizeFull();
    content.addComponent(viewContent);
    content.setExpandRatio(viewContent, 1);

    Navigator navigator = new Navigator(this, viewContent);
    navigator.addProvider(viewProvider);
    navigator.navigateTo("demo");
    setNavigator(navigator);

    updateStrings();
}

From source file:com.github.peholmst.i18n4vaadin.simple.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);/*  w ww  .  j av  a  2s .  com*/
    content.setSpacing(true);
    content.setSizeFull();
    setContent(content);

    languageChanger = new ComboBox();
    languageChanger.setContainerDataSource(
            new BeanItemContainer<java.util.Locale>(java.util.Locale.class, i18n.getSupportedLocales()));
    languageChanger.setImmediate(true);
    languageChanger.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (languageChanger.getValue() != null) {
                i18n.setLocale((java.util.Locale) languageChanger.getValue());
            }
        }
    });
    content.addComponent(languageChanger);

    Panel viewContent = new Panel();
    viewContent.setSizeFull();
    content.addComponent(viewContent);
    content.setExpandRatio(viewContent, 1);

    Navigator navigator = new Navigator(this, viewContent);
    navigator.addView("demo", DemoView.class);
    navigator.navigateTo("demo");
    setNavigator(navigator);

    updateStrings();
}

From source file:com.haulmont.cuba.web.app.folders.FolderEditWindow.java

License:Apache License

public FolderEditWindow(boolean adding, Folder folder, Presentations presentations, Runnable commitHandler) {
    this.folder = folder;
    this.commitHandler = commitHandler;

    messages = AppBeans.get(Messages.NAME);
    messagesPack = AppConfig.getMessagesPack();
    userSessionSource = AppBeans.get(UserSessionSource.NAME);
    Configuration configuration = AppBeans.get(Configuration.NAME);
    clientConfig = configuration.getConfig(ClientConfig.class);

    setCaption(adding ? getMessage("folders.folderEditWindow.adding") : getMessage("folders.folderEditWindow"));

    ThemeConstants theme = App.getInstance().getThemeConstants();
    setWidthUndefined();//from  www.j  a  va 2s  . c om
    setResizable(false);

    int[] modifiers = { ShortcutAction.ModifierKey.CTRL };
    addAction(new ShortcutListener("commit", com.vaadin.event.ShortcutAction.KeyCode.ENTER, modifiers) {
        @Override
        public void handleAction(Object sender, Object target) {
            commit();
        }
    });

    layout = new VerticalLayout();
    layout.setWidthUndefined();
    layout.setSpacing(true);

    setContent(layout);
    setModal(true);
    center();

    String fieldWidth = theme.get("cuba.web.FolderEditWindow.field.width");

    nameField = new TextField();
    nameField.setRequired(true);
    nameField.setCaption(getMessage("folders.folderEditWindow.nameField"));
    nameField.setWidth(fieldWidth);
    nameField.setValue(folder.getName());
    nameField.focus();
    layout.addComponent(nameField);

    tabNameField = new TextField();
    tabNameField.setCaption(getMessage("folders.folderEditWindow.tabNameField"));
    tabNameField.setWidth(fieldWidth);
    tabNameField.setValue(StringUtils.trimToEmpty(folder.getTabName()));
    layout.addComponent(tabNameField);

    parentSelect = new ComboBox();
    parentSelect.setCaption(getMessage("folders.folderEditWindow.parentSelect"));
    parentSelect.setWidth(fieldWidth);
    parentSelect.setNullSelectionAllowed(true);
    fillParentSelect();
    parentSelect.setValue(folder.getParent());
    layout.addComponent(parentSelect);

    if (folder instanceof SearchFolder) {
        if (presentations != null) {
            presentation = new ComboBox();
            presentation.setCaption(getMessage("folders.folderEditWindow.presentation"));
            presentation.setWidth(fieldWidth);
            presentation.setNullSelectionAllowed(true);
            fillPresentations(presentations);
            presentation.setValue(((SearchFolder) folder).getPresentation());
            layout.addComponent(presentation);
        } else if (((SearchFolder) folder).getPresentation() != null) {
            selectedPresentationField = new TextField();
            selectedPresentationField.setWidth(fieldWidth);
            selectedPresentationField.setCaption(getMessage("folders.folderEditWindow.presentation"));
            selectedPresentationField.setValue(((SearchFolder) folder).getPresentation().getName());
            selectedPresentationField.setEnabled(false);
            layout.addComponent(selectedPresentationField);
        }
    }

    sortOrderField = new TextField();
    sortOrderField.setCaption(getMessage("folders.folderEditWindow.sortOrder"));
    sortOrderField.setWidth(fieldWidth);
    sortOrderField.setValue(folder.getSortOrder() == null ? "" : folder.getSortOrder().toString());
    layout.addComponent(sortOrderField);

    if (userSessionSource.getUserSession().isSpecificPermitted("cuba.gui.searchFolder.global")
            && folder instanceof SearchFolder && BooleanUtils.isNotTrue(((SearchFolder) folder).getIsSet())) {
        globalCb = new CubaCheckBox(getMessage("folders.folderEditWindow.global"));
        globalCb.setValue(((SearchFolder) folder).getUser() == null);
        layout.addComponent(globalCb);
    }

    applyDefaultCb = new CubaCheckBox(getMessage("folders.folderEditWindow.applyDefault"));
    applyDefaultCb.setValue(BooleanUtils.isTrue(((AbstractSearchFolder) folder).getApplyDefault()));
    applyDefaultCb.setVisible(clientConfig.getGenericFilterManualApplyRequired()
            && folder instanceof SearchFolder && BooleanUtils.isNotTrue(((SearchFolder) folder).getIsSet()));
    layout.addComponent(applyDefaultCb);

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setMargin(new MarginInfo(true, false, false, false));
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    okBtn = new CubaButton(getMessage("actions.Ok"));
    okBtn.setIcon(WebComponentsHelper.getIcon("icons/ok.png"));
    okBtn.addStyleName(WebButton.ICON_STYLE);

    initButtonOkListener();
    buttonsLayout.addComponent(okBtn);

    cancelBtn = new CubaButton(getMessage("actions.Cancel"));
    cancelBtn.setIcon(WebComponentsHelper.getIcon("icons/cancel.png"));
    cancelBtn.addStyleName(WebButton.ICON_STYLE);
    cancelBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });
    buttonsLayout.addComponent(cancelBtn);

    if (AppUI.getCurrent().isTestMode()) {
        setCubaId("folderEditWindow");

        nameField.setCubaId("nameField");
        tabNameField.setCubaId("tabNameField");
        parentSelect.setCubaId("parentSelect");
        if (presentation != null) {
            presentation.setCubaId("presentationSelect");
        }
        sortOrderField.setCubaId("sortOrderField");
        if (selectedPresentationField != null) {
            selectedPresentationField.setCubaId("selectedPresentationField");
        }
        if (globalCb != null) {
            globalCb.setCubaId("globalCb");
        }
        applyDefaultCb.setCubaId("applyDefaultCb");
        okBtn.setCubaId("okBtn");
        cancelBtn.setCubaId("cancelBtn");
    }
}

From source file:com.haulmont.cuba.web.LoginWindow.java

License:Apache License

public LoginWindow(AppUI ui) {
    log.trace("Creating {}", this);
    this.ui = ui;

    globalConfig = configuration.getConfig(GlobalConfig.class);
    webConfig = configuration.getConfig(WebConfig.class);
    locales = globalConfig.getAvailableLocales();

    app = ui.getApp();//from w  ww . ja va  2  s.  c o m

    resolvedLocale = resolveLocale(app);

    connection = app.getConnection();

    loginField = new TextField();
    passwordField = new CubaPasswordField();
    localesSelect = new ComboBox();
    localesSelect.setTextInputAllowed(false);

    // make fields immediate to resync fast in case of login is already performed from another UI (i.e. browser tab)
    loginField.setImmediate(true);
    passwordField.setImmediate(true);

    localesSelect.setImmediate(true);

    okButton = new CubaButton();
    submitListener = new SubmitListener();

    rememberMeAllowed = webConfig.getRememberMeEnabled();

    if (rememberMeAllowed) {
        rememberMeCheckBox = new CubaCheckBox();
    }

    setSizeFull();

    // load theme from cookies if it is changed by user in settings dialog
    applyUserTheme();

    initUI();

    localesSelect.addValueChangeListener(event -> {
        if (!resolvedLocale.equals(getUserLocale())) {
            resolvedLocale = getUserLocale();
            clearUI();
            initUI();
        }
    });

    if (ui.isTestMode()) {
        loginField.setCubaId("loginField");
        passwordField.setCubaId("passwordField");
        localesSelect.setCubaId("localesField");
        okButton.setCubaId("loginSubmitButton");

        if (rememberMeCheckBox != null) {
            rememberMeCheckBox.setCubaId("rememberMeCheckBox");
        }

        TestIdManager testIdManager = ui.getTestIdManager();

        loginField.setId(testIdManager.reserveId("loginField"));
        passwordField.setId(testIdManager.reserveId("passwordField"));
        localesSelect.setId(testIdManager.reserveId("localesField"));

        okButton.setId(testIdManager.reserveId("loginSubmitButton"));
        if (rememberMeCheckBox != null) {
            rememberMeCheckBox.setId(testIdManager.reserveId("rememberMeCheckBox"));
        }
    }

    addShortcutListener(new ShortcutListener("Default key", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            doLogin();
        }
    });
}

From source file:com.hris.employee.EmployeeUI.java

private ComboBox employeeStatusComboBox() {
    String str[] = { "EMPLOYED", "RESIGNED" };

    ComboBox select = new ComboBox();
    select.setWidth("100%");
    select.addStyleName(ValoTheme.COMBOBOX_SMALL);
    select.addStyleName(ValoTheme.TEXTFIELD_ALIGN_RIGHT);
    select.setNullSelectionAllowed(true);
    select.setImmediate(true);/*from   w  ww.j  a v  a2  s  .c om*/
    select.addContainerProperty("c", String.class, "");
    select.setItemCaptionPropertyId("c");

    Item item = null;
    int i = 0;
    for (String s : str) {
        item = select.addItem(i);
        item.getItemProperty("c").setValue(s);
        i++;
    }

    return select;
}

From source file:com.hris.payroll.alphalist.AlphaListMainUI.java

private ComboBox selectYear() {
    year = new ComboBox();
    year.setWidth("200px");
    year.setNullSelectionAllowed(false);
    year.addStyleName(ValoTheme.COMBOBOX_SMALL);

    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    int y = cal.get(Calendar.YEAR);

    for (int i = y; i > 2011; i--) {
        year.addItem(String.valueOf(i));
    }//from   w w  w . j  a va2s  .  co  m
    year.setValue(String.valueOf(y));

    return year;
}