Java Code Examples for com.vaadin.ui.ComboBox.setValue()

The following are Jave code examples for showing how to use setValue() of the com.vaadin.ui.ComboBox class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: md-stepper   File: StepperPropertiesLayout.java   Source Code and License Vote up 6 votes
private ComboBox createThemeChooserBox() {
  List<String> themes = Arrays.asList("Blueprint", "Dark", "Default", "Facebook", "Flat",
                                      "Flat-Dark", "Light", "Metro");

  ComboBox comboBox = new ComboBox("Choose theme", themes);
  comboBox.setWidth(100, Unit.PERCENTAGE);
  comboBox.setValue("Default");
  comboBox.addValueChangeListener(e -> {
    Object value = e.getValue();
    String theme = value != null ? String.valueOf(value) : "";
    if (!"".equals(theme.trim())) {
      getUI().setTheme(theme.toLowerCase());
    }
  });

  return comboBox;
}
 
Example 2
Project: metl   File: EditAgentDeploymentPanel.java   Source Code and License Vote up 6 votes
protected ComboBox getLogLevelComponent() {
    final ComboBox combo = new ComboBox("Log Level");
    combo.setNullSelectionAllowed(false);
    combo.setWidth(200, Unit.PIXELS);
    LogLevel[] levels = LogLevel.values();
    for (LogLevel logLevel : levels) {
        combo.addItem(logLevel.name());
    }
    combo.setValue(agentDeployment.getLogLevel());
    combo.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            agentDeployment.setLogLevel((String) combo.getValue());
            saveAgentDeployment(agentDeployment);
        }
    });
    return combo;
}
 
Example 3
Project: metl   File: EditAgentDeploymentPanel.java   Source Code and License Vote up 6 votes
protected ComboBox getStartTypeComponent() {
    startTypeCombo = new ComboBox("Start Type");
    startTypeCombo.setWidth(200, Unit.PIXELS);
    startTypeCombo.setNullSelectionAllowed(false);
    StartType[] values = StartType.values();
    for (StartType value : values) {
        startTypeCombo.addItem(value.name());
    }
    startTypeCombo.setValue(agentDeployment.getStartType());
    startTypeCombo.addValueChangeListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            agentDeployment.setStartType((String) startTypeCombo.getValue());
            updateScheduleEnable();
            for (int i = 0; i < 7; i++) {
                ListSelect listSelect = ((ListSelect) cronLayout.getComponent(i));
                for (Object itemId : listSelect.getItemIds()) {
                    listSelect.unselect(itemId);
                }
                listSelect.select(listSelect.getItemIds().iterator().next());
            }
            String startExpression = null;
            if (agentDeployment.getStartType().equals(StartType.SCHEDULED_CRON.name())) {
                startExpression = "0 0 0 * * ?";
            }
            startExpressionTextField.setValue(startExpression);
            agentDeployment.setStartExpression(startExpression);
            updateScheduleFields();
            saveAgentDeployment(agentDeployment);
        }
    });
    return startTypeCombo;
}
 
Example 4
Project: primecloud-controller   File: WinServerAddSimple.java   Source Code and License Vote up 6 votes
@Override
public void attach() {
    // サーバ名(Prefix)
    prefixField = new TextField(ViewProperties.getCaption("field.serverNamePrefix"));
    getLayout().addComponent(prefixField);

    // プラットフォーム
    cloudTable = new SelectCloudTable();
    getLayout().addComponent(cloudTable);

    // サーバ台数
    serverNumber = new ComboBox(ViewProperties.getCaption("field.serverNumber"));
    serverNumber.setWidth("110px");
    serverNumber.setMultiSelect(false);
    for (int i = 1; i <= MAX_ADD_SERVER; i++) {
        serverNumber.addItem(i);
    }
    serverNumber.setNullSelectionAllowed(false);
    serverNumber.setValue(1); // 初期値は1
    getLayout().addComponent(serverNumber);

    initValidation();
}
 
Example 5
Project: dhconvalidator   File: UserSwitchPanel.java   Source Code and License Vote up 6 votes
/**
 * Setup UI.
 */
