Example usage for com.vaadin.ui ComboBox addValueChangeListener

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

Introduction

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

Prototype

@Override
    public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener) 

Source Link

Usage

From source file:org.ripla.web.util.GenericSelect.java

License:Open Source License

/**
 * Creates a <code>Selection</code> widget with the provided options.
 * /*from   w w  w  . j  a v a2 s  . c  o m*/
 * @param inProperty
 *            {@link Property&lt;String>}
 * @param inOptions
 *            {@link Collection}
 * @param inWidth
 *            int
 * @param inAllowNull
 *            boolean
 * @param inProcessor
 *            {@link IProcessor} for post processing, may be
 *            <code>null</code>
 * @return {@link ComboBox}
 */
@SuppressWarnings("serial")
public static ComboBox getSelection(final Property<String> inProperty, final Collection<String> inOptions,
        final int inWidth, final boolean inAllowNull, final IProcessor inProcessor) {
    final ComboBox outSelect = new ComboBox(null, inOptions);
    outSelect.select(inProperty.getValue());
    outSelect.setStyleName("ripla-select"); //$NON-NLS-1$
    outSelect.setWidth(inWidth, Unit.PIXELS);
    outSelect.setNullSelectionAllowed(inAllowNull);
    outSelect.setImmediate(true);
    outSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent inEvent) {
            final String lItemID = (String) inEvent.getProperty().getValue();
            inProperty.setValue(lItemID);
            if (inProcessor != null) {
                inProcessor.process(lItemID);
            }
        }
    });
    return outSelect;
}

From source file:org.vaadin.spinkit.demo.DemoUI.java

License:Apache License

private Component spinnerSizesContainer() {
    int types = SpinnerSize.values().length;
    GridLayout spinners = new GridLayout(4, (types / 4 + types % 4));
    spinners.setSizeFull();/*from   w w w  .j a v a  2s.  c  o  m*/
    spinners.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    spinners.setSpacing(true);

    ComboBox selector = new ComboBox("Select spinner type", Arrays.asList(SpinnerType.values()));
    selector.setNullSelectionAllowed(false);
    selector.setPageLength(0);
    selector.setValue(SpinnerType.ROTATING_PLANE);
    selector.addValueChangeListener(e -> {
        for (Component c : spinners) {
            if (c instanceof Spinner) {
                ((Spinner) c).setType((SpinnerType) selector.getValue());
            }
        }
    });

    StringToEnumConverter converter = new StringToEnumConverter();
    for (SpinnerSize size : SpinnerSize.values()) {
        Spinner spinner = new Spinner(SpinnerType.ROTATING_PLANE);
        spinner.setSize(size);
        spinner.setCaption(converter.convertToPresentation(size, String.class, getLocale()));
        spinners.addComponent(spinner);
    }

    VerticalLayout l = new VerticalLayout();
    l.setDefaultComponentAlignment(Alignment.TOP_CENTER);
    l.setSizeFull();
    l.setMargin(false);
    l.setSpacing(true);
    l.addComponents(selector, spinners);
    l.setExpandRatio(spinners, 1);
    return l;
}

From source file:pl.exsio.ca.module.terrain.evidence.NotificationsDataTable.java

License:Open Source License

private void handleAssignmentSelectionChange(final ComboBox assignment, final DateField date) {
    assignment.addValueChangeListener(new Property.ValueChangeListener() {

        @Override/*from   w w w  . jav a2  s  . co m*/
        public void valueChange(Property.ValueChangeEvent event) {
            date.validate();
        }
    });
}

From source file:pl.exsio.ca.module.terrain.evidence.TerrainDataTable.java

License:Open Source License

private void handleFilterActions(ComboBox types, ComboBox groups, DateField date) {
    Property.ValueChangeListener listener = this.getFiltersHandler(types, groups, date);
    types.addValueChangeListener(listener);
    groups.addValueChangeListener(listener);
    date.addValueChangeListener(listener);

    this.handleQuickNotificationClick();
}

