Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorsten Sommer2013-06-16 22:53:01 +0000
committerTorsten Sommer2013-06-16 22:53:01 +0000
commit8716eb3da97cbc53151267bd16cd0fa6bbe494f7 (patch)
tree7001ad5308da64851f8919debb8d4704a1c64cf7
parent9513b679299361d591cecc9a4a7abbb8b97e670e (diff)
downloadorg.eclipse.efxclipse-8716eb3da97cbc53151267bd16cd0fa6bbe494f7.tar.gz
org.eclipse.efxclipse-8716eb3da97cbc53151267bd16cd0fa6bbe494f7.tar.xz
org.eclipse.efxclipse-8716eb3da97cbc53151267bd16cd0fa6bbe494f7.zip
BreadcrumbBar improved. IntegerControl added.
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml15
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java19
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.css27
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.java2
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbItem.java204
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/DummyControl.java2
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css20
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/IntegerControl.java187
-rw-r--r--bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/dummy.css35
-rw-r--r--demos/org.eclipse.fx.ecp.app/css/default.css2
-rw-r--r--demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ECPUtil.java6
-rw-r--r--demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart2.java84
12 files changed, 545 insertions, 58 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml b/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml
index e19f16feb..44eac709e 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/plugin.xml
@@ -69,11 +69,6 @@
<staticTest
priority="1"
singleValue="true"
- supportedClassType="java.lang.Integer">
- </staticTest>
- <staticTest
- priority="1"
- singleValue="true"
supportedClassType="java.lang.Long">
</staticTest>
<staticTest
@@ -183,6 +178,16 @@
supportedClassType="org.eclipse.emf.ecore.EObject">
</staticTest>
</factory>
+ <factory
+ class="org.eclipse.fx.ecp.ui.controls.IntegerControl$Factory"
+ id="org.eclipse.fx.ecp.ui.controls.integerField"
+ showLabel="true">
+ <staticTest
+ priority="1"
+ singleValue="true"
+ supportedClassType="java.lang.Integer">
+ </staticTest>
+ </factory>
</extension>
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java
index 53ad239d9..767243ded 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/ECPUtil.java
@@ -2,9 +2,12 @@ package org.eclipse.fx.ecp.ui;
import java.net.URL;
+import javafx.scene.Group;
import javafx.scene.Node;
+import javafx.scene.control.Labeled;
import javafx.scene.control.TreeItem;
import javafx.scene.image.ImageView;
+import javafx.scene.layout.StackPane;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EClass;
@@ -22,15 +25,15 @@ import org.osgi.framework.Bundle;
public class ECPUtil {
public static final ComposedAdapterFactory DEFAULT_ADAPTER_FACTORY;
- private static final String PACKAGE_IMAGE_URL;
+ private static final String PACKAGE_IMAGE_URL = null;
static {
DEFAULT_ADAPTER_FACTORY = new ComposedAdapterFactory();
DEFAULT_ADAPTER_FACTORY.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
DEFAULT_ADAPTER_FACTORY.addAdapterFactory(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
- Bundle bundle = Platform.getBundle("org.eclipse.fx.ecp.app");
- URL entry = bundle.getEntry("icons/EPackage.gif");
- PACKAGE_IMAGE_URL = entry.toExternalForm();
+// Bundle bundle = Platform.getBundle("org.eclipse.fx.ecp.app");
+// URL entry = bundle.getEntry("icons/EPackage.gif");
+// PACKAGE_IMAGE_URL = entry.toExternalForm();
}
public static TreeItem<ENamedElement> getConcreteClasses() {
@@ -90,7 +93,7 @@ public class ECPUtil {
public static Node getGraphic(Object object) {
IItemLabelProvider labelProvider = (IItemLabelProvider) DEFAULT_ADAPTER_FACTORY.adapt(object, IItemLabelProvider.class);
-
+
if (labelProvider != null) {
Object image = labelProvider.getImage(object);
return AdapterFactoryCellFactory.graphicFromObject(image);
@@ -99,4 +102,10 @@ public class ECPUtil {
return null;
}
+ public static void addMark(Labeled backButton, String styleClass) {
+ StackPane mark = new StackPane();
+ mark.getStyleClass().add(styleClass);
+ backButton.setGraphic(new Group(mark));
+ }
+
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.css b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.css
index 88b3072a9..b67b188bc 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.css
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.css
@@ -3,11 +3,38 @@
-fx-background-insets: 0, 1, 2;
}
+.polygon {
+ -fx-fill: blue;
+ -fx-background-color: green;
+}
+
.breadcrumb-item {
/*-fx-base: -fx-default-button;*/
+ /*
+ -fx-background-color: -fx-outer-border, -fx-inner-border, -fx-body-color;
+ -fx-background-insets: 0, 1, 2;
+ */
-fx-text-fill: -fx-text-base-color;
}
+.breadcrumbitem-text {
+ /*-fx-background-color: rgba(255,0,0,0.5); /*-fx-default-button;*/
+ -fx-padding: 7 10 7 10;
+ /*-fx-pref-height: 40;*/
+}
+
+.last, .only {
+ -fx-base: -fx-default-button;
+}
+
+.breadcrumb-item:hover {
+ -fx-color: -fx-hover-base;
+}
+
+.breadcrumb-item:pressed {
+ -fx-color: -fx-pressed-base;
+}
+
.breadcrumb-item .outer-border {
-fx-fill: -fx-outer-border;
}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.java
index 2f644053f..4acd041bc 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbBar.java
@@ -25,7 +25,7 @@ public class BreadcrumbBar extends Control {
getStyleClass().add("breadcrumb-bar");
hBox = new HBox();
getChildren().add(hBox);
- hBox.setSpacing(-9);
+ hBox.setSpacing(-7);
}
public void setModelElement(EObject modelElement) {
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbItem.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbItem.java
index 11ba57fd9..3b7de1878 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbItem.java
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/BreadcrumbItem.java
@@ -1,11 +1,15 @@
package org.eclipse.fx.ecp.ui.controls;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.SkinBase;
-import javafx.scene.layout.HBox;
+import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
+import javafx.scene.shape.Polygon;
import javafx.scene.shape.SVGPath;
import org.eclipse.emf.common.notify.Notification;
@@ -18,31 +22,140 @@ public class BreadcrumbItem extends Control {
public enum Position {
First, Middle, Last, Only
}
-
+
+ private Label label;
+ private Position position;
+
public class Skin extends SkinBase<BreadcrumbItem> {
- private Label label;
+ private Polygon outerBorder;
+ private Polygon innerBorder;
+ private Polygon body;
- public Skin(BreadcrumbItem control, Position position) {
+ public Skin(BreadcrumbItem control, final Position position) {
super(control);
+ BreadcrumbItem.this.position = position;
+
+ // HBox hBox = new HBox();
+ // getChildren().add(hBox);
+ // hBox.setAlignment(Pos.CENTER);
- HBox hBox = new HBox();
- getChildren().add(hBox);
- hBox.setAlignment(Pos.CENTER);
-
- hBox.getChildren().add(position == Position.First || position == Position.Only ? new LeftEndCap() : new LeftCap());
+ // if (position == Position.First || position == Position.Only)
+ // hBox.getChildren().add(new LeftEndCap());
+ // else if (position == Position.Middle || position == Position.Last)
+ // hBox.getChildren().add(new LeftCap());
StackPane stackPane = new StackPane();
- hBox.getChildren().add(stackPane);
- stackPane.getStyleClass().add("body");
+ getChildren().add(stackPane);
+ // stackPane.getStyleClass().add("body");
stackPane.setAlignment(Pos.CENTER);
+ outerBorder = new Polygon();
+ stackPane.getChildren().add(outerBorder);
+ outerBorder.getStyleClass().add("outer-border");
+ outerBorder.setOnMouseClicked(new EventHandler<MouseEvent>() {
+
+ @Override
+ public void handle(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+ System.out.println(outerBorder);
+ }
+ });
+
+ innerBorder = new Polygon();
+ stackPane.getChildren().add(innerBorder);
+ innerBorder.getStyleClass().add("inner-border");
+ innerBorder.setMouseTransparent(true);
+
+ body = new Polygon();
+ stackPane.getChildren().add(body);
+ body.getStyleClass().add("body");
+ body.setMouseTransparent(true);
+
label = new Label();
stackPane.getChildren().add(label);
label.getStyleClass().add("breadcrumbitem-text");
+ label.setMouseTransparent(true);
- if(position == Position.First || position == Position.Middle)
- hBox.getChildren().add(new RightCap());
+ label.widthProperty().addListener(new ChangeListener<Number>() {
+
+ @Override
+ public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
+ System.out.println(arg1 + " -> " + arg2);
+ updateBackground();
+
+// final double w = arg2.doubleValue();
+// final double h = label.getBoundsInParent().getHeight();
+//
+// if (position == Position.First) {
+// outerBorder.getPoints().setAll(-5.0, 0.0, w, 0.0, w + 5, h / 2, w, h, -5.0, h);
+// outerBorder.setLayoutX(0);
+// outerBorder.setLayoutY(0);
+//
+// innerBorder.getPoints().setAll(-5.0, 1.0, w - 1, 1.0, w + 4, (h - 2) / 2, w - 1, h - 1, -5.0, h - 1);
+// innerBorder.setLayoutX(0);
+// innerBorder.setLayoutY(0);
+//
+// body.getPoints().setAll(-3.0, 2.0, w - 2, 2.0, w + 3, h / 2, w - 2, h - 2, -3.0, h - 2);
+// body.setLayoutX(0);
+// body.setLayoutY(0);
+// } else if (position == Position.Middle) {
+// outerBorder.getPoints().setAll(-5.0, 0.0, w, 0.0, w + 5, h / 2, w, h, -5.0, h, 0.0, h / 2);
+// outerBorder.setLayoutX(0);
+// outerBorder.setLayoutY(0);
+//
+// innerBorder.getPoints().setAll(-5.0, 1.0, w - 1, 1.0, w + 4, (h - 2) / 2, w - 1, h - 1, -5.0, h - 1, 0.0, h / 2);
+// innerBorder.setLayoutX(0);
+// innerBorder.setLayoutY(0);
+//
+// body.getPoints().setAll(-3.0, 2.0, w - 2, 2.0, w + 3, h / 2, w - 2, h - 2, -3.0, h - 2, 2.0, h / 2);
+// body.setLayoutX(0);
+// body.setLayoutY(0);
+// } else if (position == Position.Last) {
+// outerBorder.getPoints().setAll(-5.0, 0.0, w, 0.0, w, h, -5.0, h, 0.0, h / 2);
+// outerBorder.setLayoutX(0);
+// outerBorder.setLayoutY(0);
+//
+// innerBorder.getPoints().setAll(-5.0, 1.0, w - 2, 1.0, w - 2, h - 1, -5.0, h - 1, 0.0, h / 2);
+// innerBorder.setLayoutX(0);
+// innerBorder.setLayoutY(0);
+//
+// body.getPoints().setAll(-3.0, 2.0, w - 3, 2.0, w - 3, h - 2, -3.0, h - 2, 2.0, h / 2);
+// body.setLayoutX(0);
+// body.setLayoutY(0);
+// } else if (position == Position.Only) {
+// outerBorder.getPoints().setAll(0.0, 0.0, w, 0.0, w, h, 0.0, h);
+// outerBorder.setLayoutX(0);
+// outerBorder.setLayoutY(0);
+//
+// innerBorder.getPoints().setAll(1.0, 1.0, w - 1, 1.0, w - 1, h - 1, 1.0, h - 1);
+// innerBorder.setLayoutX(0);
+// innerBorder.setLayoutY(0);
+//
+// body.getPoints().setAll(2.0, 2.0, w - 2, 2.0, w - 2, h - 2, 2.0, h - 2);
+// body.setLayoutX(0);
+// body.setLayoutY(0);
+// }
+ }
+
+ });
+
+ label.heightProperty().addListener(new ChangeListener<Number>() {
+
+ @Override
+ public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
+ System.out.println(arg1 + " -> " + arg2);
+ updateBackground();
+ }
+
+ });
+
+
+
+ // if (position == Position.First || position == Position.Middle)
+ // hBox.getChildren().add(new RightCap());
+ // else if (position == Position.Last || position == Position.Only)
+ // hBox.getChildren().add(new RightEndCap());
eObject.eAdapters().add(new AdapterImpl() {
@@ -60,6 +173,62 @@ public class BreadcrumbItem extends Control {
label.setText(ECPUtil.getText(eObject));
label.setGraphic(ECPUtil.getGraphic(eObject));
}
+
+ private void updateBackground() {
+ final double w = label.getWidth();
+ final double h = label.getHeight();
+ final double s = 7;//h / 2 - 5;
+
+ if (position == Position.First) {
+ outerBorder.getPoints().setAll(0.0, 0.0, w-s, 0.0, w, h/2, w-s, h, 0.0, h);
+ outerBorder.setLayoutX(0);
+ outerBorder.setLayoutY(0);
+
+ innerBorder.getPoints().setAll(1.0, 1.0, w-s, 1.0, w, h/2, w-s, h-1, 1.0, h-1);
+ innerBorder.setLayoutX(0);
+ innerBorder.setLayoutY(0);
+
+ body.getPoints().setAll(2.0, 2.0, w-s-1, 2.0, w-2, h/2, w-s-1, h-2, 2.0, h-2);
+ body.setLayoutX(0);
+ body.setLayoutY(0);
+ } else if (position == Position.Middle) {
+ outerBorder.getPoints().setAll(0.0,0.0, w-s,0.0, w,h/2, w-s,h, 0.0,h, 5.0,h/2);
+ outerBorder.setLayoutX(0);
+ outerBorder.setLayoutY(0);
+
+ innerBorder.getPoints().setAll(1.0,1.0, w-s,1.0, w, h/2, w-s,h-1, 1.0,h-1, 6.0,h/2);
+ innerBorder.setLayoutX(0);
+ innerBorder.setLayoutY(0);
+
+ body.getPoints().setAll(2.0,2.0, w-s-1,2.0, w-1,h/2, w-s-1, h-2, 2.0, h-2, 7.0,h/2);
+ body.setLayoutX(0);
+ body.setLayoutY(0);
+ } else if (position == Position.Last) {
+ outerBorder.getPoints().setAll(0.0, 0.0, w, 0.0, w, h, 0.0, h, s, h / 2);
+ outerBorder.setLayoutX(0);
+ outerBorder.setLayoutY(0);
+
+ innerBorder.getPoints().setAll(1.0, 1.0, w - 1, 1.0, w - 1, h - 1, 1.0, h - 1, s+1, h / 2);
+ innerBorder.setLayoutX(0);
+ innerBorder.setLayoutY(0);
+
+ body.getPoints().setAll(2.0, 2.0, w - 2, 2.0, w - 2, h - 2, 2.0, h - 2, s+2, h / 2);
+ body.setLayoutX(0);
+ body.setLayoutY(0);
+ } else if (position == Position.Only) {
+ outerBorder.getPoints().setAll(0.0, 0.0, w, 0.0, w, h, 0.0, h);
+ outerBorder.setLayoutX(0);
+ outerBorder.setLayoutY(0);
+
+ innerBorder.getPoints().setAll(1.0, 1.0, w - 1, 1.0, w - 1, h - 1, 1.0, h - 1);
+ innerBorder.setLayoutX(0);
+ innerBorder.setLayoutY(0);
+
+ body.getPoints().setAll(2.0, 2.0, w - 2, 2.0, w - 2, h - 2, 2.0, h - 2);
+ body.setLayoutX(0);
+ body.setLayoutY(0);
+ }
+ }
}
@@ -68,14 +237,15 @@ public class BreadcrumbItem extends Control {
public BreadcrumbItem(EObject eObject, Position position) {
this.eObject = eObject;
setSkin(new Skin(this, position));
- getStyleClass().add("breadcrumb-item");
+ getStyleClass().addAll("breadcrumb-item", position.toString().toLowerCase());
+
}
@Override
protected String getUserAgentStylesheet() {
return getClass().getResource("BreadcrumbBar.css").toExternalForm();
}
-
+
static class LeftEndCap extends StackPane {
public LeftEndCap() {
@@ -148,7 +318,7 @@ public class BreadcrumbItem extends Control {
}
}
-
+
static class RightEndCap extends StackPane {
public RightEndCap() {
@@ -171,5 +341,5 @@ public class BreadcrumbItem extends Control {
}
}
-
+
}
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 e298357b0..ef82ec53b 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
@@ -61,7 +61,7 @@ public class DummyControl extends Control implements ECPControl {
@Override
protected String getUserAgentStylesheet() {
- return DummyControl.class.getResource("dummy.css").toExternalForm();
+ return getClass().getResource("dummy.css").toExternalForm();
}
public static class Factory implements ECPControl.Factory {
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css
index c1ff0130a..d305521df 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/ECPControls.css
@@ -28,7 +28,12 @@
-fx-pref-width: 6;
}
-.remove-button .minus {
+.increase-button, .decrease-button {
+ -fx-pref-width: 30;
+}
+
+.remove-button .minus,
+.decrease-button .minus {
-fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
-fx-background-insets: 0 0 -1 0, 0;
-fx-shape: "M -4 1 v -1 h 4 v 1 z";
@@ -37,6 +42,14 @@
-fx-pref-width: 8;
}
+.increase-button .plus {
+ -fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
+ -fx-background-insets: 0 0 -1 0, 0;
+ -fx-shape: "M -4 1 v -1 h 4 v -4 h 2 v 4 h 4 v 2 h -4 v 4 h -2 v -4 h -4 z";
+ -fx-pref-height: 10;
+ -fx-pref-width: 10;
+}
+
.unset-reference-button .cross {
-fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
-fx-background-insets: 0 0 -1 0, 0;
@@ -54,6 +67,11 @@
-fx-max-width: 1000;
}
+.text-field.center-pill {
+ -fx-background-radius: 0;
+ -fx-background-insets: 0, 1 1 1 0, 2 2 2 1;
+}
+
.model-element-form .control-label {
-fx-alignment: top-left;
-fx-min-height: 20.0;
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/IntegerControl.java b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/IntegerControl.java
new file mode 100644
index 000000000..e696c98a3
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/IntegerControl.java
@@ -0,0 +1,187 @@
+package org.eclipse.fx.ecp.ui.controls;
+
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.geometry.Pos;
+import javafx.scene.control.Button;
+import javafx.scene.control.Control;
+import javafx.scene.control.SkinBase;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.HBox;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+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.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
+import org.eclipse.fx.ecp.ui.ECPControl;
+import org.eclipse.fx.ecp.ui.ECPUtil;
+
+public class IntegerControl extends Control implements ECPControl {
+
+ protected final EObject modelElement;
+ protected final EStructuralFeature feature;
+ private EditingDomain editingDomain;
+ private TextField textField;
+
+ private final class Skin extends SkinBase<IntegerControl> {
+
+ private Adapter modelElementAdapter;
+
+ private Skin(IntegerControl control) {
+ super(control);
+
+ HBox hBox = new HBox();
+ getChildren().add(hBox);
+ hBox.setFillHeight(true);
+
+ Button decreaseButton = new Button();
+ hBox.getChildren().add(decreaseButton);
+ decreaseButton.getStyleClass().add("decrease-button");
+ decreaseButton.getStyleClass().add("left-pill");
+ ECPUtil.addMark(decreaseButton, "minus");
+ decreaseButton.setOnAction(new EventHandler<ActionEvent>() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ Integer value = (Integer) modelElement.eGet(feature);
+ Command command = SetCommand.create(editingDomain, modelElement, feature, --value);
+ if (command.canExecute())
+ editingDomain.getCommandStack().execute(command);
+ }
+
+ });
+
+ textField = new TextField() {
+
+ @Override
+ public void replaceText(int start, int end, String text) {
+ if(start == 0 && text.matches("\\-?[0-9]*"))
+ super.replaceText(start, end, text);
+
+
+ if (text.matches("[0-9]*"))
+ super.replaceText(start, end, text);
+ }
+
+ @Override
+ public void replaceSelection(String text) {
+ getSelectedText();
+ getCaretPosition();
+ if (text.matches("[0-9]*"))
+ super.replaceSelection(text);
+ }
+
+ };
+ hBox.getChildren().add(textField);
+// textField.setAlignment(Pos.BASELINE_RIGHT);
+ textField.getStyleClass().add("center-pill");
+
+ textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
+
+ @Override
+ public void changed(ObservableValue<? extends Boolean> observableValue, Boolean oldFocused, Boolean newFocused) {
+ if (!newFocused) {
+ int oldValue = (Integer) modelElement.eGet(feature);
+ int newValue = 0;
+ try {
+ newValue = Integer.parseInt(textField.getText());
+ } catch (NumberFormatException e) {
+ // TODO maybe log this?
+ }
+
+ // only commit if the value has changed
+ if (oldValue != newValue) {
+ Command command = SetCommand.create(editingDomain, modelElement, feature, newValue);
+ if (command.canExecute())
+ editingDomain.getCommandStack().execute(command);
+ }
+ }
+ }
+
+ });
+
+ Button increaseButton = new Button();
+ hBox.getChildren().add(increaseButton);
+ increaseButton.getStyleClass().add("increase-button");
+ increaseButton.getStyleClass().add("right-pill");
+ ECPUtil.addMark(increaseButton, "plus");
+ increaseButton.setOnAction(new EventHandler<ActionEvent>() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ Integer value = (Integer) modelElement.eGet(feature);
+ Command command = SetCommand.create(editingDomain, modelElement, feature, ++value);
+ if (command.canExecute())
+ editingDomain.getCommandStack().execute(command);
+ }
+
+ });
+
+ modelElementAdapter = new AdapterImpl() {
+
+ @Override
+ public void notifyChanged(Notification msg) {
+ if (msg.getFeature() == feature)
+ update();
+ }
+
+ };
+
+ modelElement.eAdapters().add(modelElementAdapter);
+
+ update();
+ }
+
+ }
+
+ private void update() {
+ Integer value = (Integer) modelElement.eGet(feature);
+ textField.setText(value.toString());
+ }
+
+ public IntegerControl(IItemPropertyDescriptor propertyDescriptor, ECPControlContext context) {
+ modelElement = context.getModelElement();
+ editingDomain = context.getEditingDomain();
+ feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
+ setSkin(new Skin(this));
+ }
+
+ @Override
+ protected String getUserAgentStylesheet() {
+ return getClass().getResource("ECPControls.css").toExternalForm();
+ }
+
+ @Override
+ public void handleValidation(Diagnostic diagnostic) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void resetValidation() {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+ }
+
+ public static class Factory implements ECPControl.Factory {
+
+ @Override
+ public ECPControl createControl(IItemPropertyDescriptor itemPropertyDescriptor, ECPControlContext context) {
+ return new IntegerControl(itemPropertyDescriptor, context);
+ }
+
+ }
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/dummy.css b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/dummy.css
index 8df005934..5fab67b95 100644
--- a/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/dummy.css
+++ b/bundles/runtime/org.eclipse.fx.ecp.ui/src/org/eclipse/fx/ecp/ui/controls/dummy.css
@@ -52,4 +52,37 @@
.breadcrumbbar-home-icon {
-fx-background-image: url("home.png");
-} \ No newline at end of file
+}
+
+.text-field.left-pill {
+ -fx-background-radius: 3 0 0 3, 2 0 0 2;
+ -fx-max-width: 1000;
+}
+
+.top-right-pill {
+ -fx-background-color: -fx-outer-border,
+ linear-gradient(to bottom, derive(-fx-color,75%), derive(-fx-color,38%)),
+ linear-gradient(to bottom, derive(-fx-color,10%) ,derive(-fx-color,2%));
+ -fx-background-insets: 0, 1 1 0 0, 2 2 1 1;
+ -fx-background-radius: 0 5 0 0 0, 0 4 0 0 0, 0 3 0 0;
+ -fx-min-height: 3;
+ -fx-pref-height: 13;
+}
+
+.bottom-right-pill {
+ -fx-background-color: -fx-outer-border,
+ linear-gradient(to bottom, derive(-fx-color,38%), derive(-fx-color,2%)),
+ linear-gradient(to bottom, derive(-fx-color,2%) ,derive(-fx-color,-6%));
+ -fx-background-insets: 0 0 0 0, 1 1 1 0, 2 2 2 1;
+ -fx-background-radius: 0 0 5 0, 0 0 4 0, 0 0 3 0;
+ -fx-min-height: 1;
+ -fx-pref-height: 14;
+}
+
+
+
+.my-button {
+ /*-fx-background-color: red, green, blue;*/
+ -fx-background-insets: 0, 1, 2;
+ -fx-background-radius: 5, 4, 3;
+}
diff --git a/demos/org.eclipse.fx.ecp.app/css/default.css b/demos/org.eclipse.fx.ecp.app/css/default.css
index 391cc6a4c..8a632eaf3 100644
--- a/demos/org.eclipse.fx.ecp.app/css/default.css
+++ b/demos/org.eclipse.fx.ecp.app/css/default.css
@@ -28,7 +28,7 @@
-fx-background-radius: 0, 0, 0;
-fx-max-height: 100;
-fx-pref-width: 30;
- -fx-pref-height: 30;
+ -fx-pref-height: 10;
}
.back-button .arrow {
diff --git a/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ECPUtil.java b/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ECPUtil.java
index 390c6157a..7fc299f74 100644
--- a/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ECPUtil.java
+++ b/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ECPUtil.java
@@ -115,10 +115,4 @@ public class ECPUtil {
return null;
}
- public static void addMark(Button backButton, String styleClass) {
- StackPane mark = new StackPane();
- mark.getStyleClass().add(styleClass);
- backButton.setGraphic(new Group(mark));
- }
-
}
diff --git a/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart2.java b/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart2.java
index c72dd7c69..8c62f5140 100644
--- a/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart2.java
+++ b/demos/org.eclipse.fx.ecp.app/src/org/eclipse/fx/ecp/ModelEditorPart2.java
@@ -14,16 +14,27 @@ import java.util.Stack;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
+import javafx.geometry.Point2D;
+import javafx.geometry.Pos;
+import javafx.scene.Node;
+import javafx.scene.Scene;
import javafx.scene.control.Button;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
+import javafx.scene.control.TextField;
+import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
+import javafx.scene.layout.StackPane;
+import javafx.stage.Window;
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecp.edit.ECPControlContext;
import org.eclipse.fx.ecp.ui.ModelElementEditor;
import org.eclipse.fx.ecp.ui.controls.BreadcrumbBar;
@@ -33,66 +44,72 @@ public class ModelEditorPart2 implements ModelElementEditor {
private ScrollPane scrollPane;
private ECPControlContext controlContext;
- private BorderPane parent;
private final Stack<ECPControlContext> prevModelElements = new Stack<>();
private final Stack<ECPControlContext> nextModelElements = new Stack<>();
- // private final SimpleListProperty<EObject> prevModelElements = new SimpleListProperty<EObject>(
- // FXCollections.<EObject> observableArrayList());
- // private final SimpleListProperty<EObject> nextModelElements = new SimpleListProperty<EObject>(
- // FXCollections.<EObject> observableArrayList());
private Button forwardButton;
private Button backButton;
private BreadcrumbBar breadcrumbBar;
- // private final ObservableList<EObject> prevModelElements = FXCollections.observableArrayList();
- // private final ObservableList<EObject> nextModelElements = FXCollections.observableArrayList();
-
@Inject
public ModelEditorPart2(BorderPane parent, final MApplication application, MPart part) {
- this.parent = parent;
scrollPane = new ScrollPane();
parent.setCenter(scrollPane);
scrollPane.setFitToWidth(true);
-
+
HBox hBox = new HBox();
-
+
backButton = new Button();
hBox.getChildren().add(backButton);
backButton.getStyleClass().add("back-button");
- ECPUtil.addMark(backButton, "arrow");
+ org.eclipse.fx.ecp.ui.ECPUtil.addMark(backButton, "arrow");
backButton.setOnAction(new EventHandler<ActionEvent>() {
-
+
@Override
public void handle(ActionEvent arg0) {
nextModelElements.push(controlContext);
controlContext = prevModelElements.pop();
updateControls();
}
-
+
});
+ backButton.setOnMousePressed(new EventHandler<MouseEvent>() {
+
+ @Override
+ public void handle(MouseEvent arg0) {
+ show(backButton, prevModelElements);
+ }
+
+ });
+
forwardButton = new Button();
hBox.getChildren().add(forwardButton);
forwardButton.getStyleClass().add("forward-button");
- ECPUtil.addMark(forwardButton, "arrow");
+ org.eclipse.fx.ecp.ui.ECPUtil.addMark(forwardButton, "arrow");
// why is this not working?
// forwardButton.disabledProperty().isEqualTo(nextModelElements.emptyProperty());
forwardButton.setOnAction(new EventHandler<ActionEvent>() {
-
+
@Override
public void handle(ActionEvent arg0) {
prevModelElements.push(controlContext);
controlContext = nextModelElements.pop();
updateControls();
}
-
+
});
-
+
breadcrumbBar = new BreadcrumbBar();
HBox.setHgrow(breadcrumbBar, Priority.ALWAYS);
hBox.getChildren().add(breadcrumbBar);
-
+
parent.setTop(hBox);
+
+ StackPane stackPane = new StackPane();
+ stackPane.getChildren().add(new TextField());
+ stackPane.getChildren().add(new Button("x"));
+ stackPane.setAlignment(Pos.CENTER_RIGHT);
+ parent.setBottom(stackPane);
}
public void setInput(final ECPControlContext modelElementContext) {
@@ -102,7 +119,7 @@ public class ModelEditorPart2 implements ModelElementEditor {
controlContext = modelElementContext;
nextModelElements.clear();
-
+
updateControls();
}
@@ -112,5 +129,32 @@ public class ModelEditorPart2 implements ModelElementEditor {
breadcrumbBar.setModelElement(controlContext.getModelElement());
scrollPane.setContent(new ModelElementForm(controlContext));
}
+
+ public void show(Node node, Stack<ECPControlContext> modelElements) {
+ ContextMenu contextMenu = new ContextMenu();
+
+ for (final ECPControlContext controlContext : modelElements) {
+ EObject modelElement = controlContext.getModelElement();
+ String text = org.eclipse.fx.ecp.ui.ECPUtil.getText(modelElement);
+ Node graphic = org.eclipse.fx.ecp.ui.ECPUtil.getGraphic(modelElement);
+ MenuItem menuItem = new MenuItem(text, graphic);
+ contextMenu.getItems().add(menuItem);
+ menuItem.setOnAction(new EventHandler<ActionEvent>() {
+
+ @Override
+ public void handle(ActionEvent event) {
+ setInput(controlContext);
+ }
+
+ });
+ }
+
+ Point2D position = node.localToScene(0.0, 0.0);
+ Scene scene = node.getScene();
+ Window window = scene.getWindow();
+ double x = position.getX() + scene.getX() + window.getX();
+ double y = position.getY() + scene.getY() + window.getY() + node.getLayoutBounds().getHeight() + 5;
+ contextMenu.show(node, x, y);
+ }
}

Back to the top