Search in sources :

Example 21 with ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class NewGroupPopupWindow method initInputFields.

protected void initInputFields() {
    // Input fields
    form.addField("id", new TextField(i18nManager.getMessage(Messages.GROUP_ID)));
    // Set id field to required
    form.getField("id").setRequired(true);
    form.getField("id").setRequiredError(i18nManager.getMessage(Messages.GROUP_ID_REQUIRED));
    form.getField("id").focus();
    // Set id field to be unique
    form.getField("id").addValidator(new Validator() {

        public void validate(Object value) throws InvalidValueException {
            if (!isValid(value)) {
                throw new InvalidValueException(i18nManager.getMessage(Messages.GROUP_ID_UNIQUE));
            }
        }

        public boolean isValid(Object value) {
            if (value != null) {
                return identityService.createGroupQuery().groupId(value.toString()).singleResult() == null;
            }
            return false;
        }
    });
    form.addField("name", new TextField(i18nManager.getMessage(Messages.GROUP_NAME)));
    ComboBox typeComboBox = new ComboBox(i18nManager.getMessage(Messages.GROUP_TYPE), Arrays.asList("assignment", "security-role"));
    typeComboBox.select("assignment");
    form.addField("type", typeComboBox);
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) Validator(com.vaadin.data.Validator)

Example 22 with ComboBox

use of com.vaadin.ui.ComboBox in project opennms by OpenNMS.

the class MibObjFieldFactory method createField.

/* (non-Javadoc)
     * @see com.vaadin.ui.TableFieldFactory#createField(com.vaadin.data.Container, java.lang.Object, java.lang.Object, com.vaadin.ui.Component)
     */
@Override
public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) {
    if (propertyId.equals("oid")) {
        final TextField field = new TextField();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.addValidator(new RegexpValidator("^\\.[.\\d]+$", "Invalid OID {0}"));
        return field;
    }
    if (propertyId.equals("instance")) {
        final ComboBox field = new ComboBox();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.setNullSelectionAllowed(false);
        field.setNewItemsAllowed(true);
        field.setNewItemHandler(new NewItemHandler() {

            @Override
            public void addNewItem(String newItemCaption) {
                if (!field.containsId(newItemCaption)) {
                    field.addItem(newItemCaption);
                    field.setValue(newItemCaption);
                }
            }
        });
        field.addItem("0");
        field.addItem("ifIndex");
        for (String rt : resourceTypes) {
            field.addItem(rt);
        }
        return field;
    }
    if (propertyId.equals("alias")) {
        final TextField field = new TextField();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.addValidator(new StringLengthValidator("Invalid alias. It should not contain more than 19 characters.", 1, 19, false));
        return field;
    }
    if (propertyId.equals("type")) {
        final TextField field = new TextField();
        field.setSizeFull();
        field.setRequired(true);
        field.setImmediate(true);
        field.addValidator(new // Based on NumericAttributeType and StringAttributeType
        RegexpValidator(// Based on NumericAttributeType and StringAttributeType
        "^(?i)(counter|gauge|timeticks|integer|octetstring|string)?\\d*$", "Invalid type {0}. Valid types are: counter, gauge, timeticks, integer, octetstring, string"));
        return field;
    }
    return null;
}
Also used : ComboBox(com.vaadin.ui.ComboBox) StringLengthValidator(com.vaadin.data.validator.StringLengthValidator) TextField(com.vaadin.ui.TextField) NewItemHandler(com.vaadin.ui.AbstractSelect.NewItemHandler) RegexpValidator(com.vaadin.data.validator.RegexpValidator)

Example 23 with ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class EnumFormPropertyRenderer method getPropertyField.

@SuppressWarnings("unchecked")
@Override
public Field getPropertyField(FormProperty formProperty) {
    ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
    comboBox.setRequired(formProperty.isRequired());
    comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
    comboBox.setEnabled(formProperty.isWritable());
    comboBox.setNullSelectionAllowed(false);
    Object firstItemId = null;
    Object itemToSelect = null;
    Map<String, String> values = (Map<String, String>) formProperty.getType().getInformation("values");
    if (values != null) {
        for (Entry<String, String> enumEntry : values.entrySet()) {
            // Add value and label (if any)
            comboBox.addItem(enumEntry.getKey());
            if (firstItemId == null) {
                // select first element
                firstItemId = enumEntry.getKey();
            }
            String selectedValue = formProperty.getValue();
            if (selectedValue != null && selectedValue.equals(enumEntry.getKey())) {
                // select first element
                itemToSelect = enumEntry.getKey();
            }
            if (enumEntry.getValue() != null) {
                comboBox.setItemCaption(enumEntry.getKey(), enumEntry.getValue());
            }
        }
    }
    // Select value or first element
    if (itemToSelect != null) {
        comboBox.select(itemToSelect);
    } else if (firstItemId != null) {
        comboBox.select(firstItemId);
    }
    return comboBox;
}
Also used : ComboBox(com.vaadin.ui.ComboBox) Map(java.util.Map)

