List of usage examples for org.eclipse.jface.databinding.swt.typed WidgetProperties buttonSelection
public static IWidgetValueProperty<Button, Boolean> buttonSelection()
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet022ComputedListCombo.java
License:Open Source License
/** * @param shell//from w ww . j a va2s . com */ protected void createControls(Shell shell) { Composite composite = new Composite(shell, SWT.NONE); Group group = new Group(composite, SWT.NONE); group.setText("Filter"); Button male = new Button(group, SWT.CHECK); male.setText("Male"); Button female = new Button(group, SWT.CHECK); female.setText("Female"); final IObservableValue<Boolean> femaleObservable = WidgetProperties.buttonSelection().observe(female); final IObservableValue<Boolean> maleObservable = WidgetProperties.buttonSelection().observe(male); Combo combo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); GridDataFactory.defaultsFor(combo).align(SWT.BEGINNING, SWT.BEGINNING).applyTo(combo); ComboViewer viewer = new ComboViewer(combo); viewer.setContentProvider(new ObservableListContentProvider<>()); // We should really have an out-of-the box filtered list... IObservableList<Thing> filteredList = new ComputedList<Thing>() { @Override protected List<Thing> calculate() { List<Thing> result = new ArrayList<>(); for (Thing thing : model) { if (femaleObservable.getValue() && !thing.female) continue; if (maleObservable.getValue() && !thing.male) continue; result.add(thing); } return result; } }; viewer.setInput(filteredList); GridLayoutFactory.swtDefaults().applyTo(group); GridLayoutFactory.swtDefaults().applyTo(composite); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet023ConditionalVisibility.java
License:Open Source License
/** * @param shell/* w ww . j a v a 2 s.c o m*/ */ private void createControls(Shell shell) { Composite composite = new Composite(shell, SWT.NONE); Group radioGroup = new Group(composite, SWT.NONE); radioGroup.setText("Type"); Button textButton = new Button(radioGroup, SWT.RADIO); textButton.setText("Text"); Button rangeButton = new Button(radioGroup, SWT.RADIO); rangeButton.setText("Range"); GridLayoutFactory.swtDefaults().generateLayout(radioGroup); final Composite oneOfTwo = new Composite(composite, SWT.NONE); final StackLayout stackLayout = new StackLayout(); oneOfTwo.setLayout(stackLayout); final Group rangeGroup = new Group(oneOfTwo, SWT.NONE); rangeGroup.setText("Range"); Label fromLabel = new Label(rangeGroup, SWT.NONE); fromLabel.setText("From:"); fromText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); Label toLabel = new Label(rangeGroup, SWT.NONE); toLabel.setText("To:"); toText = new Text(rangeGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(rangeGroup); final Group textGroup = new Group(oneOfTwo, SWT.NONE); textGroup.setText("Text"); Label label = new Label(textGroup, SWT.NONE); label.setText("Text:"); text = new Text(textGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(textGroup); GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite); final IObservableValue<Boolean> rangeSelected = WidgetProperties.buttonSelection().observe(rangeButton); final IObservableValue<Boolean> textSelected = WidgetProperties.buttonSelection().observe(textButton); // Note that ControlUpdater is not API. new ControlUpdater(oneOfTwo) { @Override protected void updateControl() { if (rangeSelected.getValue()) { stackLayout.topControl = rangeGroup; oneOfTwo.layout(); } else if (textSelected.getValue()) { stackLayout.topControl = textGroup; oneOfTwo.layout(); } } }; }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet024SelectObservableValue.java
License:Open Source License
protected void createContents() { shell = new Shell(); shell.setSize(400, 300);//from w w w . j av a 2 s . c om shell.setLayout(new GridLayout(2, true)); shell.setText("Snippet024SelectObservableValue"); final ListViewer listViewer = new ListViewer(shell, SWT.BORDER); listViewer.setContentProvider(new ArrayContentProvider()); listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Group group = new Group(shell, SWT.NONE); group.setText("Radio Group"); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); group.setLayout(new GridLayout()); // Data Binding Color[] colors = Color.values(); listViewer.setInput(colors); IObservableValue<Color> listViewerSelection = ViewerProperties.singleSelection(Color.class) .observe(listViewer); SelectObservableValue<Color> radioGroup = new SelectObservableValue<>(); for (Color color : colors) { Button button = new Button(group, SWT.RADIO); button.setText(color.toString()); radioGroup.addOption(color, WidgetProperties.buttonSelection().observe(button)); } DataBindingContext dbc = new DataBindingContext(); dbc.bindValue(radioGroup, listViewerSelection); }
From source file:org.eclipse.n4js.ui.wizard.components.AccessModifierComponent.java
License:Open Source License
private void setupBindings() { // Access modifier property binding IObservableValue<Boolean> publicButtonSelection = WidgetProperties.buttonSelection() .observe(publicAccessModifierBox); IObservableValue<Boolean> projectButtonSelection = WidgetProperties.buttonSelection() .observe(projectAccessModifierBox); IObservableValue<Boolean> privateButtonSelection = WidgetProperties.buttonSelection() .observe(privateAccessModifierBox); SelectObservableValue<AccessModifier> accessModifierSelectObservable = new SelectObservableValue<>(); accessModifierSelectObservable.addOption(AccessModifier.PUBLIC, publicButtonSelection); accessModifierSelectObservable.addOption(AccessModifier.PROJECT, projectButtonSelection); accessModifierSelectObservable.addOption(AccessModifier.PRIVATE, privateButtonSelection); IObservableValue<AccessModifier> accessModifierProperty = BeanProperties.value(AccessModifiableModel.class, N4JSClassifierWizardModel.ACCESS_MODIFIER_PROPERTY, AccessModifier.class).observe(model); dataBindingContext.bindValue(accessModifierSelectObservable, accessModifierProperty); // Internal property binding IObservableValue<Boolean> internalValue = BeanProperties .value(AccessModifiableModel.class, N4JSClassifierWizardModel.INTERNAL_PROPERTY, Boolean.class) .observe(model);//from ww w. j av a 2 s.c o m IObservableValue<Boolean> internalUI = WidgetProperties.buttonSelection() .observe(getInternalAnnotationBox()); dataBindingContext.bindValue(internalUI, internalValue); }
From source file:org.eclipse.n4js.ui.wizard.components.FileTypeComponent.java
License:Open Source License
private void setupBindings() { // Definition file property binding (definition file) IObservableValue<Boolean> externalValue = BeanProperties .value(DefinitionFileModel.class, N4JSClassifierWizardModel.DEFINITION_FILE_PROPERTY, Boolean.class) .observe(model);/* w w w .jav a 2s.c o m*/ IObservableValue<Boolean> externalUI = WidgetProperties.buttonSelection().observe(definitionFileBox); getDataBindingContext().bindValue(externalUI, externalValue); }
From source file:org.eclipse.n4js.ui.wizard.components.OtherClassifierModifiersComponent.java
License:Open Source License
private void setupBindings() { // Final property binding if (null != finalAnnotationBox && model instanceof N4JSClassWizardModel) { IObservableValue<Boolean> finalValue = BeanProperties .value(N4JSClassWizardModel.class, N4JSClassWizardModel.FINAL_ANNOTATED_PROPERTY, Boolean.class) .observe((N4JSClassWizardModel) model); IObservableValue<Boolean> finalUI = WidgetProperties.buttonSelection().observe(finalAnnotationBox); getDataBindingContext().bindValue(finalUI, finalValue); }/* ww w.j a va2 s . co m*/ // n4js annotation property binding IObservableValue<Boolean> n4jsValue = BeanProperties.value(N4JSClassifierWizardModel.class, N4JSClassifierWizardModel.N4JS_ANNOTATED_PROPERTY, Boolean.class).observe(model); IObservableValue<Boolean> n4jsUI = WidgetProperties.buttonSelection().observe(n4jsAnnotationBox); getDataBindingContext().bindValue(n4jsUI, n4jsValue); }
From source file:org.eclipse.n4js.ui.wizard.project.N4JSNewProjectWizardCreationPage.java
License:Open Source License
private void initDefaultCreateGreeterBindings(DataBindingContext dbc, Button createGreeterFileButton) { // Bind the "create greeter file"-checkbox dbc.bindValue(WidgetProperties.buttonSelection().observe(createGreeterFileButton), BeanProperties .value(N4JSProjectInfo.class, N4JSProjectInfo.CREATE_GREETER_FILE_PROP_NAME).observe(projectInfo)); }
From source file:org.eclipse.n4js.ui.wizard.project.N4JSNewProjectWizardCreationPage.java
License:Open Source License
private void initTestProjectBinding(DataBindingContext dbc, Button addNormalSourceFolderButton, Button createTestGreeterFileButton) { // Bind the "normal source folder"-checkbox dbc.bindValue(WidgetProperties.buttonSelection().observe(addNormalSourceFolderButton), PojoProperties// www . j a v a2 s. c o m .value(N4JSProjectInfo.class, N4JSProjectInfo.ADDITIONAL_NORMAL_SOURCE_FOLDER_PROP_NAME) .observe(projectInfo)); // Bind the "Create greeter file"-checkbox dbc.bindValue(WidgetProperties.buttonSelection().observe(createTestGreeterFileButton), BeanProperties .value(N4JSProjectInfo.class, N4JSProjectInfo.CREATE_GREETER_FILE_PROP_NAME).observe(projectInfo)); }