Example usage for com.vaadin.ui ComboBox setNewItemHandler

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

Introduction

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

Prototype

@Deprecated
public void setNewItemHandler(NewItemHandler newItemHandler) 

Source Link

Document

Sets the handler that is called when user types a new item.

Usage

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 av  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:org.eclipse.skalli.view.component.LinkWindow.java

License:Open Source License

/**
 * Render the window//from   w ww.ja  v a  2 s  . co  m
 */
@SuppressWarnings("serial")
private void createContents(String title) {
    setModal(true);
    setCaption(title);

    setWidth("400px"); //$NON-NLS-1$
    setHeight("300px"); //$NON-NLS-1$

    root = new VerticalLayout();
    root.setMargin(true);
    root.setSpacing(true);

    final ComboBox cbLinkGroup = new ComboBox("Link Group");
    cbLinkGroup.setInputPrompt("Enter a new group name or select from the list");
    cbLinkGroup.setWidth("100%"); //$NON-NLS-1$
    for (String groupName : knownGroups) {
        cbLinkGroup.addItem(groupName);
    }
    if (oldGroup != null && knownGroups.contains(oldGroup.getCaption())) {
        cbLinkGroup.select(oldGroup.getCaption());
    }
    cbLinkGroup.setImmediate(true);
    cbLinkGroup.setNullSelectionAllowed(false);
    cbLinkGroup.setNewItemsAllowed(true);
    cbLinkGroup.setNewItemHandler(new NewItemHandler() {
        @Override
        public void addNewItem(String newGroupName) {
            cbLinkGroup.removeAllItems();
            for (String groupName : knownGroups) {
                cbLinkGroup.addItem(groupName);
            }
            if (!cbLinkGroup.containsId(newGroupName)) {
                cbLinkGroup.addItem(newGroupName);
            }
            cbLinkGroup.select(newGroupName);
        }
    });
    cbLinkGroup.setRequired(true);
    cbLinkGroup.addValidator(new StringValidator());
    root.addComponent(cbLinkGroup);

    final TextField tfLinkCaption = new TextField("Page Title");
    tfLinkCaption.setInputPrompt("Enter a descriptive name for the page");
    tfLinkCaption.setWidth("100%"); //$NON-NLS-1$
    tfLinkCaption.setImmediate(true);
    tfLinkCaption.setRequired(true);
    tfLinkCaption.addValidator(new StringValidator());
    if (link != null) {
        tfLinkCaption.setValue(link.getLabel());
    }
    root.addComponent(tfLinkCaption);

    final TextField tfLinkURL = new TextField("URL");
    tfLinkURL.setInputPrompt("e.g. http://www.your-site.domain/path");
    tfLinkURL.setWidth("100%"); //$NON-NLS-1$
    tfLinkURL.setImmediate(true);
    tfLinkURL.setRequired(true);
    tfLinkURL.addValidator(new StringValidator());
    tfLinkURL.addValidator(new URLValidator());
    if (link != null) {
        tfLinkURL.setValue(link.getUrl());
    }
    root.addComponent(tfLinkURL);

    final Button okAndCloseButton = new Button("OK & Close");
    okAndCloseButton.setIcon(ICON_BUTTON_OK);
    okAndCloseButton.setDescription("Performs the action and closes the dialog.");
    okAndCloseButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            validateInput(cbLinkGroup);
            validateInput(tfLinkURL);
            validateInput(tfLinkCaption);

            if (cbLinkGroup.isValid() && tfLinkURL.isValid() && tfLinkCaption.isValid()) {
                String groupName = String.valueOf(cbLinkGroup.getValue());
                String linkLabel = String.valueOf(tfLinkCaption.getValue());
                String linkUrl = String.valueOf(tfLinkURL.getValue());

                if (linkAddedHandler != null) {
                    Link link = new Link(linkUrl, linkLabel);
                    linkAddedHandler.onLinkAdded(groupName, link);
                    close();
                }

                if (linkModifiedHandler != null) {
                    boolean linkModified = !link.getLabel().equals(linkLabel) || !link.getUrl().equals(linkUrl);
                    link.setLabel(linkLabel);
                    link.setUrl(linkUrl);
                    linkModifiedHandler.onLinkModified(oldGroup, groupName, link, linkModified);
                    close();
                }
            }
        }
    });
    root.addComponent(okAndCloseButton);

    root.setSizeFull();
    setContent(root);
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.TagComponent.java

