private void fillParentStepCanditatesToSelect(AbstractStep step, final NativeSelect<Step> parentStepSelect) { if (!gantt.getSteps().contains(step)) { // new step parentStepSelect.setEnabled(true); List<Step> items = new ArrayList<>(); for (Step parentStepCanditate : gantt.getSteps()) { items.add(parentStepCanditate); if (step instanceof SubStep) { if (parentStepCanditate.getSubSteps().contains(step)) { parentStepSelect.setValue(parentStepCanditate); parentStepSelect.setEnabled(false); break; } } } parentStepSelect.setItems(items); } }
private void commit(final Window win, final Binder<? extends AbstractStep> binder, final NativeSelect<Step> parentStepSelect) { AbstractStep step = binder.getBean(); gantt.markStepDirty(step); if (parentStepSelect.isEnabled() && parentStepSelect.getValue() != null) { SubStep subStep = addSubStep(parentStepSelect, step); step = subStep; } if (step instanceof Step && !gantt.getSteps().contains(step)) { gantt.addStep((Step) step); } if (ganttListener != null && step instanceof Step) { ganttListener.stepModified((Step) step); } win.close(); }
public static NativeSelect createNativeSelectEditor(String caption, Object value, Collection<Object> items, final SelectValueChange valueChange) { NativeSelect<Object> s = new NativeSelect<>(caption); s.setItemCaptionGenerator(item -> String.valueOf(item)); s.setItems(items); s.setEmptySelectionAllowed(false); s.setValue(value); s.addValueChangeListener(new ValueChangeListener<Object>() { @Override public void valueChange(ValueChangeEvent<Object> event) { valueChange.onValueChange(event.getValue()); } }); return s; }
private void initComponents(){ importTypeSelectField=new NativeSelect("Sequence format",theCanvas.getImportFormats()); importTypeSelectField.setNewItemsAllowed(false); importTypeSelectField.setNullSelectionAllowed(false); sequenceInputField=new RichTextArea(); sequenceInputField.setImmediate(true); sequenceInputField.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID=-6654910749910048984L; @Override public void valueChange(ValueChangeEvent event) { sequenceInputField.commit(); sequence=(String)event.getProperty().getValue(); } }); sequenceInputField.setHeight("90%"); sequenceInputField.setWidth("100%"); sequenceInputField.addStyleName("hide-richtext-toolbar"); ok=new NativeButton("Import"); }
public AddHandlerPanel(final String id, List<String> types) { super("Add Handler"); layout.setMargin(true); setContent(layout); final NativeSelect sel = new NativeSelect(null, types); for (String t : types) { sel.setItemCaption(t, t.substring(t.lastIndexOf(".")+1)); } sel.setValue(types.get(0)); sel.setNullSelectionAllowed(false); layout.addComponent(sel); final TextField tf = new TextField("TODO:"); layout.addComponent(tf); Button sb = new Button("Add Handler"); sb.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { fireGoToHandler(id, (String) sel.getValue(), tf.getValue()); } }); layout.addComponent(sb); }
public SetDataSourcePanel(final String id, List<String> types) { super("Add Data Source"); layout.setMargin(true); setContent(layout); final NativeSelect sel = new NativeSelect(null, types); for (String t : types) { sel.setItemCaption(t, t.substring(t.lastIndexOf(".")+1)); } sel.setValue(types.get(0)); sel.setNullSelectionAllowed(false); layout.addComponent(sel); final TextField tf = new TextField("TODO:"); layout.addComponent(tf); Button sb = new Button("SetDataSource"); sb.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { fireSetDataSource(id, (String)sel.getValue(), tf.getValue()); } }); layout.addComponent(sb); }
public LocalDateTimeField() { dateField = new DateField(); dateField.addValueChangeListener(e->showOrHideErrorDateField()); hourNs = new NativeSelect(); hourNs.addValueChangeListener(e->fireValueChange(false)); minuteNs = new NativeSelect(); minuteNs.addValueChangeListener(e->fireValueChange(false)); hlContent = new HorizontalLayout(); //hlContent.setSizeFull(); hlContent.setSpacing(true); dateField.setImmediate(true); hlContent.addComponent(dateField); for (Integer i = 0; i<24; i++){ hourNs.addItem(i); hourNs.setItemCaption(i, MethodUtils.getLabelMinuteHeure(i)); } hourNs.setNullSelectionAllowed(false); hourNs.setImmediate(true); hourNs.setValue(0); for (Integer i = 0; i<60; i++){ minuteNs.addItem(i); minuteNs.setItemCaption(i, MethodUtils.getLabelMinuteHeure(i)); } minuteNs.setNullSelectionAllowed(false); minuteNs.setImmediate(true); minuteNs.setValue(0); hlContent.addComponent(hourNs); hlContent.setComponentAlignment(hourNs, Alignment.MIDDLE_LEFT); Label label1 = new Label(":"); hlContent.addComponent(label1); hlContent.setComponentAlignment(label1, Alignment.MIDDLE_LEFT); hlContent.addComponent(minuteNs); hlContent.setComponentAlignment(minuteNs, Alignment.MIDDLE_LEFT); Label label2 = new Label("(HH:MM)"); hlContent.addComponent(label2); hlContent.setComponentAlignment(label2, Alignment.MIDDLE_LEFT); }
public LocalTimeField() { hourNs = new NativeSelect(); minuteNs = new NativeSelect(); hlContent = new HorizontalLayout(); //hlContent.setSizeFull(); hlContent.setSpacing(true); for (Integer i = 0; i<24; i++){ hourNs.addItem(i); hourNs.setItemCaption(i, MethodUtils.getLabelMinuteHeure(i)); } hourNs.setNullSelectionAllowed(false); hourNs.setImmediate(true); for (Integer i = 0; i<60; i++){ minuteNs.addItem(i); minuteNs.setItemCaption(i, MethodUtils.getLabelMinuteHeure(i)); } minuteNs.setNullSelectionAllowed(false); minuteNs.setImmediate(true); hlContent.addComponent(hourNs); hlContent.setComponentAlignment(hourNs, Alignment.MIDDLE_LEFT); Label label1 = new Label(":"); hlContent.addComponent(label1); hlContent.setComponentAlignment(label1, Alignment.MIDDLE_LEFT); hlContent.addComponent(minuteNs); hlContent.setComponentAlignment(minuteNs, Alignment.MIDDLE_LEFT); Label label2 = new Label("(HH:MM)"); hlContent.addComponent(label2); hlContent.setComponentAlignment(label2, Alignment.MIDDLE_LEFT); }
public void setEmptySelectionAllowed(boolean emptySelectionAllowed) { if (getInternalField() instanceof ComboBox) { ((ComboBox<?>) getInternalField()).setEmptySelectionAllowed(emptySelectionAllowed); } if (getInternalField() instanceof NativeSelect) { ((NativeSelect<?>) getInternalField()).setEmptySelectionAllowed(emptySelectionAllowed); } }
public void setEmptySelectionCaption(String caption) { if (getInternalField() instanceof ComboBox) { ((ComboBox<?>) getInternalField()).setEmptySelectionCaption(caption); } if (getInternalField() instanceof NativeSelect) { ((NativeSelect<?>) getInternalField()).setEmptySelectionCaption(caption); } }
@Override protected void buildDialogLayout() { setSizeFull(); final VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setHeight("-1px"); mainLayout.setMargin(true); mainLayout.setSpacing(true); mainLayout.setWidth("100%"); mainLayout.addComponent(createTextField(ctx.tr("FilesToParliamentVaadinDialog.endpointURL"), endpointURL)); selectRdfFormat = new NativeSelect(ctx.tr("FilesToParliamentVaadinDialog.dialog.format")); for (RDFFormat item : supportedRdfFormats) { selectRdfFormat.addItem(item); selectRdfFormat.setItemCaption(item, item.getName()); } selectRdfFormat.setNullSelectionAllowed(false); selectRdfFormat.setImmediate(true); mainLayout.addComponent(selectRdfFormat); final TextField targerGraphNameTextField = createTextField(ctx.tr("FilesToParliamentVaadinDialog.targetGraphName"), targetGraphName); final CheckBox perGraphCheckbox = new CheckBox(ctx.tr("FilesToParliamentVaadinDialog.perGraph"), perGraph); perGraphCheckbox.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 60440618645464919L; @Override public void valueChange(ValueChangeEvent event) { targerGraphNameTextField.setEnabled(!perGraphCheckbox.getValue()); } }); mainLayout.addComponent(new CheckBox(ctx.tr("FilesToParliamentVaadinDialog.clearDestinationGraph"), clearDestinationGraph)); mainLayout.addComponent(perGraphCheckbox); mainLayout.addComponent(targerGraphNameTextField); setCompositionRoot(mainLayout); }
@Override protected void buildDialogLayout() { FormLayout mainLayout = new FormLayout(); // top-level component properties setWidth("100%"); setHeight("100%"); mainLayout.setMargin(true); mainLayout.setSpacing(true); encodingSelect = new NativeSelect(ctx.tr("dialog.tlfs.encoding")); for (Encoding encoding : Encoding.values()) { encodingSelect.addItem(encoding); encodingSelect.setItemCaption(encoding, encoding.getCharset()); } encodingSelect.setNullSelectionAllowed(false); encodingSelect.setImmediate(true); TextField txtSearch = new TextField(this.ctx.tr("dialog.tlfs.search"), search); txtSearch.setWidth("100%"); TextField txtReplace = new TextField(this.ctx.tr("dialog.tlfs.replace"), replace); txtReplace.setWidth("100%"); mainLayout.addComponent(encodingSelect); mainLayout.addComponent(txtSearch); mainLayout.addComponent(txtReplace); setCompositionRoot(mainLayout); }
private void fillPredecessorCanditatesToSelect(AbstractStep step, final NativeSelect<AbstractStep> predecessorSelect) { List<AbstractStep> items = new ArrayList<>(); for (Step stepCanditate : gantt.getSteps()) { if (!stepCanditate.equals(step) && stepCanditate instanceof Step) { items.add(stepCanditate); } } predecessorSelect.setItems(items); }
private SubStep addSubStep(final NativeSelect parentStepSelect, AbstractStep dataSource) { SubStep subStep = new SubStep(); subStep.setCaption(dataSource.getCaption()); subStep.setCaptionMode(dataSource.getCaptionMode()); subStep.setStartDate(dataSource.getStartDate()); subStep.setEndDate(dataSource.getEndDate()); subStep.setBackgroundColor(dataSource.getBackgroundColor()); subStep.setDescription(dataSource.getDescription()); subStep.setProgress(dataSource.getProgress()); subStep.setShowProgress(dataSource.isShowProgress()); subStep.setStyleName(dataSource.getStyleName()); ((Step) parentStepSelect.getValue()).addSubStep(subStep); return subStep; }
public static NativeSelect createHeightUnitEditor(final Component component) { return createNativeSelectEditor("Height Unit", component.getHeightUnits(), Arrays.asList(Unit.PERCENTAGE, Unit.PIXELS), new SelectValueChange() { @Override public void onValueChange(Object unit) { component.setHeight(component.getHeight(), (Unit) unit); } }); }
public static NativeSelect createWidthUnitEditor(final Component component) { return createNativeSelectEditor("Width Unit", component.getWidthUnits(), Arrays.asList(Unit.PERCENTAGE, Unit.PIXELS), new SelectValueChange() { @Override public void onValueChange(Object unit) { component.setWidth(component.getWidth(), (Unit) unit); } }); }
private void initGrid() { this.grid = new Grid<>(PropertyItem.class); this.grid.removeAllColumns(); Column<PropertyItem, String> propertyColumn = this.grid.addColumn(PropertyItem::getKey) .setCaption("Property") .setExpandRatio(1); Column<PropertyItem, String> valueColumn = this.grid.addColumn(PropertyItem::getValue) .setCaption("Value") .setExpandRatio(1); Column<PropertyItem, String> originColumn = this.grid.addColumn(PropertyItem::getOrigin).setCaption("Origin"); this.grid.sort(propertyColumn); this.grid.setSizeFull(); this.grid.setRowHeight(40); // distinct origin List<String> origins = this.currentEnv.getProperties().stream() .map(PropertyItem::getOrigin) .distinct() .sorted(String::compareTo) .collect(Collectors.toList()); // Filters TextField filterProperty = new TextField(); TextField filterValue = new TextField(); NativeSelect<String> filterOrigin = new NativeSelect<>(null, origins); filterProperty.setPlaceholder("filter by key..."); filterProperty.addValueChangeListener(e -> updateProperties(e.getValue(), filterValue.getValue(), filterOrigin.getValue())); filterProperty.setValueChangeMode(ValueChangeMode.LAZY); filterProperty.focus(); filterProperty.setSizeFull(); filterValue.setPlaceholder("filter by value..."); filterValue.addValueChangeListener(e -> updateProperties(filterProperty.getValue(), e.getValue(), filterOrigin.getValue())); filterValue.setValueChangeMode(ValueChangeMode.LAZY); filterValue.setSizeFull(); filterOrigin.addValueChangeListener(e -> updateProperties(filterProperty.getValue(), filterValue.getValue(), e.getValue())); filterOrigin.setSizeFull(); // Header row HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount()); filterRow.getCell(propertyColumn).setComponent(filterProperty); filterRow.getCell(valueColumn).setComponent(filterValue); filterRow.getCell(originColumn).setComponent(filterOrigin); }
@Override public void enter(ViewChangeEvent event) { pageHelper.setErrorHandler(this); this.removeAllComponents(); // Get application int appId = Integer.parseInt(event.getParameters()); Application app = pageHelper.getApp(appId); // Get loggers config Optional<Loggers> loggers = getLoggers(app); if(loggers.isPresent()) { // Display loggers in a grid grid = new Grid<>(LoggerGridRow.class); grid.removeAllColumns(); Column<LoggerGridRow, String> nameColumn = grid.addColumn(LoggerGridRow::getName) .setCaption("Name") .setExpandRatio(2); grid.addComponentColumn(logger -> { NativeSelect<String> levelsDropdown = new NativeSelect<>(null, loggers.get().getLevels()); levelsDropdown.setEmptySelectionAllowed(false); levelsDropdown.setSelectedItem(logger.getLevel()); // on selected level levelsDropdown.addValueChangeListener(value -> { // change logger level loggersService.changeLevel(app, logger.getName(), value.getValue()); // refresh data in grid (several loggers might have been impacted) updateLoggers(app); Notification.show( String.format("Logger %s level changed to %s", logger.getName(), value.getValue()) , Notification.Type.TRAY_NOTIFICATION); }); return levelsDropdown; }) .setCaption("Level") .setExpandRatio(1); grid.setSizeFull(); grid.setRowHeight(40); grid.setItems(loggersRows); grid.sort(nameColumn); // Filter grid by logger name filterInput = new TextField(); filterInput.setPlaceholder("filter by logger name..."); filterInput.addValueChangeListener(e -> filterLoggers(e.getValue())); filterInput.setValueChangeMode(ValueChangeMode.LAZY); filterInput.focus(); filterInput.setSizeFull(); // Header row HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount()); filterRow.getCell(nameColumn).setComponent(filterInput); this.addComponent(new PageHeader(app, "Loggers")); this.addComponent(new Label("Changing a level will update one/many logger(s) level(s)")); this.addComponent(grid); } else { this.addComponent(new PageHeader(app, "Loggers")); this.addComponent(new Label(String.format("Failed to call %s<br />This endpoint is available since Spring Boot 1.5", app.endpoints().loggers()), ContentMode.HTML)); } }
/** * Adds the font settings panel in dialog */ private void addFontSettings(StyleSettings styles) { final Panel p = new Panel(main.getUIText(StandardUIConstants.FONT)); final Layout pL = new VerticalLayout(); p.setContent(pL); p.setStyleName("light"); fontFamily = new NativeSelect( main.getUIText(StandardUIConstants.FONT_FAMILY)); fontFamily.setNullSelectionAllowed(false); for (String font : FONTS) { fontFamily.addItem(font); } fontFamily.select(styles.getFontFamily()); fontSize = new NativeSelect( main.getUIText(StandardUIConstants.FONT_SIZE)); fontSize.setNullSelectionAllowed(false); for (String size : FONT_SIZES) { fontSize.addItem(size); } fontSize.select(styles.getFontSize()); fontBolded = new CheckBox(main.getUIText(StandardUIConstants.BOLDED)); fontBolded.setValue(styles.isFontBolded()); fontItalic = new CheckBox(main.getUIText(StandardUIConstants.ITALIC)); fontItalic.setValue(styles.isFontItalic()); final GridLayout gl = new GridLayout(4, 1); gl.setWidth("100%"); gl.addComponent(fontFamily); gl.addComponent(fontSize); gl.addComponent(fontBolded); gl.setComponentAlignment(fontBolded, new Alignment( Bits.ALIGNMENT_BOTTOM)); gl.addComponent(fontItalic); gl.setComponentAlignment(fontItalic, new Alignment( Bits.ALIGNMENT_BOTTOM)); pL.addComponent(gl); addComponent(p); }
public JobLogFilter(final JobLogView view, String column, String search) { this.view = view; searchStringField = new TextField(); if (search != null) { searchStringField.setValue(search); } searchStringField.setDescription("Search for values starting with this string. Question mark (?) is a wildcard for a single character and asterisk (*) for any number of characters."); searchStringField.addShortcutListener(new ShortcutListener("Search", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { view.update(); } }); columnToSearch = new NativeSelect(); Button clearButton = new Button(); clearButton.setIcon(new ThemeResource("crystal/button_cancel-bw.png")); clearButton.setDescription("Remove filter"); clearButton.addStyleName("search-button"); for (int i = 0; i < JobLogContainer.NATURAL_COL_ORDER.length; i++) { //Do not search from generated columns if (SEARCH_COLUMNS.contains(JobLogContainer.NATURAL_COL_ORDER[i])) { columnToSearch.addItem(JobLogContainer.NATURAL_COL_ORDER[i]); columnToSearch.setItemCaption(JobLogContainer.NATURAL_COL_ORDER[i], JobLogContainer.COL_HEADERS_ENGLISH[i]); } } if (column != null) { columnToSearch.setValue(column); } else { columnToSearch.setValue(JobLogContainer.USERNAME); } columnToSearch.setNullSelectionAllowed(false); clearButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { getView().clearFilter(JobLogFilter.this); } }); addComponent(columnToSearch); addComponent(searchStringField); addComponent(clearButton); addStyleName("search-filter-bg"); addStyleName("search-filter"); }
public NativeSelectBuilder() { super(NativeSelectBuilder.class, new NativeSelect()); }
@Test public void shouldSetRequired() throws Exception { NativeSelect nativeSelect = NativeSelectBuilder.nativeSelect().required().build(); assertThat(nativeSelect.isRequired()).isEqualTo(true); }
@Test public void shouldSetCaptionInStaticFactory() throws Exception { NativeSelect nativeSelect = NativeSelectBuilder.nativeSelect("caption").build(); assertThat(nativeSelect.getCaption()).isEqualTo("caption"); }
@Test public void shouldDisableComponent() throws Exception { NativeSelect nativeSelect = NativeSelectBuilder.nativeSelect().disabled().build(); assertThat(nativeSelect.isEnabled()).isFalse(); }
@Test public void shouldSetVisibility() throws Exception { NativeSelect nativeSelect = NativeSelectBuilder.nativeSelect().invisible().build(); assertThat(nativeSelect.isVisible()).isFalse(); }
/** * Sets the item caption generator that is used to produce the strings shown * in the combo box for each item. By default, * {@link String#valueOf(Object)} is used. * * @param itemCaptionGenerator * the item caption provider to use, not null * @return this for method chaining * @see NativeSelect#setItemCaptionGenerator(ItemCaptionGenerator) */ @SuppressWarnings("unchecked") public default THIS withItemCaptionGenerator(ItemCaptionGenerator<ITEM> itemCaptionGenerator) { ((NativeSelect<ITEM>) this).setItemCaptionGenerator(itemCaptionGenerator); return (THIS) this; }
/** * Sets the number of items that are visible. If only one item is visible, * then the box will be displayed as a drop-down list (the default). * * @param visibleItemCount * the visible item count * @throws IllegalArgumentException * if the value is smaller than one * @return this for method chaining * @see NativeSelect#setVisibleItemCount(int) */ @SuppressWarnings("unchecked") public default THIS withVisibleItemCount(int visibleItemCount) { ((NativeSelect<ITEM>) this).setVisibleItemCount(visibleItemCount); return (THIS) this; }
/** * Sets whether the user is allowed to select nothing in the combo box. When * true, a special empty item is shown to the user. * * @param emptySelectionAllowed * true to allow not selecting anything, false to require * selection * @return this for method chaining * @see NativeSelect#setEmptySelectionAllowed(boolean) */ @SuppressWarnings("unchecked") public default THIS withEmptySelectionAllowed(boolean emptySelectionAllowed) { ((NativeSelect<ITEM>) this).setEmptySelectionAllowed(emptySelectionAllowed); return (THIS) this; }
/** * Sets the empty selection caption. * <p> * The empty string {@code ""} is the default empty selection caption. * <p> * If empty selection is allowed via the * {@link NativeSelect#setEmptySelectionAllowed(boolean)} method (it is by default) then * the empty item will be shown with the given caption. * * @param caption * the caption to set, not {@code null} * @return this for method chaining * @see NativeSelect#setEmptySelectionCaption(String) * @see NativeSelect#isSelected(Object) */ @SuppressWarnings("unchecked") public default THIS withEmptySelectionCaption(String caption) { ((NativeSelect<ITEM>) this).setEmptySelectionCaption(caption); return (THIS) this; }
/** * Creates a new {@code NativeSelect} with an empty caption and no items. * * @since 0.1 */ // Copied from Vaadin Framework public NativeSelectGroup() { this(new NativeSelect<>()); }
/** * Creates a new {@code NativeSelect} with the given caption and no items. * * @param caption the component caption to set, null for no caption * @since 0.1 */ // Copied from Vaadin Framework public NativeSelectGroup(String caption) { this(new NativeSelect<>(caption)); }
/** * Creates a new {@code NativeSelect} with the given caption, containing the * data items in the given collection. * * @param caption the component caption to set, null for no caption * @param items the data items to use, not null * @since 0.1 */ // Copied from Vaadin Framework public NativeSelectGroup(String caption, Collection<V> items) { this(new NativeSelect<>(caption, items)); }
/** * Creates a new {@code NativeSelect} with the given caption, using the * given {@code DataProvider} as the source of data items. * * @param caption the component caption to set, null for no caption * @param dataProvider the source of data items to use, not null * @since 0.1 */ // Copied from Vaadin Framework public NativeSelectGroup(String caption, DataProvider<V, ?> dataProvider) { this(new NativeSelect<>(caption, dataProvider)); }
/** * Uses the given <code>NativeSelect</code> as base for the component. * * @param field the <code>NativeSelect</code> used in the component, not {@code null} * @since 0.1 */ public NativeSelectGroup(NativeSelect<V> field) { super(field); }