From source file:pl.exsio.ca.module.terrain.report.CaReportModule.java

License:Open Source License

protected ComboBox createReportChooser() {
    ComboBox chooser = new ComboBox(t("pick"));
    final BeanItemContainer<Report> container = new BeanItemContainer(Report.class);
    for (Report report : this.reportRegistry.getRegisteredReports()) {
        container.addBean(report);// w w w .  j a va  2 s .  c om
    }
    chooser.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    chooser.setItemCaptionPropertyId("name");
    chooser.setContainerDataSource(container);
    chooser.setWidth("300px");
    chooser.setNullSelectionAllowed(false);
    chooser.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                if (lastReport instanceof Report) {
                    removeComponent(lastReport);
                }
                lastReport = container.getItem(event.getProperty().getValue()).getBean();
                addComponent(lastReport.load());
                setExpandRatio(lastReport, 20);
            }
        }
    });

    return chooser;
}

From source file:pl.exsio.ca.module.terrain.report.impl.EventReportImpl.java

License:Open Source License

@Override
public Report load() {
    this.removeAllComponents();
    ComboBox events = this.getEventsCombo();
    ComboBox groups = this.getGroupsCombo();
    ComboBox types = this.getTypesCombo();

    Property.ValueChangeListener listener = this.getControlsHandler(events, types, groups);
    events.addValueChangeListener(listener);
    groups.addValueChangeListener(listener);
    types.addValueChangeListener(listener);
    HorizontalLayout controls = new HorizontalLayout();
    controls.setSpacing(true);//from w w  w  . j  a va  2s  .  c  o m
    controls.addComponent(events);
    controls.addComponent(groups);
    controls.addComponent(types);
    this.addComponentAsFirst(controls);
    this.showReport((pl.exsio.ca.model.Event) events.getConvertedValue(), null, null);
    return this;
}

From source file:pl.exsio.ca.module.terrain.report.impl.WorkReportImpl.java

License:Open Source License

@Override
public Report load() {
    this.removeAllComponents();
    DateField start = this.getStartField();
    DateField end = this.getEndField();
    ComboBox groups = this.getGroupsCombo();
    ComboBox types = this.getTypesCombo();

    Property.ValueChangeListener listener = this.getControlsHandler(start, end, types, groups);
    start.addValueChangeListener(listener);
    end.addValueChangeListener(listener);
    groups.addValueChangeListener(listener);
    types.addValueChangeListener(listener);
    HorizontalLayout controls = new HorizontalLayout();
    controls.setSpacing(true);/*w ww  .  j a  va  2s  .c o m*/
    controls.addComponent(start);
    controls.addComponent(end);
    controls.addComponent(groups);
    controls.addComponent(types);
    this.addComponentAsFirst(controls);
    this.showReport(start.getValue(), end.getValue(), null, null);
    return this;
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.form.SecurityPermissionsForm.java

License:Open Source License

private void handleRoleSelectionChange(ComboBox roleSelect, final FormLayout permissionsLayout,
        final JPAContainer<? extends Role> roles, final Map<String, Permission> permissionsMap) {
    roleSelect.addValueChangeListener(new Property.ValueChangeListener() {

        private Map<CheckBox, Permission> permissionCbsMap;

        @Override//from  ww w .j a v  a 2  s .c  om
        public void valueChange(Property.ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                this.createRolePermissionsForm(event);
            }
        }

        private void createRolePermissionsForm(Property.ValueChangeEvent event) throws NumberFormatException {
            this.permissionCbsMap = new HashMap<>();
            permissionsLayout.removeAllComponents();

            Long itemId = Long.parseLong(event.getProperty().getValue().toString());
            Role selectedRole = roles.getItem(itemId).getEntity();
            final GrantedAuthoritySid sid = new GrantedAuthoritySid(selectedRole.getName());

            for (String permissionName : permissionsMap.keySet()) {
                CheckBox permissionCb = this.createPermissionCheckbox(permissionName, sid);
                permissionsLayout.addComponent(permissionCb);
            }

            Button savePermissions = this.createSaveButton(sid);
            permissionsLayout.addComponent(savePermissions);
        }

        private CheckBox createPermissionCheckbox(String permissionName, final GrantedAuthoritySid sid) {
            CheckBox permissionCb = new CheckBox(permissionName,
                    acl.isGranted(subject, permissionsMap.get(permissionName), sid));
            this.permissionCbsMap.put(permissionCb, permissionsMap.get(permissionName));
            return permissionCb;
        }

        private Button createSaveButton(final GrantedAuthoritySid sid) {
            Button savePermissions = new Button(t("core.save"), FontAwesome.FLOPPY_O);
            savePermissions.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    for (CheckBox permissionCb : permissionCbsMap.keySet()) {
                        if (permissionCb.getValue()) {
                            acl.grant(subject, permissionCbsMap.get(permissionCb), sid);
                        } else {
                            acl.revoke(subject, permissionCbsMap.get(permissionCb), sid);
                        }
                    }
                    Notification.show(t("core.security.management.permision.update.success"));
                }
            });
            return savePermissions;
        }
    });
}

