Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2013-07-18 19:42:37 -0400
committerTom Schindl2013-07-18 19:42:37 -0400
commitbc6fc019825a2a0239da675f2c66bd1e4b60e2be (patch)
treedfec269369c1ccdbd40ec1735e6b914b6c2fcc2b
parent3fbd7b92d3b486a98517349bbd59b36ba6d6a416 (diff)
downloadorg.eclipse.efxclipse-bc6fc019825a2a0239da675f2c66bd1e4b60e2be.tar.gz
org.eclipse.efxclipse-bc6fc019825a2a0239da675f2c66bd1e4b60e2be.tar.xz
org.eclipse.efxclipse-bc6fc019825a2a0239da675f2c66bd1e4b60e2be.zip
Bug 410186 - [databinding] need to have special properties for selection
models
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/META-INF/MANIFEST.MF3
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueObservable.java17
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueProperty.java22
-rwxr-xr-xbundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/JFXUIProperties.java7
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlObservableValueDecorator.java23
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlPropertyValueProperty.java24
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlReadOnlyPropertyValueProperty.java68
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlValueProperty.java52
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/SingleSelectionProperty.java59
9 files changed, 270 insertions, 5 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/META-INF/MANIFEST.MF b/bundles/runtime/org.eclipse.fx.ui.databinding/META-INF/MANIFEST.MF
index 3f87bb12e..b7f156434 100644
--- a/bundles/runtime/org.eclipse.fx.ui.databinding/META-INF/MANIFEST.MF
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/META-INF/MANIFEST.MF
@@ -5,7 +5,8 @@ Bundle-SymbolicName: org.eclipse.fx.ui.databinding
Bundle-Version: 0.9.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.core.databinding.observable;bundle-version="1.4.1",
- org.eclipse.fx.core.databinding;bundle-version="0.9.0"
+ org.eclipse.fx.core.databinding;bundle-version="0.9.0",
+ org.eclipse.core.databinding.property
Export-Package: org.eclipse.fx.ui.databinding
Import-Package: javafx.animation;version="2.2.0",
javafx.application;version="2.2.0",
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueObservable.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueObservable.java
new file mode 100644
index 000000000..9aaa84509
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueObservable.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+
+public interface IJFXControlValueObservable extends IObservableValue {
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueProperty.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueProperty.java
new file mode 100644
index 000000000..6d8d62221
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/IJFXControlValueProperty.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding;
+
+import javafx.scene.control.Control;
+
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.property.value.IValueProperty;
+
+public interface IJFXControlValueProperty extends IValueProperty {
+ public IJFXControlValueObservable observe(Control control);
+ public IJFXControlValueObservable observe(Realm realm, Control control);
+ public IJFXControlValueObservable observeDelayed(int delay, Control control);
+}
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/JFXUIProperties.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/JFXUIProperties.java
index 5f056add9..8ee9c3459 100755
--- a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/JFXUIProperties.java
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/JFXUIProperties.java
@@ -10,11 +10,10 @@
*******************************************************************************/
package org.eclipse.fx.ui.databinding;
-import org.eclipse.fx.core.databinding.IJFXBeanValueProperty;
-import org.eclipse.fx.core.databinding.JFXBeanProperties;
+import org.eclipse.fx.ui.databinding.internal.SingleSelectionProperty;
public class JFXUIProperties {
- public static IJFXBeanValueProperty singleListViewSelection() {
- return JFXBeanProperties.value("selectionModel.selectedItem");
+ public static IJFXControlValueProperty singleViewSelection() {
+ return new SingleSelectionProperty();
}
}
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlObservableValueDecorator.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlObservableValueDecorator.java
new file mode 100644
index 000000000..cbe2d552b
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlObservableValueDecorator.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding.internal;
+
+import org.eclipse.core.databinding.observable.value.DecoratingObservableValue;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.fx.ui.databinding.IJFXControlValueObservable;
+
+public class ControlObservableValueDecorator extends DecoratingObservableValue implements IJFXControlValueObservable {
+
+ public ControlObservableValueDecorator(IObservableValue decorated) {
+ super(decorated, true);
+ }
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlPropertyValueProperty.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlPropertyValueProperty.java
new file mode 100644
index 000000000..586b62da8
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlPropertyValueProperty.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding.internal;
+
+import javafx.beans.property.Property;
+
+public abstract class ControlPropertyValueProperty extends ControlReadOnlyPropertyValueProperty {
+ protected abstract Property<Object> getProperty(Object source);
+
+ @Override
+ protected void doSetValue(Object source, Object value) {
+ Property<Object> p = getProperty(source);
+ p.setValue(value);
+ }
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlReadOnlyPropertyValueProperty.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlReadOnlyPropertyValueProperty.java
new file mode 100644
index 000000000..48b7bd49a
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlReadOnlyPropertyValueProperty.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding.internal;
+
+import javafx.beans.property.ReadOnlyProperty;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.property.INativePropertyListener;
+import org.eclipse.core.databinding.property.IProperty;
+import org.eclipse.core.databinding.property.ISimplePropertyListener;
+import org.eclipse.core.databinding.property.NativePropertyListener;
+
+public abstract class ControlReadOnlyPropertyValueProperty extends ControlValueProperty {
+
+ @Override
+ protected Object doGetValue(Object source) {
+ ReadOnlyProperty<Object> p = getProperty(source);
+ return p != null ? p.getValue() : null;
+ }
+
+ protected abstract ReadOnlyProperty<Object> getProperty(Object source);
+
+ @Override
+ public INativePropertyListener adaptListener(ISimplePropertyListener listener) {
+ return new ListenerImpl(this, listener);
+ }
+
+ class ListenerImpl extends NativePropertyListener implements ChangeListener<Object> {
+ private Object owner;
+
+ public ListenerImpl(IProperty property, ISimplePropertyListener listener) {
+ super(property, listener);
+ }
+
+ @Override
+ public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
+ fireChange(owner, Diffs.createValueDiff(oldValue, newValue));
+ }
+
+ @Override
+ protected void doAddTo(Object source) {
+ this.owner = source;
+ ReadOnlyProperty<Object> p = getProperty(source);
+ if( p != null ) {
+ p.addListener(this);
+ }
+ }
+
+ @Override
+ protected void doRemoveFrom(Object source) {
+ this.owner = null;
+ ReadOnlyProperty<Object> p = getProperty(source);
+ if( p != null ) {
+ p.removeListener(this);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlValueProperty.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlValueProperty.java
new file mode 100644
index 000000000..93cc8b419
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/ControlValueProperty.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding.internal;
+
+import javafx.scene.control.Control;
+
+import org.eclipse.core.databinding.observable.Observables;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.property.value.SimpleValueProperty;
+import org.eclipse.fx.core.databinding.JFXRealm;
+import org.eclipse.fx.ui.databinding.IJFXControlValueObservable;
+import org.eclipse.fx.ui.databinding.IJFXControlValueProperty;
+
+public abstract class ControlValueProperty extends SimpleValueProperty implements IJFXControlValueProperty {
+
+ @Override
+ public IJFXControlValueObservable observeDelayed(int delay, Control control) {
+ IObservableValue v = observe(control);
+ return new ControlObservableValueDecorator(Observables.observeDelayedValue(delay, v));
+ }
+
+ @Override
+ public IJFXControlValueObservable observe(Control control) {
+ IObservableValue v = super.observe(JFXRealm.getDefault(), control);
+ return new ControlObservableValueDecorator(v);
+ }
+
+ @Override
+ public IJFXControlValueObservable observe(Realm realm, Control control) {
+ IObservableValue v = super.observe(realm, control);
+ return new ControlObservableValueDecorator(v);
+ }
+
+ @Override
+ public IJFXControlValueObservable observe(Realm realm, Object source) {
+ return observe(realm, (Control)source);
+ }
+
+ @Override
+ public IJFXControlValueObservable observe(Object source) {
+ return observe((Control)source);
+ }
+}
diff --git a/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/SingleSelectionProperty.java b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/SingleSelectionProperty.java
new file mode 100644
index 000000000..695193e5e
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ui.databinding/src/org/eclipse/fx/ui/databinding/internal/SingleSelectionProperty.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BestSolution.at and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.fx.ui.databinding.internal;
+
+import javafx.beans.property.ReadOnlyProperty;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.ListView;
+import javafx.scene.control.SelectionModel;
+import javafx.scene.control.TableView;
+
+public class SingleSelectionProperty extends ControlReadOnlyPropertyValueProperty {
+
+ @Override
+ public Object getValueType() {
+ return null;
+ }
+
+ @Override
+ protected ReadOnlyProperty<Object> getProperty(Object source) {
+ SelectionModel<Object> model = getSelectionModel(source);
+ return model == null ? null : model.selectedItemProperty();
+ }
+
+ @SuppressWarnings("unchecked")
+ static SelectionModel<Object> getSelectionModel(Object source) {
+ SelectionModel<Object> m = null;
+ if( source instanceof ListView<?> ) {
+ m = ((ListView<Object>) source).getSelectionModel();
+ } else if( source instanceof ComboBox<?> ) {
+ m = ((ComboBox<Object>) source).getSelectionModel();
+ } else if( source instanceof ChoiceBox<?> ) {
+ m = ((ChoiceBox<Object>) source).getSelectionModel();
+ } else if( source instanceof TableView<?> ) {
+ m = ((TableView<Object>) source).getSelectionModel();
+ }
+ return m;
+ }
+
+ @Override
+ protected void doSetValue(Object source, Object value) {
+ SelectionModel<Object> o = getSelectionModel(source);
+ if( o != null ) {
+ if( value == null ) {
+ o.clearSelection();
+ } else {
+ o.select(value);
+ }
+ }
+ }
+}

Back to the top