License:Open Source License

@SuppressWarnings("serial")
private void paintTagComboBoxLayout() {
    tagComboBoxLayout.removeAllComponents();
    // add tag input field
    final ComboBox tagComboBox = new ComboBox();
    SortedMap<String, Integer> availableTags = taggingService.getTags(Project.class);
    for (String tag : availableTags.keySet()) {
        tagComboBox.addItem(tag);/* www. ja v  a  2  s  .c o m*/
    }
    tagComboBox.setNewItemsAllowed(true);
    tagComboBox.setNewItemHandler(new NewItemHandler() {
        @Override
        public void addNewItem(String newItemCaption) {
            Collection<Validator> validators = tagComboBox.getValidators();
            for (Validator val : validators) {
                if (!val.isValid(newItemCaption)) {
                    Iterator<Component> it = tagComboBoxLayout.getComponentIterator();
                    it.next(); // this is the combobox
                    if (!it.hasNext()) {
                        tagComboBoxLayout
                                .addComponent(new Label("Use lowercase letters without whitespaces only."));
                    }
                    return;
                }
            }
            if (!tagComboBox.containsId(newItemCaption)) {
                TaggingUtils.addTags(project, newItemCaption);
                util.persist(project);
                paintTagEdit(); // TODO performance?
            }
        }
    });
    tagComboBox.addListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            if (!TaggingUtils.hasTag(project, event.getProperty().getValue().toString())) {
                TaggingUtils.addTags(project, event.getProperty().getValue().toString());
                util.persist(project);
                paintTagEdit(); // TODO performance?
            }
        }
    });

    tagComboBox.setImmediate(true);
    tagComboBox.setInputPrompt("Enter tag confirmed by enter");
    tagComboBox.setWidth("300px");
    tagComboBox.setNullSelectionAllowed(false);
    tagComboBox.focus();

    tagComboBox.addValidator(new TagValidator());
    tagComboBoxLayout.addComponent(tagComboBox);
}

From source file:org.opennms.features.vaadin.events.EventFormFieldFactory.java

License:Open Source License

