Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorsten Sommer2013-05-23 03:07:24 -0400
committerTorsten Sommer2013-05-23 03:07:24 -0400
commit9c65298fe3c3ac08e4cb59814567742e7d782ceb (patch)
treeb4b9649e44405a03e110843fb41870e932720902
parent46410356c80d6e354914add57b0438d88f8cc86a (diff)
downloadorg.eclipse.efxclipse-9c65298fe3c3ac08e4cb59814567742e7d782ceb.tar.gz
org.eclipse.efxclipse-9c65298fe3c3ac08e4cb59814567742e7d782ceb.tar.xz
org.eclipse.efxclipse-9c65298fe3c3ac08e4cb59814567742e7d782ceb.zip
Reverted previous commit
-rw-r--r--.gitignore1
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/META-INF/MANIFEST.MF3
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml4
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/schema/controls.exsd18
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/Control.java53
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/DummyControlFactory.java14
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/CheckBoxControl.java27
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DummyControl.java32
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/EnumControl.java97
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/FormControlFactory.java52
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java136
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiTextControl.java134
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/TextFieldControl.java85
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryDescriptor.java14
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryRegistryImpl.java51
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/StaticApplicableTester.java122
-rwxr-xr-xbundles/runtime/org.eclipse.fx.emf.databinding/src/org/eclipse/fx/emf/databinding/edit/EMFEditFXProperties.java293
-rw-r--r--demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart.java9
18 files changed, 532 insertions, 613 deletions
diff --git a/.gitignore b/.gitignore
index 392e95cd9..9d89fa03f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
/org.eclipse.osgi
-bin/
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/META-INF/MANIFEST.MF b/bundles/runtime/org.eclipse.fx.ecp.ui/META-INF/MANIFEST.MF
index b8047efa9..be2db9508 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/META-INF/MANIFEST.MF
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/META-INF/MANIFEST.MF
@@ -12,8 +12,7 @@ Require-Bundle: org.eclipse.core.runtime,
com.google.guava;bundle-version="10.0.1",
org.eclipse.fx.emf.edit.ui;bundle-version="0.8.1",
org.eclipse.fx.ecp.dummy;bundle-version="1.0.0",
- org.eclipse.e4.ui.workbench;bundle-version="0.11.0",
- org.eclipse.fx.emf.databinding;bundle-version="0.8.1"
+ org.eclipse.e4.ui.workbench;bundle-version="0.11.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.fx.ecp.ui
Service-Component: OSGI-INF/modelElementOpener.xml
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml b/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml
index 7ca30d9e9..b1fd96fb4 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml
@@ -22,7 +22,6 @@
<factory
class="org.eclipse.fx.ecp.ui.controls.CheckBoxControl$Factory"
- multi="false"
id="org.eclipse.fx.ecp.ui.controls.checkBox"
showLabel="true">
<staticTest
@@ -34,7 +33,6 @@
<factory
class="org.eclipse.fx.ecp.ui.controls.TextFieldControl$Factory"
- multi="false"
id="org.eclipse.fx.ecp.ui.controls.textField"
showLabel="true">
@@ -92,7 +90,6 @@
</factory>
<factory
class="org.eclipse.fx.ecp.ui.controls.EnumControl$Factory"
- multi="false"
id="org.eclipse.fx.ecp.ui.controls.enumCombo"
showLabel="true">
<staticTest
@@ -103,7 +100,6 @@
</factory>
<factory
class="org.eclipse.fx.ecp.ui.controls.MultiControl$Factory"
- multi="true"
id="org.eclipse.fx.ecp.ui.controls.multiText"
showLabel="true">
<staticTest
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/schema/controls.exsd b/bundles/runtime/org.eclipse.fx.ecp.ui/schema/controls.exsd
index 714c2dc74..3e485d237 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/schema/controls.exsd
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/schema/controls.exsd
@@ -55,6 +55,7 @@
</annotation>
<complexType>
<choice>
+ <element ref="dynamicTest"/>
<element ref="staticTest" minOccurs="1" maxOccurs="unbounded"/>
</choice>
<attribute name="id" type="string" use="required">
@@ -81,11 +82,24 @@
</documentation>
</annotation>
</attribute>
- <attribute name="multi" type="boolean" use="required">
+ </complexType>
+ </element>
+
+ <element name="dynamicTest">
+ <annotation>
+ <documentation>
+ A dynamic test simply provides an implementation of the org.eclipse.emf.ecp.edit.util.ECPApplicableTester interface.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="testClass" type="string" use="required">
<annotation>
<documentation>
- Whether the control can be embedded into a multi-control. The default is true.
+ The implementation of the tester. The Class must extend the org.eclipse.emf.ecp.edit.util.ECPApplicableTester.
</documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.ecp.edit.util.ECPApplicableTester"/>
+ </appinfo>
</annotation>
</attribute>
</complexType>
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/Control.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/Control.java
index 2cca18e63..ba2b6b12d 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/Control.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/Control.java
@@ -2,62 +2,51 @@ package org.eclipse.fx.ecp.ui;
import java.util.Set;
-import javafx.beans.property.Property;
-
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecp.edit.ECPControlContext;
+import org.eclipse.emf.ecp.edit.util.ECPApplicableTester;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.impl.ControlFactoryRegistryImpl;
-@SuppressWarnings("restriction")
public interface Control {
-
+
void handleValidation(Diagnostic diagnostic);
-
+
void resetValidation();
interface Factory {
-
- Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context);
-
+
+ Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context);
+
interface Descriptor {
-
+
/**
* Creates a factory and returns it.
* <p>
- * An implementation may and usually does choose to create only one instance, which it returns for
- * each call.
+ * An implementation may and usually does choose to create only one instance,
+ * which it returns for each call.
* </p>
- *
* @return a factory.
*/
Factory createFactory();
-
+
String getID();
-
+
boolean showLabel();
-
- Set<ApplicableTester> getTesters();
-
+
+ Set<ECPApplicableTester> getTesters();
+
}
-
+
interface Registry {
-
+
Registry INSTANCE = new ControlFactoryRegistryImpl();
-
- Factory getFactory(EStructuralFeature feature, EObject modelElement, boolean multi);
-
+
+ Factory getFactory(Class<?> controlClass, IItemPropertyDescriptor propertyDescriptor, EObject modelElement);
+
}
-
- }
-
- public interface ApplicableTester {
-
- int NOT_APPLICABLE = -1;
-
- int isApplicable(EStructuralFeature feature, EObject eObject);
-
+
}
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/DummyControlFactory.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/DummyControlFactory.java
new file mode 100644
index 000000000..3e3621c82
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/DummyControlFactory.java
@@ -0,0 +1,14 @@
+package org.eclipse.fx.ecp.ui;
+
+import org.eclipse.emf.ecp.edit.ECPControlContext;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
+
+@SuppressWarnings("restriction")
+public class DummyControlFactory implements Control.Factory {
+
+ @Override
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return null;
+ }
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/CheckBoxControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/CheckBoxControl.java
index 43037771c..1a11b1673 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/CheckBoxControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/CheckBoxControl.java
@@ -1,17 +1,32 @@
package org.eclipse.fx.ecp.ui.controls;
-import javafx.beans.property.Property;
import javafx.scene.control.CheckBox;
+import javafx.scene.layout.VBox;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecp.edit.ECPControlContext;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
-public class CheckBoxControl extends CheckBox implements Control {
+@SuppressWarnings("restriction")
+public class CheckBoxControl extends VBox implements Control {
- public CheckBoxControl(Property<Boolean> property, ECPControlContext context) {
- selectedProperty().bindBidirectional(property);
+ public CheckBoxControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+ getStyleClass().add("formControl");
+
+ EObject modelElement = context.getModelElement();
+
+ EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
+ Object val = modelElement.eGet(feature);
+
+ CheckBox checkBox = new CheckBox();
+ checkBox.setSelected((Boolean) val);
+
+ getChildren().add(checkBox);
+
+ getChildren().add(new ValidationMessage());
}
@Override
@@ -29,8 +44,8 @@ public class CheckBoxControl extends CheckBox implements Control {
public static class Factory implements Control.Factory {
@Override
- public Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context) {
- return new CheckBoxControl((Property<Boolean>) property, context);
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new CheckBoxControl(itemPropertyDescriptor, context);
}
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DummyControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DummyControl.java
index 52607d297..ca3ef987f 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DummyControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DummyControl.java
@@ -1,20 +1,38 @@
package org.eclipse.fx.ecp.ui.controls;
-import javafx.beans.property.Property;
+import javafx.scene.control.Label;
import javafx.scene.control.TextField;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecp.edit.ECPControlContext;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
@SuppressWarnings("restriction")
-public class DummyControl extends TextField implements Control {
+public class DummyControl extends HBox implements Control {
- public DummyControl(Property<?> property, ECPControlContext context) {
- setText(property.getValue().toString());
- setDisable(true);
+ public DummyControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+ EObject modelElement = context.getModelElement();
+
+ String displayName = propertyDescriptor.getDisplayName(modelElement);
+ Label label = new Label(displayName);
+ label.getStyleClass().add(IControlConstants.CONTROL_LABEL_CLASS);
+ getChildren().add(label);
+
+ EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
+ Object val = modelElement.eGet(feature);
+
+ TextField textField = new TextField();
+ textField.setText(val.toString());
+ textField.setDisable(true);
+ HBox.setHgrow(textField, Priority.ALWAYS);
+
+ getChildren().add(textField);
}
@Override
@@ -30,8 +48,8 @@ public class DummyControl extends TextField implements Control {
public static class Factory implements Control.Factory {
@Override
- public Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context) {
- return new DummyControl(property, context);
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new DummyControl(itemPropertyDescriptor, context);
}
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/EnumControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/EnumControl.java
index 67576b13d..82752ae07 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/EnumControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/EnumControl.java
@@ -1,9 +1,7 @@
package org.eclipse.fx.ecp.ui.controls;
import java.util.ArrayList;
-import java.util.Collection;
-import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.ChoiceBox;
@@ -26,53 +24,106 @@ import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
@SuppressWarnings("restriction")
-public class EnumControl extends ChoiceBox<Enumerator> implements Control {
+public class EnumControl extends VBox implements Control {
- public EnumControl(final Property<Enumerator> property, Collection<Enumerator> values, ECPControlContext context) {
+ private ValidationMessage validationMessage;
- getItems().addAll(values);
+ public EnumControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+ final EObject modelElement = context.getModelElement();
+ final EditingDomain editingDomain = context.getEditingDomain();
- SingleSelectionModel<Enumerator> selectionModel = getSelectionModel();
+ final EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
- selectionModel.select(property.getValue());
+ ChoiceBox<Enumerator> choiceBox = new ChoiceBox<>();
+
+ EClassifier type = feature.getEType();
+
+ EEnum eEnum = (EEnum) type;
+
+ EList<EEnumLiteral> enumLiterals = eEnum.getELiterals();
+
+ ArrayList<Enumerator> values = new ArrayList<Enumerator>();
+
+ if (!feature.isRequired())
+ values.add(null);
+
+ for (EEnumLiteral literal : enumLiterals)
+ values.add(literal.getInstance());
+
+ choiceBox.getItems().addAll(values);
+
+ SingleSelectionModel<Enumerator> selectionModel = choiceBox.getSelectionModel();
+
+ Enumerator val = (Enumerator) modelElement.eGet(feature);
+
+ selectionModel.select(val);
+
+ getChildren().add(choiceBox);
selectionModel.selectedItemProperty().addListener(new ChangeListener<Enumerator>() {
@Override
public void changed(ObservableValue<? extends Enumerator> observableValue, Enumerator oldValue, Enumerator newValue) {
- property.setValue(newValue);
+ Command command = SetCommand.create(editingDomain, modelElement, feature, newValue);
+ if (command.canExecute())
+ editingDomain.getCommandStack().execute(command);
+
+ if(newValue == null) {
+ validationMessage.setMessage("A value must be selected");
+ } else {
+ validationMessage.setMessage(null);
+ }
}
});
+ validationMessage = new ValidationMessage();
+ getChildren().add(validationMessage);
}
@Override
public void handleValidation(Diagnostic diagnostic) {
-
+// if (diagnostic.getSeverity() != Diagnostic.OK) {
+//
+// validationMessage.setMessage(diagnostic.getMessage());
+//
+//// validationLabel.setText(diagnostic.getMessage());
+//
+// // Timeline timeline = new Timeline();
+// //
+// // timeline.getKeyFrames().addAll(
+// // new KeyFrame(Duration.ZERO, new
+// // KeyValue(rectangle.heightProperty(), 0, Interpolator.EASE_BOTH)),
+// // new KeyFrame(Duration.millis(300), new
+// // KeyValue(rectangle.heightProperty(), 50, Interpolator.EASE_BOTH))
+// // );
+// //
+// // timeline.play();
+//
+// // ScaleTransition transition = ScaleTransitionBuilder.create()
+// // .node(validationLabel)
+// // .duration(Duration.seconds(2))
+// // .fromY(0)
+// // .toY(1)
+// // .build();
+// // transition.play();
+//
+// } else {
+// resetValidation();
+// }
}
@Override
public void resetValidation() {
-
+// validationLabel.setText(null);
+
}
public static class Factory implements Control.Factory {
@Override
- public Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context) {
- EClassifier type = feature.getEType();
- EEnum eEnum = (EEnum) type;
- EList<EEnumLiteral> enumLiterals = eEnum.getELiterals();
- ArrayList<Enumerator> values = new ArrayList<Enumerator>();
-
- if (!feature.isRequired())
- values.add(null);
-
- for (EEnumLiteral literal : enumLiterals)
- values.add(literal.getInstance());
-
- return new EnumControl((Property<Enumerator>) property, values, context);
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new EnumControl(itemPropertyDescriptor, context);
}
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/FormControlFactory.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/FormControlFactory.java
new file mode 100644
index 000000000..8fa899e7e
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/FormControlFactory.java
@@ -0,0 +1,52 @@
+//package at.bestsolution.efxclipse.ecp.ui.controls;
+//
+//import javafx.scene.Node;
+//
+//import org.eclipse.emf.ecore.EAttribute;
+//import org.eclipse.emf.ecore.EClassifier;
+//import org.eclipse.emf.ecore.EDataType;
+//import org.eclipse.emf.ecore.EEnum;
+//import org.eclipse.emf.ecore.EObject;
+//import org.eclipse.emf.ecore.EReference;
+//import org.eclipse.emf.ecore.EStructuralFeature;
+//import org.eclipse.emf.ecore.EcorePackage;
+//import org.eclipse.emf.ecp.edit.ECPControlContext;
+//import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
+//
+//public class FormControlFactory {
+//
+// public Node createFormControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+//
+// EObject modelElement = context.getModelElement();
+// EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
+//
+// EClassifier type = feature.getEType();
+//
+// if (feature.isMany()) {
+// if (type == EcorePackage.Literals.ESTRING) {
+// return new MultiTextControl(propertyDescriptor, context);
+// }
+// if (feature instanceof EReference) {
+// return new MultiReferenceControl(propertyDescriptor, context);
+// }
+// } else {
+//
+// if (type == EcorePackage.Literals.EBOOLEAN) {
+// return new CheckBoxControl(propertyDescriptor, context);
+// } else if (type instanceof EEnum) {
+// return new EnumControl(propertyDescriptor, context);
+// } else if (feature instanceof EAttribute) {
+// TextFieldControl textFieldControl = new TextFieldControl(propertyDescriptor, context);
+// if (type instanceof EDataType && textFieldControl.isControlFor((EDataType) type))
+// return textFieldControl;
+// } else if (feature instanceof EReference) {
+// return new ReferenceControl(propertyDescriptor, context);
+// }
+//
+// }
+//
+// return new DummyControl(propertyDescriptor, context);
+//
+// }
+//
+//}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java
index b27ba5f73..21b6d7617 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiControl.java
@@ -1,19 +1,18 @@
package org.eclipse.fx.ecp.ui.controls;
+import java.io.InputStream;
import java.net.URL;
+import java.util.List;
import java.util.Objects;
-import javafx.beans.property.Property;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
+import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
+import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
-import javafx.scene.input.InputMethodEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
@@ -28,16 +27,15 @@ import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecp.edit.ECPControlContext;
-import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.DeleteCommand;
import org.eclipse.emf.edit.command.MoveCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
import org.eclipse.fx.ecp.ui.ECPUIPlugin;
-import org.eclipse.fx.emf.databinding.edit.EMFEditFXProperties;
-import org.eclipse.fx.emf.databinding.edit.EMFEditFXProperties.EListItemProperty;
import org.osgi.framework.Bundle;
@SuppressWarnings("all")
@@ -49,20 +47,13 @@ public class MultiControl extends VBox implements Control {
private EditingDomain editingDomain;
private EList<?> values;
private VBox controlsBox;
- private Button addButton;
- private TextField addTextField;
- private Command addCommand;
- private final ECPControlContext context;
-
- public MultiControl(final EStructuralFeature feature, final ECPControlContext context) {
- this.feature = feature;
- this.context = context;
+
+ public MultiControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
modelElement = context.getModelElement();
editingDomain = context.getEditingDomain();
+ feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
values = (EList<?>) modelElement.eGet(feature);
- setSpacing(4);
-
controlsBox = new VBox();
getChildren().add(controlsBox);
controlsBox.setSpacing(4);
@@ -70,42 +61,8 @@ public class MultiControl extends VBox implements Control {
for (int i = 0; i < values.size(); i++) {
controlsBox.getChildren().add(new ControlWrapper(i));
}
-
- HBox hBox = new HBox();
- getChildren().add(hBox);
-
- addTextField = new TextField();
- hBox.getChildren().add(addTextField);
-// addTextField.setText(feature.getDefaultValue().toString());
- addTextField.setPromptText("Enter a value");
- addTextField.setStyle("-fx-background-radius: 3 0 0 3, 2 0 0 2; -fx-background-insets: 0 0 1 0, 1 1 2 1;");
- addTextField.setMaxWidth(Double.MAX_VALUE);
- HBox.setHgrow(addTextField, Priority.ALWAYS);
- addTextField.textProperty().addListener(new ChangeListener<String>() {
-
- @Override
- public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
- updateAddButton();
- }
-
- });
-
- addButton = new Button(null, getImage("icons/add.png"));
- hBox.getChildren().add(addButton);
- addButton.getStyleClass().add("right-pill");
- addButton.setOnAction(new EventHandler<ActionEvent>() {
-
- @Override
- public void handle(ActionEvent arg0) {
- if(addCommand != null && addCommand.canExecute()) {
- editingDomain.getCommandStack().execute(addCommand);
- addTextField.setText(null);
- addTextField.requestFocus();
- }
- }
-
- });
+ getChildren().add(new Button(null, getImage("icons/add.png")));
modelElement.eAdapters().add(new AdapterImpl() {
@@ -115,51 +72,34 @@ public class MultiControl extends VBox implements Control {
if (Objects.equals(msg.getFeature(), feature)) {
final int position = msg.getPosition();
-
- final ObservableList<Node> children = controlsBox.getChildren();
-
+
switch (msg.getEventType()) {
case Notification.REMOVE:
- children.remove(position);
+ controlsBox.getChildren().remove(position);
break;
case Notification.MOVE:
int oldIndex = ((Integer) msg.getOldValue()).intValue();
- ControlWrapper controlWrapper = (ControlWrapper) children.remove(oldIndex);
- children.add(position, controlWrapper);
+ ControlWrapper controlWrapper = (ControlWrapper) controlsBox.getChildren().remove(oldIndex);
+ controlsBox.getChildren().add(position, controlWrapper);
controlWrapper.setIndex(position);
break;
- case Notification.ADD:
- controlsBox.getChildren().add(new ControlWrapper(position));
+ }
+
+ for (Node node : controlsBox.getChildren()) {
+ if(node instanceof ControlWrapper)
+ ((ControlWrapper) node).updateButtons();
}
- for (int i = 0; i < children.size(); i++)
- ((ControlWrapper) children.get(i)).setIndex(i);
-
- updateButtons(children);
-
- updateAddButton();
}
}
});
-
- updateAddButton();
validationMessage = new ValidationMessage();
getChildren().add(validationMessage);
}
- private void updateAddButton() {
- addCommand = AddCommand.create(editingDomain, modelElement, feature, addTextField.getText());
- addButton.setDisable(!addCommand.canExecute());
- }
-
- private void updateButtons(final ObservableList<Node> children) {
- for (Node node : children)
- ((ControlWrapper) node).updateButtons();
- }
-
public static ImageView getImage(String resourcePath) {
Bundle bundle = Platform.getBundle(ECPUIPlugin.PLUGIN_ID);
Path path = new Path(resourcePath);
@@ -184,8 +124,8 @@ public class MultiControl extends VBox implements Control {
public static class Factory implements Control.Factory {
@Override
- public Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context) {
- return new MultiControl(feature, context);
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new MultiControl(itemPropertyDescriptor, context);
}
}
@@ -198,32 +138,13 @@ public class MultiControl extends VBox implements Control {
public ControlWrapper(int initialIndex) {
index = initialIndex;
-
- setFillHeight(true);
- Object value = values.get(initialIndex);
- org.eclipse.fx.ecp.ui.Control.Factory factory = Control.Factory.Registry.INSTANCE.getFactory(feature, modelElement, false);
-
-
-// TextField label = new TextField();
-
- try {
- Property<?> property = EMFEditFXProperties.listItem(editingDomain, modelElement, feature, initialIndex);
- Node control = (Node) factory.createControl(property, feature, context);
- getChildren().add(control);
-// label.textProperty().bindBidirectional((Property<String>) property);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-// if(value != null)
-// label.setText(value.toString());
-// label.setPromptText("Please enter a value");
-// label.setMaxWidth(Double.MAX_VALUE);
-// HBox.setHgrow(label, Priority.ALWAYS);
-// label.setStyle("-fx-background-radius: 3 0 0 3, 2 0 0 2; -fx-background-insets: 0 0 1 0, 1 1 2 1;");
-// getChildren().add(label);
+ setFillHeight(true);
+ TextField label = new TextField(values.get(initialIndex).toString());
+ label.setMaxWidth(Double.MAX_VALUE);
+ HBox.setHgrow(label, Priority.ALWAYS);
+ label.setStyle("-fx-background-radius: 3 0 0 3, 2 0 0 2; -fx-background-insets: 0 0 1 0, 1 1 2 1;");
+ getChildren().add(label);
if (feature.isOrdered()) {
@@ -270,9 +191,10 @@ public class MultiControl extends VBox implements Control {
}
});
-
+
updateButtons();
}
+
public void setIndex(int index) {
this.index = index;
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiTextControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiTextControl.java
index f29e147dd..79531191d 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiTextControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/MultiTextControl.java
@@ -1,67 +1,67 @@
-//package org.eclipse.fx.ecp.ui.controls;
-//
-//import java.util.List;
-//
-//import javafx.collections.FXCollections;
-//import javafx.scene.control.ListView;
-//import javafx.scene.layout.VBox;
-//
-//import org.eclipse.emf.common.util.Diagnostic;
-//import org.eclipse.emf.ecore.EObject;
-//import org.eclipse.emf.ecore.EStructuralFeature;
-//import org.eclipse.emf.ecp.edit.ECPControlContext;
-//import org.eclipse.emf.edit.domain.EditingDomain;
-//import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
-//import org.eclipse.fx.ecp.ui.Control;
-//
-//@SuppressWarnings("restriction")
-//public class MultiTextControl extends VBox implements Control {
-//
-// private ValidationMessage validationMessage = null;
-//
-// public MultiTextControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
-// final EObject modelElement = context.getModelElement();
-// final EditingDomain editingDomain = context.getEditingDomain();
-//
-// getStyleClass().add("multiTextControl");
-//
-// final EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
-//
-// ListView<Object> listView = new ListView<>();
-//
-// List<Object> values = (List<Object>) modelElement.eGet(feature);
-//
-// listView.setItems(FXCollections.observableList(values));
-//
-// getChildren().add(listView);
-//
-// listView.setDisable(true);
-//
-// validationMessage = new ValidationMessage();
-// getChildren().add(validationMessage);
-// }
-//
-// @Override
-// public void handleValidation(Diagnostic diagnostic) {
-// if (diagnostic.getSeverity() != Diagnostic.OK) {
-// validationMessage.setMessage(diagnostic.getMessage());
-// } else {
-// resetValidation();
-// }
-// }
-//
-// @Override
-// public void resetValidation() {
-// validationMessage.setMessage(null);
-// }
-//
-// public static class Factory implements Control.Factory {
-//
-// @Override
-// public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
-// return new MultiTextControl(itemPropertyDescriptor, context);
-// }
-//
-// }
-//
-//}
+package org.eclipse.fx.ecp.ui.controls;
+
+import java.util.List;
+
+import javafx.collections.FXCollections;
+import javafx.scene.control.ListView;
+import javafx.scene.layout.VBox;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecp.edit.ECPControlContext;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
+import org.eclipse.fx.ecp.ui.Control;
+
+@SuppressWarnings("restriction")
+public class MultiTextControl extends VBox implements Control {
+
+ private ValidationMessage validationMessage = null;
+
+ public MultiTextControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+ final EObject modelElement = context.getModelElement();
+ final EditingDomain editingDomain = context.getEditingDomain();
+
+ getStyleClass().add("multiTextControl");
+
+ final EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
+
+ ListView<Object> listView = new ListView<>();
+
+ List<Object> values = (List<Object>) modelElement.eGet(feature);
+
+ listView.setItems(FXCollections.observableList(values));
+
+ getChildren().add(listView);
+
+ listView.setDisable(true);
+
+ validationMessage = new ValidationMessage();
+ getChildren().add(validationMessage);
+ }
+
+ @Override
+ public void handleValidation(Diagnostic diagnostic) {
+ if (diagnostic.getSeverity() != Diagnostic.OK) {
+ validationMessage.setMessage(diagnostic.getMessage());
+ } else {
+ resetValidation();
+ }
+ }
+
+ @Override
+ public void resetValidation() {
+ validationMessage.setMessage(null);
+ }
+
+ public static class Factory implements Control.Factory {
+
+ @Override
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new MultiTextControl(itemPropertyDescriptor, context);
+ }
+
+ }
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/TextFieldControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/TextFieldControl.java
index 1549b8b87..c31a96bbf 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/TextFieldControl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/TextFieldControl.java
@@ -1,68 +1,113 @@
package org.eclipse.fx.ecp.ui.controls;
-import javafx.beans.property.Property;
+import java.util.Objects;
+
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
+import javafx.collections.ObservableList;
import javafx.scene.control.TextField;
+import javafx.scene.layout.VBox;
+import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecp.edit.ECPControlContext;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
@SuppressWarnings("restriction")
-public class TextFieldControl extends TextField implements Control {
+public class TextFieldControl extends VBox implements Control {
+
+ private TextField textField;
+ private ValidationMessage validationMessage = null;
+
+ public TextFieldControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
- public TextFieldControl(final Property<Object> property, EStructuralFeature feature, ECPControlContext context) {
+ final EObject modelElement = context.getModelElement();
+ final EditingDomain editingDomain = context.getEditingDomain();
+
+ final EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
final EDataTypeValueHandler valueHandler = new EDataTypeValueHandler((EDataType) feature.getEType());
- setText(valueHandler.toString(property.getValue()));
+ Object value = modelElement.eGet(feature);
+
+ textField = new TextField(valueHandler.toString(value));
- property.addListener(new ChangeListener<Object>() {
+ textField.textProperty().addListener(new ChangeListener<String>() {
@Override
- public void changed(ObservableValue<? extends Object> arg0, Object arg1, Object arg2) {
- String text = valueHandler.toString(arg2);
- setText(text);
+ public void changed(ObservableValue<? extends String> observableValue, String oldText, String newText) {
+ final String message = valueHandler.isValid(newText);
+ ObservableList<String> styleClass = textField.getStyleClass();
+ if (message == null) {
+ styleClass.remove(IControlConstants.INVALID_CLASS);
+ } else {
+ if (!styleClass.contains(IControlConstants.INVALID_CLASS))
+ styleClass.add(IControlConstants.INVALID_CLASS);
+ }
+ validationMessage.setMessage(message);
}
});
- textProperty().addListener(new ChangeListener<String>() {
+ textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
- public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
- try {
- Object value = valueHandler.toValue(arg2);
- property.setValue(value);
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ public void changed(ObservableValue<? extends Boolean> observableValue, Boolean oldFocused, Boolean newFocused) {
+ if (!newFocused) {
+ Object oldValue = modelElement.eGet(feature);
+ String text = textField.getText();
+ String message = valueHandler.isValid(text);
+
+ if (message == null) {
+ Object newValue = valueHandler.toValue(text);
+
+ // only commit if the value has changed
+ if (!Objects.equals(oldValue, newValue)) {
+ Command command = SetCommand.create(editingDomain, modelElement, feature, newValue);
+ if (command.canExecute())
+ editingDomain.getCommandStack().execute(command);
+ }
+ } else {
+ System.err.println(message);
+ }
}
}
});
+
+ getChildren().add(textField);
+
+ validationMessage = new ValidationMessage();
+ getChildren().add(validationMessage);
}
@Override
public void handleValidation(Diagnostic diagnostic) {
-
+ if (diagnostic.getSeverity() != Diagnostic.OK) {
+ validationMessage.setMessage(diagnostic.getMessage());
+ } else {
+ resetValidation();
+ }
}
@Override
public void resetValidation() {
-
+ validationMessage.setMessage(null);
}
public static class Factory implements Control.Factory {
@Override
- public Control createControl(Property<?> property, EStructuralFeature feature, ECPControlContext context) {
- return new TextFieldControl((Property<Object>) property, feature, context);
+ public Control createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new TextFieldControl(itemPropertyDescriptor, context);
}
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryDescriptor.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryDescriptor.java
index 71a06154b..a960345cc 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryDescriptor.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryDescriptor.java
@@ -2,8 +2,8 @@ package org.eclipse.fx.ecp.ui.impl;
import java.util.Set;
+import org.eclipse.emf.ecp.edit.util.ECPApplicableTester;
import org.eclipse.fx.ecp.ui.Control;
-import org.eclipse.fx.ecp.ui.Control.ApplicableTester;
import org.eclipse.fx.ecp.ui.Control.Factory;
public class ControlFactoryDescriptor implements Control.Factory.Descriptor {
@@ -11,15 +11,13 @@ public class ControlFactoryDescriptor implements Control.Factory.Descriptor {
private final String id;
private final Factory factoryInstance;
private final boolean showLabel;
- private final Set<ApplicableTester> applicableTesters;
- private final boolean multi;
+ private final Set<ECPApplicableTester> applicableTesters;
- public ControlFactoryDescriptor(String id, Factory factoryInstance, boolean showLabel, Set<ApplicableTester> applicableTesters, boolean multi) {
+ public ControlFactoryDescriptor(String id, Factory factoryInstance, boolean showLabel, Set<ECPApplicableTester> applicableTesters) {
this.id = id;
this.factoryInstance = factoryInstance;
this.showLabel = showLabel;
this.applicableTesters = applicableTesters;
- this.multi = multi;
}
public Factory createFactory() {
@@ -34,12 +32,8 @@ public class ControlFactoryDescriptor implements Control.Factory.Descriptor {
return showLabel;
}
- public Set<ApplicableTester> getTesters() {
+ public Set<ECPApplicableTester> getTesters() {
return applicableTesters;
}
-
- public boolean isMulti() {
- return multi;
- }
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryRegistryImpl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryRegistryImpl.java
index ddeedf573..5297973a4 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryRegistryImpl.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/ControlFactoryRegistryImpl.java
@@ -7,9 +7,10 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecp.edit.util.ECPApplicableTester;
+import org.eclipse.emf.ecp.edit.util.StaticApplicableTester;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.fx.ecp.ui.Control;
-import org.eclipse.fx.ecp.ui.Control.ApplicableTester;
import org.eclipse.fx.ecp.ui.Control.Factory;
import org.osgi.framework.Bundle;
@@ -19,9 +20,8 @@ public class ControlFactoryRegistryImpl implements Control.Factory.Registry {
private static final String CLASS_ATTRIBUTE = "class";
private static final String CONTROL_ID = "id";
+ private static final String CONTROL_CLASS_ATTRIBUTE = "controlClass";
private static final String LABEL_ATTRIBUTE = "showLabel";
- private static final String CONTROL_EMBEDDABLE = "embeddable";
- private static final String CONTROL_MULTI = "multi";
private static final String TEST_DYNAMIC = "dynamicTest";
private static final String CONTROL_TESTER = "testClass";
@@ -31,6 +31,7 @@ public class ControlFactoryRegistryImpl implements Control.Factory.Registry {
private static final String TESTER_CLASSTYPE = "supportedClassType";
private static final String TESTER_EOBJECT = "supportedEObject";
private static final String TESTER_FEATURE = "supportedFeature";
+ private static final String TESTER_SINGLEVALUE = "singleValue";
private final Set<ControlFactoryDescriptor> controlDescriptors = new HashSet<ControlFactoryDescriptor>();
@@ -38,29 +39,33 @@ public class ControlFactoryRegistryImpl implements Control.Factory.Registry {
readExtensionPoint();
}
- public Factory getFactory(EStructuralFeature feature, EObject modelElement, boolean multi) {
- ControlFactoryDescriptor factoryDescriptor = getControlFactoryCandidate(feature, modelElement, multi);
+ public Factory getFactory(Class<?> controlClass, IItemPropertyDescriptor propertyDescriptor, EObject modelElement) {
+ ControlFactoryDescriptor factoryDescriptor = getControlFactoryCandidate(controlClass, propertyDescriptor,
+ modelElement);
return factoryDescriptor != null ? factoryDescriptor.createFactory() : null;
}
private void readExtensionPoint() {
- IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(CONTROL_EXTENSION);
+ IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(
+ CONTROL_EXTENSION);
for (IConfigurationElement configurationElement : configurationElements) {
try {
String id = configurationElement.getAttribute(CONTROL_ID);
- Control.Factory factory = (Control.Factory) configurationElement.createExecutableExtension(CLASS_ATTRIBUTE);
-
+ Control.Factory factory = (Control.Factory) configurationElement
+ .createExecutableExtension(CLASS_ATTRIBUTE);
boolean showLabel = Boolean.parseBoolean(configurationElement.getAttribute(LABEL_ATTRIBUTE));
- boolean multi = Boolean.parseBoolean(configurationElement.getAttribute(CONTROL_MULTI));
+ String controlClass = configurationElement.getAttribute(CONTROL_CLASS_ATTRIBUTE);
+// Class<?> resolvedWidgetClass = loadClass(configurationElement.getContributor().getName(), controlClass);
- Set<ApplicableTester> testers = new HashSet<ApplicableTester>();
+ Set<ECPApplicableTester> testers = new HashSet<ECPApplicableTester>();
for (IConfigurationElement testerExtension : configurationElement.getChildren()) {
if (TEST_DYNAMIC.equals(testerExtension.getName())) {
- testers.add((ApplicableTester) testerExtension.createExecutableExtension(CONTROL_TESTER));
+ testers.add((ECPApplicableTester) testerExtension.createExecutableExtension(CONTROL_TESTER));
} else if (TEST_STATIC.equals(testerExtension.getName())) {
+ boolean singleValue = Boolean.parseBoolean(testerExtension.getAttribute(TESTER_SINGLEVALUE));
int priority = Integer.parseInt(testerExtension.getAttribute(TESTER_PRIORITY));
String type = testerExtension.getAttribute(TESTER_CLASSTYPE);
@@ -71,17 +76,18 @@ public class ControlFactoryRegistryImpl implements Control.Factory.Registry {
if (eObject == null)
eObject = "org.eclipse.emf.ecore.EObject";
- Class<? extends EObject> supportedEObject = loadClass(testerExtension.getContributor().getName(), eObject);
+ Class<? extends EObject> supportedEObject = loadClass(testerExtension.getContributor()
+ .getName(), eObject);
String supportedFeature = testerExtension.getAttribute(TESTER_FEATURE);
- testers.add(new StaticApplicableTester(priority, supportedClassType, supportedEObject,
- supportedFeature));
+ testers.add(new StaticApplicableTester(singleValue, priority, supportedClassType,
+ supportedEObject, supportedFeature));
}
}
- controlDescriptors.add(new ControlFactoryDescriptor(id, factory, showLabel, testers, multi));
+ controlDescriptors.add(new ControlFactoryDescriptor(id, factory, showLabel, testers));
} catch (ClassNotFoundException e1) {
// TODO log exception
e1.printStackTrace();
@@ -97,24 +103,23 @@ public class ControlFactoryRegistryImpl implements Control.Factory.Registry {
Bundle bundle = Platform.getBundle(bundleName);
if (bundle == null) {
// TODO externalize strings
- throw new ClassNotFoundException(clazz + " cannot be loaded because bundle " + bundleName + " cannot be resolved");
+ throw new ClassNotFoundException(clazz + " cannot be loaded because bundle " + bundleName
+ + " cannot be resolved");
}
return (Class<T>) bundle.loadClass(clazz);
}
- private ControlFactoryDescriptor getControlFactoryCandidate(EStructuralFeature feature, EObject modelElement, boolean multi) {
+ private ControlFactoryDescriptor getControlFactoryCandidate(Class<?> clazz,
+ IItemPropertyDescriptor itemPropertyDescriptor, EObject modelElement) {
int highestPriority = -1;
ControlFactoryDescriptor bestCandidate = null;
for (ControlFactoryDescriptor descriptor : controlDescriptors) {
- if(descriptor.isMulti() != multi)
- continue;
-
int currentPriority = -1;
- for (ApplicableTester tester : descriptor.getTesters()) {
- int testerPriority = tester.isApplicable(feature, modelElement);
+ for (ECPApplicableTester tester : descriptor.getTesters()) {
+ int testerPriority = tester.isApplicable(itemPropertyDescriptor, modelElement);
if (testerPriority > currentPriority)
currentPriority = testerPriority;
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/StaticApplicableTester.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/StaticApplicableTester.java
deleted file mode 100644
index 51bbaceef..000000000
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/impl/StaticApplicableTester.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH 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:
- * Eugen Neufeld - initial API and implementation
- *
- *******************************************************************************/
-package org.eclipse.fx.ecp.ui.impl;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.fx.ecp.ui.Control.ApplicableTester;
-
-public class StaticApplicableTester implements ApplicableTester {
-
- private final int priority;
- private final Class<?> supportedClassType;
- private final Class<? extends EObject> supportedEObject;
- private final String supportedFeature;
-
- public StaticApplicableTester(int priority, Class<?> supportedClassType,
- Class<? extends EObject> supportedEObject, String supportedFeature) {
- this.priority = priority;
- this.supportedClassType = supportedClassType;
- this.supportedEObject = supportedEObject;
- this.supportedFeature = supportedFeature;
- }
-
- public int isApplicable(EStructuralFeature feature, EObject eObject) {
-
- // if the feature is a multiValue and the description is a singlevalue continue
-// if (isSingleValue() == feature.isMany()) {
-// return NOT_APPLICABLE;
-// }
-
- // if we have an attribute
- if (EAttribute.class.isInstance(feature)) {
- Class<?> instanceClass = ((EAttribute) feature).getEAttributeType().getInstanceClass();
- // if the attribute class is an primitive test the primitive types
- if (instanceClass.isPrimitive()) {
- try {
- Class<?> primitive = (Class<?>) getSupportedClassType().getField("TYPE").get(null); //$NON-NLS-1$
- if (!primitive.equals(instanceClass)) {
- return NOT_APPLICABLE;
- }
-
- } catch (IllegalArgumentException e) {
- return NOT_APPLICABLE;
- } catch (SecurityException e) {
- return NOT_APPLICABLE;
- } catch (IllegalAccessException e) {
- return NOT_APPLICABLE;
- } catch (NoSuchFieldException e) {
- return NOT_APPLICABLE;
- }
- }
- // otherwise test the classes itself
- else if (!getSupportedClassType().isAssignableFrom(instanceClass)) {
- return NOT_APPLICABLE;
- }
- }
- // if we have an reference the the classes
- else if (EReference.class.isInstance(feature)) {
- Class<?> instanceClass = feature.getEType().getInstanceClass();
- if (!getSupportedClassType().isAssignableFrom(instanceClass)) {
- return NOT_APPLICABLE;
- }
- }
- // if the supported eobject is assignable from the current eobject and the supported feature is either
- // null or equals the current one
- if (getSupportedEObject().isInstance(eObject)
- && (getSupportedFeature() == null || eObject.eClass().getEStructuralFeature(getSupportedFeature()).equals(feature))) {
- return getPriority();
- }
-
- return NOT_APPLICABLE;
- }
-
- /**
- * The static priority of the corresponding control.
- *
- * @return the priority
- */
- public int getPriority() {
- return priority;
- }
-
- /**
- * The eobejct which is supported by the corresponding control.
- *
- * @return the class of the supported eobejct
- */
- public Class<? extends EObject> getSupportedEObject() {
- return supportedEObject;
- }
-
- /**
- * The name of the feature the corresponding control supports.
- *
- * @return the name of the supported feature
- */
- public String getSupportedFeature() {
- return supportedFeature;
- }
-
- /**
- * The class of the type the corresponding control supports.
- *
- * @return the class of the supported type
- */
- public Class<?> getSupportedClassType() {
- return supportedClassType;
- }
-
-}
diff --git a/bundles/runtime/org.eclipse.fx.emf.databinding/src/org/eclipse/fx/emf/databinding/edit/EMFEditFXProperties.java b/bundles/runtime/org.eclipse.fx.emf.databinding/src/org/eclipse/fx/emf/databinding/edit/EMFEditFXProperties.java
index 5c7c230da..52163a619 100755
--- a/bundles/runtime/org.eclipse.fx.emf.databinding/src/org/eclipse/fx/emf/databinding/edit/EMFEditFXProperties.java
+++ b/bundles/runtime/org.eclipse.fx.emf.databinding/src/org/eclipse/fx/emf/databinding/edit/EMFEditFXProperties.java
@@ -1,181 +1,112 @@
-/**
- * Copyright (c) 2012 TESIS DYNAware GmbH 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:
- * Torsten Sommer <torsten.sommer@tesis.de> - initial API and implementation
- */
-package org.eclipse.fx.emf.databinding.edit;
-
-import javafx.beans.property.ObjectPropertyBase;
-import javafx.beans.property.Property;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-
-public class EMFEditFXProperties {
-
- /**
- * Returns a {@link Property} for the given {@link EStructuralFeature}
- *
- * @param editingDomain the editing domain
- * @param feature the feature instance the property is created for
- * @return a value property for the given {@link EStructuralFeature}
- */
- public static <T> Property<T> value(EditingDomain editingDomain, EObject eObject, EStructuralFeature feature) {
- return new EObjectProperty<>(editingDomain, eObject, feature);
- }
-
- public static <T> EListItemProperty<T> listItem(EditingDomain editingDomain, EObject eObject, EStructuralFeature feature, int index) {
- return new EListItemProperty<>(editingDomain, eObject, feature, index);
- }
-
- private static class EObjectProperty<T> extends ObjectPropertyBase<T> {
-
- final private EObject eObject;
- final private EStructuralFeature feature;
- final private EditingDomain editingDomain;
-
- private EObjectProperty(EditingDomain editingDomain, EObject eObject, EStructuralFeature feature) {
- super();
- this.eObject = eObject;
- this.feature = feature;
- this.editingDomain = editingDomain;
-
- eObject.eAdapters().add(new AdapterImpl() {
- @Override
- public void notifyChanged(Notification msg) {
- fireValueChangedEvent();
- }
- });
- }
-
- @Override
- public void setValue(T newValue) {
- Command command = SetCommand.create(editingDomain, eObject, feature, newValue);
- if (command.canExecute())
- editingDomain.getCommandStack().execute(command);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public T getValue() {
- return (T) eObject.eGet(feature);
- }
-
- @Override
- public Object getBean() {
- return eObject;
- }
-
- @Override
- public String getName() {
- return feature.getName();
- }
-
- }
-
- public static class EListItemProperty<T> extends ObjectPropertyBase<T> {
-
- final private EObject eObject;
- final private EStructuralFeature feature;
- final private EditingDomain editingDomain;
- final private EList<T> eList;
- private int index;
-
- @SuppressWarnings("unchecked")
- private EListItemProperty(EditingDomain editingDomain, final EObject eObject, final EStructuralFeature feature, int initialIndex) {
- super();
- this.eObject = eObject;
- this.feature = feature;
- this.editingDomain = editingDomain;
- this.eList = (EList<T>) eObject.eGet(feature);
- this.index = initialIndex;
-
- eObject.eAdapters().add(new AdapterImpl() {
- @Override
- public void notifyChanged(Notification msg) {
- if (msg.getFeature() == feature) {
-
- switch (msg.getEventType()) {
- case Notification.ADD:
- break;
- case Notification.MOVE: {
- int oldIndex = ((Integer) msg.getOldValue()).intValue();
- int position = msg.getPosition();
- if (oldIndex == index)
- index = position;
- else if (oldIndex > index && position <= index)
- index++;
- else if (oldIndex < index && position >= index)
- index--;
- break;
- }
- case Notification.REMOVE:
- int position = msg.getPosition();
- if (index == position) {
- index = -1;
- eObject.eAdapters().remove(this);
- } else if (index > position) {
- index--;
- }
- break;
- case Notification.ADD_MANY:
- throw new RuntimeException("ADD_MANY is currently not supported");
- case Notification.REMOVE_MANY:
- throw new RuntimeException("REMOVE_MANY is currently not supported");
- }
-
- fireValueChangedEvent();
-
- }
-
- }
- });
- }
-
- @Override
- public void setValue(T newValue) {
- Command command = SetCommand.create(editingDomain, eObject, feature, newValue, index);
- if (command.canExecute())
- editingDomain.getCommandStack().execute(command);
- }
-
- @Override
- public T getValue() {
- if (index >= 0 && index <= eList.size())
- return (T) eList.get(index);
- else
- return null;
- }
-
- @Override
- public Object getBean() {
- return eObject;
- }
-
- @Override
- public String getName() {
- return feature.getName();
- }
-
- public int getIndex() {
- return index;
- }
-
- public void setIndex(int index) {
- this.index = index;
- }
-
- }
-
-}
+/**
+ * Copyright (c) 2012 TESIS DYNAware GmbH 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:
+ * Torsten Sommer <torsten.sommer@tesis.de> - initial API and implementation
+ */
+package org.eclipse.fx.emf.databinding.edit;
+
+import javafx.beans.property.ListPropertyBase;
+import javafx.beans.property.ObjectPropertyBase;
+import javafx.beans.property.Property;
+import javafx.collections.ObservableList;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+public class EMFEditFXProperties {
+
+ /**
+ * Returns a {@link Property} for the given {@link EStructuralFeature}
+ *
+ * @param editingDomain the editing domain
+ * @param feature the feature instance the property is created for
+ * @return a value property for the given {@link EStructuralFeature}
+ */
+ public static <T> Property<T> value(EditingDomain editingDomain, EObject eObject, EStructuralFeature feature) {
+ return new EObjectProperty<>(editingDomain, eObject, feature);
+ }
+
+ public static <T> ObservableList<T> list(EditingDomain editingDomain, Notifier owner, EList<T> list) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ public static <T> ObservableList<T> list(EditingDomain editingDomain, EObject eObject, EStructuralFeature feature) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ static class EObjectObservableList<T> extends ListPropertyBase<T> {
+
+ EObject eObject;
+ EStructuralFeature feature;
+ EditingDomain editingDomain;
+
+ public Object getBean() {
+ return eObject;
+ }
+
+ public String getName() {
+ return feature.getName();
+ }
+
+ }
+
+ static class EObjectProperty<T> extends ObjectPropertyBase<T> {
+
+ EObject eObject;
+ EStructuralFeature feature;
+ EditingDomain editingDomain;
+
+ public EObjectProperty(EditingDomain editingDomain, EObject eObject, EStructuralFeature feature) {
+ super();
+ this.eObject = eObject;
+ this.feature = feature;
+ this.editingDomain = editingDomain;
+
+ eObject.eAdapters().add(new AdapterImpl() {
+ @Override
+ public void notifyChanged(Notification msg) {
+ fireValueChangedEvent();
+ }
+ });
+ }
+
+ public void setEObject(EObject eObject) {
+ this.eObject = eObject;
+ }
+
+ @Override
+ public void setValue(T newValue) {
+ Command command = SetCommand.create(editingDomain, eObject, feature, newValue);
+ if (command.canExecute())
+ editingDomain.getCommandStack().execute(command);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public T getValue() {
+ return (T) eObject.eGet(feature);
+ }
+
+ public Object getBean() {
+ return eObject;
+ }
+
+ public String getName() {
+ return feature.getName();
+ }
+
+ }
+
+}
diff --git a/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart.java b/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart.java
index 38dd69df6..39c494a49 100644
--- a/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart.java
+++ b/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart.java
@@ -15,7 +15,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javafx.beans.property.Property;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.VPos;
@@ -44,7 +43,6 @@ import org.eclipse.fx.ecp.ui.Control;
import org.eclipse.fx.ecp.ui.ModelElementEditor;
import org.eclipse.fx.ecp.ui.Control.Factory;
import org.eclipse.fx.ecp.ui.Control.Factory.Registry;
-import org.eclipse.fx.emf.databinding.edit.EMFEditFXProperties;
@SuppressWarnings("restriction")
@@ -124,13 +122,12 @@ public class ModelEditorPart implements ModelElementEditor {
GridPane.setValignment(label, VPos.TOP);
gridPane.add(label, 0, i);
- EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
+ Factory factory = registry.getFactory(Node.class, propertyDescriptor, modelElement);
- Factory factory = registry.getFactory(feature, modelElement, feature.isMany());
+ EStructuralFeature feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
if (factory != null) {
- Property<?> property = EMFEditFXProperties.value(modelElementContext.getEditingDomain(), modelElementContext.getModelElement(), feature);
- Control control = factory.createControl(property, feature, modelElementContext);
+ Control control = factory.createControl(propertyDescriptor, modelElementContext);
Node node = (Node) control;
gridPane.add(node, 1, i);
GridPane.setHgrow(node, Priority.ALWAYS);

Back to the top