private void initComponents() {
	List<User> users = UserList.INSTANCE.getUsers();
	userSwitchBox = new ComboBox(Messages.getString("UserSwitchPanel.boxCaption")); //$NON-NLS-1$
	setUsers(users);
	User current = (User) VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name());
	userSwitchBox.setValue(current);
	
	userSwitchBox.setDescription(
		Messages.getString("UserSwitchPanel.boxDescription")); //$NON-NLS-1$
	userSwitchBox.setNewItemsAllowed(false);
	userSwitchBox.setNullSelectionAllowed(false);
	
	addComponent(userSwitchBox);
	btReload = new Button(Messages.getString("UserSwitchPanel.reloadCaption")); //$NON-NLS-1$
	btReload.setStyleName(BaseTheme.BUTTON_LINK);
	btReload.addStyleName("plain-link"); //$NON-NLS-1$
	
	addComponent(btReload);
}
 
Example 6
Project: md-stepper   File: StepperPropertiesLayout.java   Source Code and License Vote up 5 votes
private ComboBox createStepperTypeBox() {
  List<String> stepperTypes = Arrays.asList("Horizontal", "Vertical");

  ComboBox comboBox = new ComboBox("Stepper Type *", stepperTypes);
  comboBox.setWidth(100, Unit.PERCENTAGE);
  comboBox.setValue(stepperTypes.get(0));
  comboBox.addValueChangeListener(event -> {
    createStepper();
    fireEvent(new StepperCreateEvent(StepperPropertiesLayout.this, stepper));
  });
  return comboBox;
}
 
Example 7
Project: md-stepper   File: StepperPropertiesLayout.java   Source Code and License Vote up 5 votes
private ComboBox createIconStyleBox() {
  List<String> iconStyles = Arrays.asList("Square", "Circular");
  ComboBox comboBox = new ComboBox("Choose Icon Style", iconStyles);
  comboBox.setWidth(100, Unit.PERCENTAGE);
  comboBox.setValue("Circular");
  comboBox.addValueChangeListener(event -> updateStepperIconStyles());
  return comboBox;
}
 
Example 8
Project: VaadinUtils   File: ReportParameterReportChooser.java   Source Code and License Vote up 5 votes
/**
 * 
 * @param caption
 * @param defaultValue
 * @param parameterName
 * @param enumClass
 */
public ReportParameterReportChooser(String caption, T defaultValue, String parameterName, Class<T> enumClass)
{
	super(caption, parameterName);
	field = new ComboBox(caption);
	this.enumClass = enumClass;
	field.setContainerDataSource(FormHelper.createContainerFromEnumClass("value", enumClass));
	field.setNewItemsAllowed(false);
	field.setNullSelectionAllowed(false);
	field.setTextInputAllowed(false);
	field.setValue(defaultValue);
}
 
Example 9
Project: VaadinUtils   File: ReportParameterEnum.java   Source Code and License Vote up 5 votes
/**
 * 
 * @param caption
 * @param defaultValue
 * @param parameterName
 * @param enumClass
 */
public ReportParameterEnum(String caption, T defaultValue, String parameterName, Class<T> enumClass)
{
	super(caption, parameterName);
	field = new ComboBox(caption);
	this.enumClass = enumClass;
	field.setContainerDataSource(FormHelper.createContainerFromEnumClass("value", enumClass));
	field.setNewItemsAllowed(false);
	field.setNullSelectionAllowed(false);
	field.setTextInputAllowed(false);
	field.setValue(defaultValue);
}
 
Example 10
Project: jdal   File: FormUtils.java   Source Code and License Vote up 5 votes
/**
 * Fill combo with a list of objeces.
 * @param data list to fill with.
 * @param clear true if clear all items before adding new ones.
 */
public static void fillCombo(ComboBox combo, List<?> data, boolean clear) {
	Object selected = combo.getValue();
	
	if (clear) {
		combo.removeAllItems();
	}
	
	for (Object o : data) {
		combo.addItem(o);
	}
	
	if (data.contains(selected))
		combo.setValue(selected);
}
 