public Field createField(Item item, Object propertyId, Component uiContext) {
    if ("logMsgDest".equals(propertyId)) {
        final ComboBox dest = new ComboBox("Destination");
        dest.addItem("logndisplay");
        dest.addItem("logonly");
        dest.addItem("suppress");
        dest.addItem("donotpersist");
        dest.addItem("discardtraps");
        dest.setNullSelectionAllowed(false);
        dest.setRequired(true);//from w w  w . j ava 2  s .c o m
        return dest;
    }
    if ("logMsgContent".equals(propertyId)) {
        final TextArea content = new TextArea("Log Message");
        content.setWidth("100%");
        content.setRows(10);
        content.setRequired(true);
        content.setNullRepresentation("");
        return content;
    }
    if ("alarmDataAlarmType".equals(propertyId)) {
        final ComboBox f = new ComboBox("Alarm Type");
        f.addItem(new Integer(1));
        f.addItem(new Integer(2));
        f.addItem(new Integer(3));
        f.setNewItemHandler(new NewItemHandler() {
            @Override
            public void addNewItem(String newItemCaption) {
                try {
                    f.addItem(new Integer(newItemCaption));
                } catch (Exception e) {
                }
            }
        });
        f.setDescription(
                "<b>1</b> to be a problem that has a possible resolution, alarm-type set to <b>2</b> to be a resolution event, and alarm-type set to <b>3</b> for events that have no possible resolution");
        f.setNullSelectionAllowed(false);
        return f;
    }
    if ("alarmDataAutoClean".equals(propertyId)) {
        final CheckBox f = new CheckBox("Auto Clean");
        f.setWidth("100%");
        return f;
    }
    if ("alarmDataReductionKey".equals(propertyId)) {
        final TextField f = new TextField("Reduction Key");
        f.setWidth("100%");
        f.setNullRepresentation("");
        return f;
    }
    if ("alarmDataClearKey".equals(propertyId)) {
        final TextField f = new TextField("Clear Key");
        f.setWidth("100%");
        f.setNullRepresentation("");
        return f;
    }
    if ("severity".equals(propertyId)) {
        final ComboBox severity = new ComboBox("Severity");
        for (String sev : OnmsSeverity.names()) {
            severity.addItem(sev.substring(0, 1).toUpperCase() + sev.substring(1).toLowerCase());
        }
        severity.setNullSelectionAllowed(false);
        severity.setRequired(true);
        return severity;
    }
    if ("descr".equals(propertyId)) {
        final TextArea descr = new TextArea("Description");
        descr.setWidth("100%");
        descr.setRows(10);
        descr.setRequired(true);
        descr.setNullRepresentation("");
        return descr;
    }
    if ("operinstruct".equals(propertyId)) {
        final TextArea oper = new TextArea("Operator Instructions") {
            @Override
            public Object getValue() { // This is because of the intern usage on Event.setOperInstruct()
                return super.getValue() == null ? "" : super.getValue();
            }
        };
        oper.setWidth("100%");
        oper.setRows(10);
        oper.setNullRepresentation("");
        return oper;
    }
    if ("maskElements".equals(propertyId)) {
        final MaskElementField field = new MaskElementField();
        field.setCaption("Mask Elements");
        return field;
    }
    if ("maskVarbinds".equals(propertyId)) {
        final MaskVarbindField field = new MaskVarbindField();
        field.setCaption("Mask Varbinds");
        return field;
    }
    if ("varbindsdecodeCollection".equals(propertyId)) {
        final VarbindsDecodeField field = new VarbindsDecodeField();
        field.setCaption("Varbind Decodes");
        return field;
    }
    if ("uei".equals(propertyId)) {
        final TextField f = new TextField("Event UEI");
        f.setRequired(true);
        f.setWidth("100%");
        return f;
    }
    if ("eventLabel".equals(propertyId)) {
        final TextField f = new TextField("Event Label");
        f.setRequired(true);
        f.setWidth("100%");
        return f;
    }
    final Field f = DefaultFieldFactory.get().createField(item, propertyId, uiContext);
    f.setWidth("100%");
    return f;
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.PopupRecombineDiseaseGroups.java

private ComboBox generateLabelList(String diseaseCategory) {
    final ComboBox diseaseGroupsList = new ComboBox();
    diseaseGroupsList.setStyleName("diseasegrouplist");
    diseaseGroupsList.setNullSelectionAllowed(false);
    diseaseGroupsList.setImmediate(true);
    diseaseGroupsList.setNewItemsAllowed(true);
    diseaseGroupsList.setWidth(300, Unit.PIXELS);

    diseaseGroupsList.setInputPrompt("Select or enter new disease group name");
    diseaseGroupsList.setPageLength(500);

    for (String name : default_DiseaseCat_DiseaseGroupMap.get(diseaseCategory).values()) {
        diseaseGroupsList.addItem(name);
        if (!captionAstrMap.containsKey(name)) {
            captionAstrMap.put(name, 0);
        }//  w w  w.  j a va 2  s. c  om

    }

    diseaseGroupsList.setNewItemHandler(new AbstractSelect.NewItemHandler() {

        @Override
        public void addNewItem(String newItemCaption) {
            diseaseGroupsList.addItem(newItemCaption + "*");
            diseaseGroupsList.select(newItemCaption + "*");
            captionAstrMap.put(newItemCaption + "*", 1);

        }
    });
    diseaseGroupsList.setHeight("24px");
    diseaseGroupsList.addValueChangeListener(new Property.ValueChangeListener() {

        private String lastSelected = "";

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            String selectedItem = event.getProperty().getValue().toString();
            if (!selectedItem.equalsIgnoreCase(diseaseGroupsList.getData().toString())) {
                String astr = "";
                if (!selectedItem.contains("*")) {
                    astr = "*";
                    captionAstrMap.put(selectedItem, captionAstrMap.get(selectedItem) + 1);
                } else {

                }
                diseaseGroupsList.setItemCaption(selectedItem, selectedItem + astr);
            } else {
                diseaseGroupsList.setItemCaption(diseaseGroupsList.getData().toString(),
                        diseaseGroupsList.getData().toString());
            }
            if (!lastSelected.equalsIgnoreCase("")) {
                captionAstrMap.put(lastSelected, Math.max(captionAstrMap.get(lastSelected) - 1, 0));
            }
            lastSelected = selectedItem;
        }
    });

    return diseaseGroupsList;
}

