Java Code Examples for com.vaadin.ui.ComboBox#addValueChangeListener()

The following examples show how to use com.vaadin.ui.ComboBox#addValueChangeListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hawkbit   File: ComboBoxBuilder.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return a new ComboBox
 */
public ComboBox buildCombBox() {
    final ComboBox comboBox = SPUIComponentProvider.getComboBox(null, "", null, ValoTheme.COMBOBOX_SMALL, false, "",
            prompt);
    comboBox.setImmediate(true);
    comboBox.setPageLength(7);
    comboBox.setItemCaptionPropertyId(SPUILabelDefinitions.VAR_NAME);
    comboBox.setSizeUndefined();
    if (caption != null) {
        comboBox.setCaption(caption);
    }
    if (id != null) {
        comboBox.setId(id);
    }
    if (valueChangeListener != null) {
        comboBox.addValueChangeListener(valueChangeListener);
    }
    return comboBox;
}
 
Example 2
@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
	final VerticalLayout panelContent = createPanelContent();
	final String pageId = getPageId(parameters);

	final ViewRiksdagenCommittee viewRiksdagenCommittee = getItem(parameters);
	getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);

	String selectedYear = "2018/19";
	if (parameters != null && parameters.contains("[") && parameters.contains("]")) {
		selectedYear = parameters.substring(parameters.indexOf('[') + 1, parameters.lastIndexOf(']'));
	}

	final ComboBox<String> comboBox = new ComboBox<>("Select year", Collections.unmodifiableList(
			Arrays.asList("2018/19","2017/18", "2016/17", "2015/16", "2014/15", "2013/14", "2012/13", "2011/12", "2010/11")));
	panelContent.addComponent(comboBox);
	panelContent.setExpandRatio(comboBox, ContentRatio.SMALL2);
	comboBox.setSelectedItem(selectedYear);
	
	comboBox.addValueChangeListener(new DecisionFlowValueChangeListener(NAME,pageId));

	final Map<String, List<ViewRiksdagenCommittee>> committeeMap = getApplicationManager()
			.getDataContainer(ViewRiksdagenCommittee.class).getAll().stream()
			.collect(Collectors.groupingBy(c -> c.getEmbeddedId().getOrgCode().toUpperCase(Locale.ENGLISH)));

	final SankeyChart chart = decisionFlowChartManager.createCommitteeDecisionFlow(viewRiksdagenCommittee,
			committeeMap, comboBox.getSelectedItem().orElse(selectedYear));
	panelContent.addComponent(chart);
	panelContent.setExpandRatio(chart, ContentRatio.LARGE);

	getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER, NAME,
			parameters, pageId);
	panel.setCaption(new StringBuilder().append(NAME).append("::").append(COMMITTEE_DECISION_FLOW).toString());

	return panelContent;

}
 
Example 3
@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
	final VerticalLayout panelContent = createPanelContent();
	getParliamentMenuItemFactory().createParliamentTopicMenu(menuBar);

	String selectedYear = "2018/19";
	if (parameters != null && parameters.contains("[") && parameters.contains("]")) {
		selectedYear = parameters.substring(parameters.indexOf('[') + 1, parameters.lastIndexOf(']'));
	} 
	
	final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
			.getDataContainer(ViewRiksdagenCommittee.class);
	final List<ViewRiksdagenCommittee> allCommittess = dataContainer.getAll();

	final Map<String, List<ViewRiksdagenCommittee>> committeeMap = allCommittess.stream().collect(Collectors.groupingBy(c -> c.getEmbeddedId().getOrgCode().toUpperCase(Locale.ENGLISH)));
	
	final ComboBox<String> comboBox = new ComboBox<>("Select year", Collections.unmodifiableList(Arrays.asList("2018/19","2017/18","2016/17","2015/16","2014/15","2013/14","2012/13","2011/12","2010/11")));
	panelContent.addComponent(comboBox);
	panelContent.setExpandRatio(comboBox, ContentRatio.SMALL);
	comboBox.setSelectedItem(selectedYear);
	comboBox.addValueChangeListener(new DecisionFlowValueChangeListener(NAME,""));
	
	final SankeyChart chart = decisionFlowChartManager.createAllDecisionFlow(committeeMap,comboBox.getSelectedItem().orElse(selectedYear));
	panelContent.addComponent(chart);
	panelContent.setExpandRatio(chart, ContentRatio.LARGE);

	final TextArea textarea = decisionFlowChartManager.createCommitteeeDecisionSummary(committeeMap,comboBox.getSelectedItem().orElse(selectedYear));
	textarea.setSizeFull();
	panelContent.addComponent(textarea);
	panelContent.setExpandRatio(textarea, ContentRatio.SMALL_GRID);


	getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARLIAMENT_RANKING_VIEW, ApplicationEventGroup.USER, NAME,
			parameters, selectedYear);
	panel.setCaption(new StringBuilder().append(NAME).append("::").append(PARLIAMENT_DECISION_FLOW).toString());

	return panelContent;

}
 