Example 11
Project: metl   File: EditContentRouterPanel.java   Source Code and License Vote up 4 votes
public Field<?> createField(final Container dataContainer, final Object itemId, final Object propertyId,
        com.vaadin.ui.Component uiContext) {
    final Route route = (Route) itemId;
    Field<?> field = null;
    if (propertyId.equals("matchExpression")) {
        final TextField textField = new ImmediateUpdateTextField(null) {
            @Override
            protected void save(String text) {
                route.setMatchExpression(text);
                EditContentRouterPanel.this.save();
            }
        };
        textField.setWidth(100, Unit.PERCENTAGE);
        textField.setValue(route.getMatchExpression());
        field = textField;
    } else if (propertyId.equals("targetStepId")) {
        final ComboBox combo = new ComboBox();
        combo.setWidth(100, Unit.PERCENTAGE);
        flow = context.getConfigurationService().findFlow(flow.getId());
        List<FlowStepLink> stepLinks = flow.findFlowStepLinksWithSource(flowStep.getId());
        for (FlowStepLink flowStepLink : stepLinks) {
            FlowStep comboStep = flow.findFlowStepWithId(flowStepLink.getTargetStepId());
            combo.addItem(comboStep.getId());
            combo.setItemCaption(comboStep.getId(), comboStep.getName());

            if (flowStepLink.getTargetStepId().equals(route.getTargetStepId()) || combo.getValue() == null) {
                combo.setValue(comboStep.getId());
            }
        }

        combo.setImmediate(true);
        combo.setNewItemsAllowed(false);
        combo.setNullSelectionAllowed(false);
        combo.addValueChangeListener(new ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                String stepId = (String) event.getProperty().getValue();
                if (stepId != null) {
                    route.setTargetStepId(stepId);
                    EditContentRouterPanel.this.save();
                }
            }
        });
        field = combo;
    }
    if (field != null) {
        field.setReadOnly(readOnly);
    }
    return field;
}
 
Example 12
Project: dhconvalidator   File: PaperSelectionPanel.java   Source Code and License Vote up 4 votes
/**
 * Setup UI.
 */
private void initComponents() {
	Label info = new Label(
		Messages.getString("PaperSelectionPanel.hintMsg"), //$NON-NLS-1$
		ContentMode.HTML); 
	
	languages = 
			new ComboBox(Messages.getString("PaperSelectionPanel.language"), //$NON-NLS-1$
					Arrays.asList(SubmissionLanguage.values()));
	languages.setNullSelectionAllowed(false);
	languages.setValue(SubmissionLanguage.valueOf(PropertyKey.defaultSubmissionLanguage.getValue(SubmissionLanguage.ENGLISH.name())));
	
	paperTable = new Table(Messages.getString("PaperSelectionPanel.tableTitle")); //$NON-NLS-1$
	paperTable.setSelectable(true);
	paperTable.setMultiSelect(true);
	paperTable.setPageLength(4);
	paperTable.addContainerProperty("title", String.class, null); //$NON-NLS-1$
	paperTable.setColumnHeader(
		"title", 
		Messages.getString("PaperSelectionPanel.titleColumnTitle")); //$NON-NLS-1$ //$NON-NLS-2$
	paperTable.setWidth("100%"); //$NON-NLS-1$
	paperTable.setImmediate(true);
	
	btGenerate = new Button(
		Messages.getString(
			"PaperSelectionPanel.generateButtonCaption")); //$NON-NLS-1$
	StreamResource templateStreamResource = 
			new StreamResource(
					new StreamSource() {
						@Override
						public InputStream getStream() {
							return createTemplates();
						}
					}, "your_personal_dh_templates.zip" ); //$NON-NLS-1$
	
	templateStreamResource.setCacheTime(0);
	new FileDownloader(templateStreamResource).extend(btGenerate);
	
	addCenteredComponent(info);
	addCenteredComponent(languages);
	addCenteredComponent(paperTable);
	addCenteredComponent(btGenerate);
	
	postDownloadLabel = 
			new Label(
				Messages.getString("PaperSelectionPanel.postDownloadInfo",
					inputConverter.getTextEditorDescription(),
					PropertyKey.base_url.getValue()+"popup/DHConvalidatorServices#!converter"),
				ContentMode.HTML);
	postDownloadLabel.addStyleName("postDownloadInfoRedAndBold");
	postDownloadLabel.setVisible(false);
	
	addCenteredComponent(postDownloadLabel);
	
}
 