From source file:ru.codeinside.adm.ui.AdminApp.java

License:Mozilla Public License

private RefreshableTab createSettings() {

    final Form systemForm;
    {//from   w  w  w .  j a va 2 s. c  om
        final ComboBox serviceLocation;
        {
            String[][] defs = { { "? ", "http://195.245.214.33:7777/esv" },
                    { "? ",
                            "http://oraas.rt.ru:7777/gateway/services/SID0003318" } };
            serviceLocation = new ComboBox("?? ?? ");
            serviceLocation.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_EXPLICIT);
            for (String[] def : defs) {
                addOption(serviceLocation, def[1], def[0], false);
            }
            serviceLocation.setImmediate(true);
            serviceLocation.setInputPrompt("http://");
            serviceLocation.setNewItemsAllowed(true);
            serviceLocation.setNewItemHandler(new AbstractSelect.NewItemHandler() {
                @Override
                public void addNewItem(String newItemCaption) {
                    addOption(serviceLocation, newItemCaption, newItemCaption, true);
                }
            });
            String href = AdminServiceProvider.get()
                    .getSystemProperty(CertificateVerifier.VERIFY_SERVICE_LOCATION);
            addOption(serviceLocation, href, href, true);
        }

        final CheckBox allowValidate;
        {
            allowValidate = new CheckBox(" ? ");
            allowValidate.setRequired(true);
            allowValidate.setImmediate(true);
            allowValidate.addListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent event) {
                    serviceLocation.setRequired(Boolean.TRUE.equals(event.getProperty().getValue()));
                }
            });
            allowValidate.setValue(AdminServiceProvider
                    .getBoolProperty(CertificateVerifier.ALLOW_VERIFY_CERTIFICATE_PROPERTY));
        }

        systemForm = new Form();
        systemForm.addField("location", serviceLocation);
        systemForm.addField("allowVerify", allowValidate);
        systemForm.setImmediate(true);
        systemForm.setWriteThrough(false);
        systemForm.setInvalidCommitted(false);

        Button commit = new Button("", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {
                    systemForm.commit();
                    set(CertificateVerifier.VERIFY_SERVICE_LOCATION, serviceLocation.getValue());
                    set(CertificateVerifier.ALLOW_VERIFY_CERTIFICATE_PROPERTY, allowValidate.getValue());
                    event.getButton().getWindow().showNotification("?? ?",
                            Window.Notification.TYPE_HUMANIZED_MESSAGE);
                } catch (Validator.InvalidValueException ignore) {
                }
            }
        });

        HorizontalLayout buttons = new HorizontalLayout();
        buttons.setSpacing(true);
        buttons.addComponent(commit);
        systemForm.getFooter().addComponent(buttons);
    }

    Panel b1 = new Panel();
    b1.setSizeFull();
    Label b1label = new Label(" ?");
    b1label.addStyleName(Reindeer.LABEL_H2);
    b1.addComponent(b1label);
    b1.addComponent(systemForm);

    VerticalLayout certificates = new VerticalLayout();
    certificates.setSizeFull();
    certificates.setSpacing(true);

    HorizontalLayout topHl = new HorizontalLayout();
    topHl.setSizeFull();
    topHl.setSpacing(true);

    Panel certificatesPanel = new Panel("", certificates);
    certificatesPanel.setSizeFull();
    certificatesPanel.addStyleName(Reindeer.PANEL_LIGHT);

    boolean linkCertificate = AdminServiceProvider.getBoolProperty(CertificateVerifier.LINK_CERTIFICATE);
    final CheckBox switchLink = new CheckBox("? ");
    switchLink.setValue(linkCertificate);
    switchLink.setImmediate(true);
    switchLink.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            set(CertificateVerifier.LINK_CERTIFICATE, switchLink.getValue());
            event.getButton().getWindow().showNotification("?? ?",
                    Window.Notification.TYPE_HUMANIZED_MESSAGE);
        }
    });

    Panel b2 = new Panel();
    b2.setSizeFull();
    Label b2label = new Label("? ?");
    b2label.addStyleName(Reindeer.LABEL_H2);
    b2.addComponent(b2label);
    b2.addComponent(switchLink);

    certificates.addComponent(b1);
    certificates.addComponent(b2);
    certificates.setExpandRatio(b1, 0.7f);
    certificates.setExpandRatio(b2, 0.3f);

    CheckBox productionMode = new CheckBox("?  ",
            AdminServiceProvider.getBoolProperty(API.PRODUCTION_MODE));
    productionMode.setImmediate(true);
    productionMode.setDescription(
            " ?   ?   ??   ?? testMsg");
    productionMode.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            boolean value = Boolean.TRUE.equals(event.getProperty().getValue());
            set(API.PRODUCTION_MODE, value);
        }
    });
    Panel smevPanel = new Panel(" ");
    smevPanel.setSizeFull();
    smevPanel.addComponent(productionMode);

    HorizontalLayout bottomHl = new HorizontalLayout();
    bottomHl.setSizeFull();
    bottomHl.setSpacing(true);

    LogSettings logSettings = new LogSettings();
    Panel emailDatesPanel = createEmailDatesPanel();

    Panel mailTaskConfigPanel = createMilTaskConfigPanel();

    topHl.addComponent(certificatesPanel);
    topHl.addComponent(emailDatesPanel);
    topHl.addComponent(mailTaskConfigPanel);
    topHl.setExpandRatio(certificatesPanel, 0.4f);
    topHl.setExpandRatio(emailDatesPanel, 0.6f);
    topHl.setExpandRatio(mailTaskConfigPanel, 0.5f);

    Panel esiaPanel = buildEsiaPanel();
    Panel printTemplatesPanel = buildPrintTemplatesPanel();

    bottomHl.addComponent(smevPanel);
    bottomHl.addComponent(esiaPanel);
    bottomHl.addComponent(printTemplatesPanel);
    bottomHl.setExpandRatio(smevPanel, 0.2f);
    bottomHl.setExpandRatio(esiaPanel, 0.4f);
    bottomHl.setExpandRatio(printTemplatesPanel, 0.4f);

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setSizeFull();
    layout.addComponent(topHl);
    layout.addComponent(logSettings);
    layout.addComponent(bottomHl);
    layout.setExpandRatio(topHl, 0.40f);
    layout.setExpandRatio(logSettings, 0.40f);
    layout.setExpandRatio(bottomHl, 0.20f);
    layout.setMargin(true);
    layout.setSpacing(true);

    return new RefreshableTab(layout, logSettings);
}