Example 4
public InviteUserTokenField() {
    inviteEmails = new HashSet<>();
    this.setWidth("100%");

    ProjectMemberService prjMemberService = AppContextUtil.getSpringBean(ProjectMemberService.class);
    candidateUsers = prjMemberService.getUsersNotInProject(CurrentProjectVariables.getProjectId(), AppUI.getAccountId());
    List<SimpleTokenizable> tokens = candidateUsers.stream().map(user -> new SimpleTokenizable(user.getUsername().hashCode(), user.getUsername())).collect(Collectors.toList());
    ComboBox<SimpleTokenizable> comboBox = new ComboBox<>("", tokens);
    comboBox.setItemCaptionGenerator(SimpleTokenizable::getStringValue);
    comboBox.setPlaceholder("Type here to add");
    comboBox.setNewItemProvider((ComboBox.NewItemProvider<SimpleTokenizable>) value -> {
        if (StringUtils.isValidEmail(value) && !inviteEmails.contains(value)) {
            inviteEmails.add(value);
            tokenField.addTokenizable(new SimpleTokenizable(value.hashCode(), value));
            return Optional.empty();
        } else {
            Notification.show("Warning", "Invalid input", Notification.Type.WARNING_MESSAGE);
            return Optional.empty();
        }
    });
    comboBox.addValueChangeListener(getComboBoxValueChange(tokenField));

    tokenField.addTokenRemovedListener(event -> {
        Tokenizable token = event.getTokenizable();
        inviteEmails.remove(token.getStringValue());
    });

    tokenField.setInputField(comboBox);
    tokenField.setEnableDefaultDeleteTokenAction(true);
    this.addComponent(tokenField);
}
 
Example 5
Source Project: chipster   File: InputOutputUI.java    License: MIT License 5 votes vote down vote up
protected void initElements() {
	type2 = new ComboBox();
	type2.setImmediate(true);
	type2.setWidth(WIDTH);
	lbMeta = new Label("Meta:");
	cbMeta = new CheckBox();
	cbMeta.setDescription("Is this element Meta data");
	
	optional.setWidth(WIDTH);
	type = new ComboBox();
	type.setWidth(WIDTH);
	type.setNullSelectionAllowed(false);
	type.setImmediate(true);
	type.addItem(SINGLE_FILE);
	type.addItem(MULTI_FILE);
	type.select(SINGLE_FILE);
	type.addValueChangeListener(new ValueChangeListener() {
		private static final long serialVersionUID = -1134955257251483403L;

		@Override
		public void valueChange(ValueChangeEvent event) {
			if(type.getValue().toString().contentEquals(SINGLE_FILE)) {
				getSingleFileUI();
			} else if(type.getValue().toString().contentEquals(MULTI_FILE)){
				getMultipleFilesUI();
			}
		}
	});
}
 
Example 6
Source Project: jdal   File: FormUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add a link on primary and dependent ComboBoxes by property name. 
 * When selection changes on primary use propertyName to get a Collection and fill dependent ComboBox with it
 * @param primary ComboBox when selection changes
 * @param dependent ComboBox that are filled with collection   
 * @param propertyName the property name for get the collection from primary selected item
 * @param addNull if true, add a null as first combobox item
 */
@SuppressWarnings("rawtypes")
public static void link(final ComboBox primary, final ComboBox dependent,
		final String propertyName, final boolean addNull) {

	primary.addValueChangeListener(new ValueChangeListener() {

		public void valueChange(ValueChangeEvent event) {
			Object selected = event.getProperty().getValue();
			if (selected != null) {
				BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(selected);
				if (wrapper.isReadableProperty(propertyName)) {
					Collection items = (Collection) wrapper.getPropertyValue(propertyName);
					dependent.removeAllItems();
					
					if (addNull)
						dependent.addItem(null);
					
					for (Object item : items)
						dependent.addItem(item);
				}
				else {
					log.error("Can't write on propety '" + propertyName + "' of class: '" + selected.getClass() + "'");
				}
			}

		}
	});
}
 