Example 13
Project: mycollab   File: TicketDashboardViewImpl.java   Source Code and License Vote up 4 votes
public TicketDashboardViewImpl() {
    this.withMargin(new MarginInfo(false, true, true, true));
    ticketSearchPanel = new TicketSearchPanel();

    MHorizontalLayout groupWrapLayout = new MHorizontalLayout();
    groupWrapLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    groupWrapLayout.addComponent(new ELabel(UserUIContext.getMessage(GenericI18Enum.ACTION_SORT)));
    final ComboBox sortCombo = new ValueComboBox(false, UserUIContext.getMessage(GenericI18Enum.OPT_SORT_DESCENDING),
            UserUIContext.getMessage(GenericI18Enum.OPT_SORT_ASCENDING));
    sortCombo.addValueChangeListener(valueChangeEvent -> {
        String sortValue = (String) sortCombo.getValue();
        if (UserUIContext.getMessage(GenericI18Enum.OPT_SORT_ASCENDING).equals(sortValue)) {
            sortDirection = SearchCriteria.ASC;
        } else {
            sortDirection = SearchCriteria.DESC;
        }
        queryAndDisplayTickets();
    });
    sortDirection = SearchCriteria.DESC;
    groupWrapLayout.addComponent(sortCombo);

    groupWrapLayout.addComponent(new ELabel(UserUIContext.getMessage(GenericI18Enum.OPT_GROUP)));
    final ComboBox groupCombo = new ValueComboBox(false, UserUIContext.getMessage(GenericI18Enum.FORM_DUE_DATE),
            UserUIContext.getMessage(GenericI18Enum.FORM_START_DATE), UserUIContext.getMessage(GenericI18Enum.FORM_CREATED_TIME),
            UserUIContext.getMessage(GenericI18Enum.OPT_PLAIN), UserUIContext.getMessage(GenericI18Enum.OPT_USER),
            UserUIContext.getMessage(MilestoneI18nEnum.SINGLE));
    groupByState = UserUIContext.getMessage(MilestoneI18nEnum.SINGLE);
    groupCombo.setValue(UserUIContext.getMessage(MilestoneI18nEnum.SINGLE));
    groupCombo.addValueChangeListener(valueChangeEvent -> {
        groupByState = (String) groupCombo.getValue();
        queryAndDisplayTickets();
    });

    groupWrapLayout.addComponent(groupCombo);

    ticketSearchPanel.addHeaderRight(groupWrapLayout);

    MButton printBtn = new MButton("", clickEvent -> UI.getCurrent().addWindow(
            new TicketCustomizeReportOutputWindow(new LazyValueInjector() {
                @Override
                protected Object doEval() {
                    return baseCriteria;
                }
            }))).withIcon(FontAwesome.PRINT).withStyleName(WebThemes.BUTTON_OPTION)
            .withDescription(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT));
    groupWrapLayout.addComponent(printBtn);

    MButton newTicketBtn = new MButton(UserUIContext.getMessage(TicketI18nEnum.NEW), clickEvent -> {
        UI.getCurrent().addWindow(AppContextUtil.getSpringBean(TicketComponentFactory.class)
                .createNewTicketWindow(null, CurrentProjectVariables.getProjectId(), null, false));
    }).withIcon(FontAwesome.PLUS).withStyleName(WebThemes.BUTTON_ACTION)
            .withVisible(CurrentProjectVariables.canWriteTicket());
    groupWrapLayout.addComponent(newTicketBtn);

    if (!SiteConfiguration.isCommunityEdition()) {
        MButton advanceDisplayBtn = new MButton(UserUIContext.getMessage(ProjectCommonI18nEnum.OPT_LIST))
                .withIcon(FontAwesome.NAVICON).withWidth("100px");

        MButton kanbanBtn = new MButton(UserUIContext.getMessage(ProjectCommonI18nEnum.OPT_KANBAN), clickEvent ->
                displayKanbanView()).withWidth("100px").withIcon(FontAwesome.TH);

        ToggleButtonGroup viewButtons = new ToggleButtonGroup();
        viewButtons.addButton(advanceDisplayBtn);
        viewButtons.addButton(kanbanBtn);
        viewButtons.withDefaultButton(advanceDisplayBtn);
        groupWrapLayout.addComponent(viewButtons);
    }

    MHorizontalLayout mainLayout = new MHorizontalLayout().withFullHeight().withFullWidth();
    wrapBody = new MVerticalLayout().withMargin(new MarginInfo(false, true, true, false));
    rightColumn = new MVerticalLayout().withWidth("370px").withMargin(new MarginInfo(true, false, false, false));
    mainLayout.with(wrapBody, rightColumn).expand(wrapBody);
    this.with(ticketSearchPanel, mainLayout);
}
 
