Java源码示例:com.vaadin.ui.NativeSelect
示例1
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);
}
}
示例2
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();
}
示例3
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;
}
示例4
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);
}
示例5
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;
}
示例6
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);
}
});
}
示例7
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);
}
});
}
示例8
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;
}
示例9
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");
}