Example 24 with ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class SelectUsersPopupWindow method selectUser.

protected void selectUser(String userId, String userName) {
    if (!selectedUsersTable.containsId(userId)) {
        Item item = selectedUsersTable.addItem(userId);
        item.getItemProperty("userName").setValue(userName);
        if (showRoles) {
            ComboBox comboBox = new ComboBox(null, Arrays.asList(i18nManager.getMessage(Messages.TASK_ROLE_CONTRIBUTOR), i18nManager.getMessage(Messages.TASK_ROLE_IMPLEMENTER), i18nManager.getMessage(Messages.TASK_ROLE_MANAGER), i18nManager.getMessage(Messages.TASK_ROLE_SPONSOR)));
            comboBox.select(i18nManager.getMessage(Messages.TASK_ROLE_CONTRIBUTOR));
            comboBox.setNewItemsAllowed(true);
            item.getItemProperty("role").setValue(comboBox);
        }
    }
}
Also used : Item(com.vaadin.data.Item) ComboBox(com.vaadin.ui.ComboBox)

Example 25 with ComboBox

use of com.vaadin.ui.ComboBox in project charts by vaadin.

the class ChartsDemoUI method init.

@Override
protected void init(VaadinRequest request) {
    initGATracker();
    tabSheet = new TabSheet();
    tabSheet.addSelectedTabChangeListener(new TabSheet.SelectedTabChangeListener() {

        @Override
        public void selectedTabChange(TabSheet.SelectedTabChangeEvent event) {
            com.vaadin.ui.JavaScript.eval("setTimeout(function(){prettyPrint();},300);");
        }
    });
    tabSheet.setSizeFull();
    tabSheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
    Link homepage = new Link("Home page", new ExternalResource("https://vaadin.com/add-ons/charts"));
    Link javadoc = new Link("JavaDoc", new ExternalResource("http://demo.vaadin.com/javadoc/com.vaadin/vaadin-charts/" + getVersion() + "/"));
    Link manual = new Link("Manual", new ExternalResource("https://vaadin.com/docs/-/part/charts/charts-overview.html"));
    Label version = new Label("Version " + getVersion());
    version.addStyleName("version");
    HorizontalLayout links = new HorizontalLayout(homepage, javadoc, manual);
    links.setSpacing(true);
    links.addStyleName("links");
    final HorizontalSplitPanel horizontalSplitPanel = new HorizontalSplitPanel();
    horizontalSplitPanel.setSecondComponent(tabSheet);
    horizontalSplitPanel.setSplitPosition(300, Unit.PIXELS);
    horizontalSplitPanel.addStyleName("main-layout");
    ChartOptions.get().setTheme(new ValoLightTheme());
    themeSelector = new ComboBox("Charts Theme:");
    themeSelector.addStyleName("theme-selector");
    themeSelector.addStyleName(ValoTheme.COMBOBOX_SMALL);
    themeSelector.setTextInputAllowed(false);
    com.vaadin.addon.charts.model.style.Theme defaultTheme = new ValoLightTheme();
    Map<com.vaadin.addon.charts.model.style.Theme, String> mapThemes = new HashMap<>();
    com.vaadin.addon.charts.model.style.Theme[] themes = new com.vaadin.addon.charts.model.style.Theme[] { defaultTheme, new ValoDarkTheme(), new VaadinTheme(), new HighChartsDefaultTheme(), new GridTheme(), new GrayTheme(), new SkiesTheme() };
    mapThemes.put(themes[0], "Valo Light");
    mapThemes.put(themes[1], "Valo Dark");
    mapThemes.put(themes[2], "Vaadin");
    mapThemes.put(themes[3], "HighCharts");
    mapThemes.put(themes[4], "Grid");
    mapThemes.put(themes[5], "Gray");
    mapThemes.put(themes[6], "Skies");
    themeSelector.setEmptySelectionAllowed(false);
    themeSelector.setItems(themes);
    themeSelector.setSelectedItem(defaultTheme);
    themeSelector.setItemCaptionGenerator(mapThemes::get);
    themeSelector.addSelectionListener(e -> {
        ChartOptions.get().setTheme(e.getValue());
    });
    final HierarchicalContainer container = getContainer();
    VerticalLayout content = new VerticalLayout();
    content.setSpacing(true);
    content.setMargin(false);
    Label logo = new Label("Vaadin Charts");
    logo.setWidth("100%");
    logo.addStyleName("h3");
    logo.addStyleName("logo");
    TextField filterField = new TextField();
    filterField.setPlaceholder("Filter examples");
    filterField.setIcon(FontAwesome.SEARCH);
    filterField.addStyleName("filter");
    filterField.setWidth("100%");
    filterField.addValueChangeListener(e -> {
        container.removeAllContainerFilters();
        String text = e.getValue();
        if (text != null && !text.isEmpty()) {
            expandForFiltering();
            container.addContainerFilter("searchName", text, true, false);
        } else {
            restoreExpandedStates();
        }
    });
    tree = new Tree();
    tree.setImmediate(true);
    tree.setContainerDataSource(container);
    tree.setItemCaptionPropertyId("displayName");
    tree.setNullSelectionAllowed(false);
    tree.setWidth("100%");
    tree.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            Object value = event.getProperty().getValue();
            if (value instanceof Class) {
                updateTabSheet((Class) value);
            } else {
                tree.expandItemsRecursively(value);
            }
        }
    });
    Button feedback = new Button("Got feedback?", FontAwesome.COMMENTING_O);
    feedback.addStyleName("feedback-button");
    feedback.addStyleName(ValoTheme.BUTTON_PRIMARY);
    feedback.addStyleName(ValoTheme.BUTTON_TINY);
    feedback.addClickListener(e -> {
        getUI().addWindow(new FeedbackForm());
    });
    content.addComponents(logo, links, feedback, filterField, tree, version);
    content.setComponentAlignment(feedback, Alignment.MIDDLE_CENTER);
    horizontalSplitPanel.setFirstComponent(content);
    selectItem();
    Page.getCurrent().addUriFragmentChangedListener(new Page.UriFragmentChangedListener() {

        @Override
        public void uriFragmentChanged(Page.UriFragmentChangedEvent event) {
            selectItem();
        }
    });
    setContent(new CssLayout() {

        {
            setSizeFull();
            addComponent(horizontalSplitPanel);
            addComponent(themeSelector);
        }
    });
    if (tracker != null) {
        tracker.trackPageview("/charts");
    }
}
Also used : SkiesTheme(com.vaadin.addon.charts.themes.SkiesTheme) HighChartsDefaultTheme(com.vaadin.addon.charts.themes.HighChartsDefaultTheme) ValoLightTheme(com.vaadin.addon.charts.themes.ValoLightTheme) HashMap(java.util.HashMap) Label(com.vaadin.ui.Label) VaadinTheme(com.vaadin.addon.charts.themes.VaadinTheme) Page(com.vaadin.server.Page) GrayTheme(com.vaadin.addon.charts.themes.GrayTheme) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValoDarkTheme(com.vaadin.addon.charts.themes.ValoDarkTheme) CssLayout(com.vaadin.ui.CssLayout) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) Tree(com.vaadin.v7.ui.Tree) Property(com.vaadin.v7.data.Property) ComboBox(com.vaadin.ui.ComboBox) GridTheme(com.vaadin.addon.charts.themes.GridTheme) ExternalResource(com.vaadin.server.ExternalResource) TabSheet(com.vaadin.ui.TabSheet) HorizontalSplitPanel(com.vaadin.ui.HorizontalSplitPanel) ValoLightTheme(com.vaadin.addon.charts.themes.ValoLightTheme) ValoDarkTheme(com.vaadin.addon.charts.themes.ValoDarkTheme) ValoTheme(com.vaadin.ui.themes.ValoTheme) Theme(com.vaadin.annotations.Theme) GrayTheme(com.vaadin.addon.charts.themes.GrayTheme) VaadinTheme(com.vaadin.addon.charts.themes.VaadinTheme) GridTheme(com.vaadin.addon.charts.themes.GridTheme) HighChartsDefaultTheme(com.vaadin.addon.charts.themes.HighChartsDefaultTheme) SkiesTheme(com.vaadin.addon.charts.themes.SkiesTheme) HierarchicalContainer(com.vaadin.v7.data.util.HierarchicalContainer) Link(com.vaadin.ui.Link)

Aggregations

ComboBox (com.vaadin.ui.ComboBox)41 HorizontalLayout (com.vaadin.ui.HorizontalLayout)7 TextField (com.vaadin.ui.TextField)7 Button (com.vaadin.ui.Button)6 SplitComboBox (au.com.vaadinutils.crud.splitFields.SplitComboBox)5 LegacySplitComboBox (au.com.vaadinutils.crud.splitFields.legacy.LegacySplitComboBox)5 Item (com.vaadin.data.Item)5 Label (com.vaadin.ui.Label)5 VerticalLayout (com.vaadin.ui.VerticalLayout)5 Test (org.junit.Test)4 LegacyComboBox (org.vaadin.ui.LegacyComboBox)4 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 Panel (com.vaadin.ui.Panel)3 UI (com.vaadin.ui.UI)3 LinkkiComboBox (org.linkki.core.ui.components.LinkkiComboBox)3 TimePicker (au.com.vaadinutils.layout.TimePicker)2 ViewRiksdagenCommittee (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee)2 ApplicationEventGroup (com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup)2 DataContainer (com.hack23.cia.service.api.DataContainer)2