Example 14
Project: ExpressZip   File: FindLayersViewComponent.java   Source Code and License Vote up 4 votes
private void setupAddFilterWindow(Window window) {
	// General variables

	// Layouts
	GridLayout mainLayout = new GridLayout(1, 3);
	HorizontalLayout axisLayout = new HorizontalLayout();
	HorizontalLayout criteriaLayout = new HorizontalLayout();
	HorizontalLayout buttonLayout = new HorizontalLayout();
	hznCriteria = criteriaLayout;

	// Buttons
	ExpressZipButton btnAdd = new ExpressZipButton("Add", Style.ACTION);
	btnAdd.setClickShortcut(KeyCode.ENTER);
	btnAdd.addStyleName("primary");
	ExpressZipButton btnCancel = new ExpressZipButton("Cancel", Style.ACTION);

	// Fields
	ComboBox cmbAxis = new ComboBox();
	cmbAxis.setTextInputAllowed(false);
	cmbAxis.setNullSelectionAllowed(false);

	// Labels
	Label lblAxis = new Label("Axis");

	btnAdd.addListener(filterButtonListener);
	btnCancel.addListener(filterButtonListener);

	for (Filter.AxisFilters f : Filter.axisArray) {
		cmbAxis.addItem(filter.getNameOfFilter(f));
	}
	cmbAxis.setImmediate(true);
	cmbAxis.addListener(axisSelectedListener);
	cmbAxis.setValue(filter.getNameOfFilter(Filter.axisArray[0]));

	mainLayout.addComponent(axisLayout, 0, 0);
	mainLayout.addComponent(criteriaLayout, 0, 1);
	mainLayout.addComponent(buttonLayout, 0, 2);
	mainLayout.setSpacing(true);

	axisLayout.setSpacing(true);

	axisLayout.addComponent(lblAxis);
	axisLayout.addComponent(cmbAxis);
	axisLayout.setExpandRatio(lblAxis, .2f);
	axisLayout.setExpandRatio(cmbAxis, .8f);
	axisLayout.setComponentAlignment(lblAxis, Alignment.MIDDLE_LEFT);
	axisLayout.setComponentAlignment(cmbAxis, Alignment.MIDDLE_LEFT);
	axisLayout.setSizeFull();

	criteriaLayout.setSizeFull();

	buttonLayout.setSpacing(true);
	buttonLayout.addComponent(btnAdd);
	buttonLayout.addComponent(btnCancel);
	buttonLayout.setComponentAlignment(btnAdd, Alignment.BOTTOM_RIGHT);
	buttonLayout.setComponentAlignment(btnCancel, Alignment.BOTTOM_RIGHT);
	buttonLayout.setExpandRatio(btnAdd, 1f);
	buttonLayout.setExpandRatio(btnCancel, 0f);
	buttonLayout.setSizeFull();

	mainLayout.setRowExpandRatio(0, 1f);
	mainLayout.setRowExpandRatio(1, 1f);
	mainLayout.setRowExpandRatio(2, 1f);
	mainLayout.setSizeFull();

	window.addComponent(mainLayout);
	window.getContent().setSizeFull();
}
 
Example 15
Project: gazpachoquest   File: OldLoginView.java   Source Code and License Vote up 4 votes
public OldLoginView() {
    setSizeFull();

    // Language bar in the top-right corner for selecting
    // invitation interface language
    final HorizontalLayout languageBar = new HorizontalLayout();
    languageBar.setHeight("50px");
    // addComponent(languageBar);
    // setComponentAlignment(languageBar, Alignment.TOP_RIGHT);

    // Allow selecting a language. We are in a constructor of a
    // CustomComponent, so preselecting the current
    // language of the application can not be done before
    // this (and the selection) component are attached to
    // the application.
    final ComboBox languageSelector = new ComboBox("Select a language") {
        @Override
        public void attach() {
            super.attach();
            // setValue(getLocale());
        }
    };

    // for (int i=0; i<locales.length; i++) {
    String locale = "es";
    languageSelector.addItem(locale);
    languageSelector.setItemCaption(locale, "español");

    // Automatically select the current locale
    // if (locales[i].equals(getLocale()))
    languageSelector.setValue(locale);

    // }

    // Create the invitation input field
    invitationTextField = new TextField("Invitation key:");
    invitationTextField.setWidth("300px");
    invitationTextField.setRequired(true);
    invitationTextField.setInputPrompt("Your questionnair invitation key (eg. 12345678)");
    invitationTextField.setInvalidAllowed(false);

    // Create login button
    enterButton = new Button("Enter", this);

    // Add both to a panel
    VerticalLayout fields = new VerticalLayout(languageSelector, invitationTextField, enterButton);
    fields.setCaption("Please enter your invitation key to access the questionnair");
    fields.setSpacing(true);
    fields.setMargin(new MarginInfo(true, true, true, false));
    fields.setSizeUndefined();

    // The view root layout
    VerticalLayout viewLayout = new VerticalLayout(fields);
    viewLayout.setSizeFull();
    viewLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER);
    viewLayout.setStyleName(Reindeer.LAYOUT_BLUE);
    setCompositionRoot(viewLayout);
}