From source file:pl.exsio.plupload.examples.AdvancedUploaderExample.java

License:Open Source License

@Override
protected void decorateActionPane(VerticalLayout pane) {
    final Plupload uploader = Util.createUploader();
    uploader.setChunkSize("2mb");
    uploader.setMaxRetries(5);/* ww w  .  j av a  2 s  .c om*/
    uploader.setMultiSelection(true);
    uploader.setPreventDuplicates(true);
    uploader.addFilter(new PluploadFilter("image files", "jpg, png, jpeg"));
    uploader.setImageResize(
            new PluploadImageResize().setEnabled(true).setCrop(true).setHeight(100).setWidth(200));
    uploader.addFileUploadedListener(new Plupload.FileUploadedListener() {

        @Override
        public void onFileUploaded(PluploadFile file) {
            Notification.show("I've just uploaded file: " + file.getName());
        }
    });

    final Label info = new Label();
    uploader.addUploadProgressListener(new Plupload.UploadProgressListener() {

        @Override
        public void onUploadProgress(PluploadFile file) {
            info.setValue("I'm uploading " + file.getName() + " and I'm at " + file.getPercent() + "%");
        }
    });

    uploader.addFilesAddedListener(new Plupload.FilesAddedListener() {

        @Override
        public void onFilesAdded(PluploadFile[] files) {
            uploader.start();
        }
    });

    uploader.addUploadCompleteListener(new Plupload.UploadCompleteListener() {

        @Override
        public void onUploadComplete() {
            info.setValue("upload is completed!");
        }
    });

    uploader.addErrorListener(new Plupload.ErrorListener() {

        @Override
        public void onError(PluploadError error) {
            Notification.show("There was an error: " + error.getMessage() + " (" + error.getType() + ")",
                    Notification.Type.ERROR_MESSAGE);
        }
    });

    ComboBox chunkSizeChoice = new ComboBox("Choose chunk size");
    for (double i = 0.5; i <= 3; i += 0.5) {
        chunkSizeChoice.addItem(i + "mb");
    }
    chunkSizeChoice.setNullSelectionAllowed(false);
    chunkSizeChoice.setValue("2.0mb");
    chunkSizeChoice.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            String chunkSize = event.getProperty().getValue().toString();
            uploader.setChunkSize(chunkSize);
            Notification.show("Chunk size was changed to " + chunkSize);
        }
    });

    pane.setSpacing(true);
    pane.addComponent(chunkSizeChoice);
    pane.addComponent(uploader);
    pane.addComponent(info);
}

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);
        }/*from www  . ja  v  a  2s .c  o  m*/

    }

    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;
}