Example 7
Source Project: XACML   File: RangeEditorComponent.java    License: MIT License 4 votes vote down vote up
private void setupComboText(final ComboBox box, final TextField text) {
	//
	// Respond to combo changes
	//
	box.addValueChangeListener(new ValueChangeListener() {
		private static final long serialVersionUID = 1L;

		@Override
		public void valueChange(ValueChangeEvent event) {
			//
			// Get the new value
			//
			String property = (String) box.getValue();
			//
			// Get our constraint object
			//
			ConstraintValue value = (ConstraintValue) box.getData();
			//
			// Update our object
			//
			if (property == null) {
				//
				// Clear the text field and disable it
				//
				text.setEnabled(false);
				text.setValue(null);
			} else {
				//
				// Change the property name
				//
				value.setProperty(property);
				//
				// Focus to the text field and enable it
				//
				text.setEnabled(true);
				text.focus();
			}
		}
	});
	
}
 
Example 8
Source Project: gantt   File: DemoUI.java    License: Apache License 2.0 4 votes vote down vote up
private Panel createControls() {
    Panel panel = new Panel();
    panel.setWidth(100, Unit.PERCENTAGE);

    controls = new HorizontalLayout();
    controls.setSpacing(true);
    controls.setMargin(true);
    panel.setContent(controls);

    subControls = new HorizontalLayout();
    subControls.setSpacing(true);
    subControls.setVisible(false);

    start = createStartDateField();
    end = createEndDateField();

    Button createStep = new Button("Create New Step...", createStepClickListener);

    HorizontalLayout heightAndUnit = new HorizontalLayout(Util.createHeightEditor(gantt),
            Util.createHeightUnitEditor(gantt));

    HorizontalLayout widthAndUnit = new HorizontalLayout(Util.createWidthEditor(gantt),
            Util.createWidthUnitEditor(gantt));

    reso = new NativeSelect<Resolution>("Resolution");
    reso.setEmptySelectionAllowed(false);
    reso.setItems(org.tltv.gantt.client.shared.Resolution.Hour, org.tltv.gantt.client.shared.Resolution.Day,
            org.tltv.gantt.client.shared.Resolution.Week);
    reso.setValue(gantt.getResolution());
    resolutionValueChangeRegistration = Optional.of(reso.addValueChangeListener(resolutionValueChangeListener));

    localeSelect = new NativeSelect<Locale>("Locale") {
        @Override
        public void attach() {
            super.attach();

            if (getValue() == null) {
                // use default locale
                setValue(gantt.getLocale());
                addValueChangeListener(localeValueChangeListener);
            }
        }
    };
    localeSelect.setEmptySelectionAllowed(false);
    localeSelect.setItems(Locale.getAvailableLocales());
    localeSelect.setItemCaptionGenerator((l) -> l.getDisplayName(getLocale()));

    ComboBox<String> timezoneSelect = new ComboBox<String>("Timezone");
    timezoneSelect.setWidth(300, Unit.PIXELS);
    timezoneSelect.setEmptySelectionAllowed(false);
    timezoneSelect.setItemCaptionGenerator(new ItemCaptionGenerator<String>() {

        @Override
        public String apply(String item) {
            if ("Default".equals(item)) {
                return "Default (" + getDefaultTimeZone().getDisplayName() + ")";
            }
            TimeZone tz = TimeZone.getTimeZone(item);
            return tz.getID() + " (raw offset " + (tz.getRawOffset() / 60000) + "m)";
        }
    });
    List<String> items = new ArrayList<>();
    items.add("Default");
    items.addAll(Gantt.getSupportedTimeZoneIDs());
    timezoneSelect.setItems((caption, fltr) -> caption.contains(fltr), items);
    timezoneSelect.setValue("Default");
    timezoneSelect.addValueChangeListener(timezoneValueChangeListener);

    final Button toggleSubControlsBtn = new Button("Show More Settings...");
    toggleSubControlsBtn.addStyleName("link");
    toggleSubControlsBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            subControls.setVisible(!subControls.isVisible());
            toggleSubControlsBtn.setCaption(subControls.isVisible() ? "Less Settings..." : "More Settings...");
        }
    });

    controls.addComponent(start);
    controls.addComponent(end);
    controls.addComponent(reso);
    controls.addComponent(subControls);
    controls.addComponent(toggleSubControlsBtn);
    controls.setComponentAlignment(toggleSubControlsBtn, Alignment.BOTTOM_CENTER);

    subControls.addComponent(localeSelect);
    subControls.addComponent(timezoneSelect);
    subControls.addComponent(heightAndUnit);
    subControls.addComponent(widthAndUnit);
    subControls.addComponent(createStep);
    subControls.setComponentAlignment(createStep, Alignment.MIDDLE_LEFT);

    return panel;
}