summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2014-01-10 09:12:12 (EST)
committerLaurent Wouters2014-01-10 09:12:12 (EST)
commit5dd80bd638a1665602107ab655a28df0bb59df65 (patch)
tree4e59ab9d584bd4c47ac2aee465fb90a0b4746a71
parenteee86fab3ee48287d409e467324a91de9135e492 (diff)
downloadorg.eclipse.papyrus-5dd80bd638a1665602107ab655a28df0bb59df65.zip
org.eclipse.papyrus-5dd80bd638a1665602107ab655a28df0bb59df65.tar.gz
org.eclipse.papyrus-5dd80bd638a1665602107ab655a28df0bb59df65.tar.bz2
Added support for the customization of the line style of connectors through CSS
Change-Id: Iab5be1acde1600ab7e4917372bbdad73b32b2f2b Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java109
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java18
2 files changed, 126 insertions, 1 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java
index 2db9f10..973d934 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java
@@ -11,8 +11,15 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
+import org.eclipse.gmf.runtime.notation.Connector;
+import org.eclipse.gmf.runtime.notation.IntValueStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusConnectionEndEditPolicy;
@@ -22,11 +29,113 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusConnectionEn
*/
public abstract class ConnectionEditPart extends ConnectionNodeEditPart implements IPapyrusEditPart {
+ /**
+ * CSS property for the line style
+ */
+ protected static final String LINE_STYLE = "lineStyle";
+
+ /**
+ * CSS property for the line dashes' length
+ */
+ protected static final String LINE_DASH_LENGTH = "lineDashLength";
+
+ /**
+ * CSS property for the length between line dashes
+ */
+ protected static final String LINE_DASH_GAP = "lineDashGap";
+
public ConnectionEditPart(View view) {
super(view);
}
/**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart#refresh()
+ */
+ @Override
+ public void refresh() {
+ super.refresh();
+ IFigure figure = this.getFigure();
+ Object model = this.getModel();
+ if (figure instanceof PolylineConnectionEx && model instanceof Connector) {
+ Connector connector = (Connector) model;
+ PolylineConnectionEx polyline = (PolylineConnectionEx) figure;
+ String lineStyle = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), LINE_STYLE));
+ int lineDashLength = extract((IntValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), LINE_DASH_LENGTH));
+ int lineDashGap = extract((IntValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), LINE_DASH_GAP));
+ if (lineStyle != null) {
+ setupLineStyle(polyline, lineStyle, connector.getLineWidth(), lineDashLength, lineDashGap);
+ }
+ }
+ }
+
+ /**
+ * Extracts the primitive value from the given style
+ *
+ * @param style
+ * The style
+ * @return The primitive value
+ */
+ private String extract(StringValueStyle style) {
+ if (style == null || style.getStringValue() == null || style.getStringValue().isEmpty()) {
+ return null;
+ }
+ return style.getStringValue();
+ }
+
+ /**
+ * Extracts the primitive value from the given style
+ *
+ * @param style
+ * The style
+ * @return The primitive value
+ */
+ private int extract(IntValueStyle style) {
+ if (style == null) {
+ return 0;
+ }
+ return style.getIntValue();
+ }
+
+ /**
+ * Setups the line style of the polyline according to the given CSS style
+ *
+ * @param polyline
+ * The shape to setup
+ * @param style
+ * The CSS style
+ * @param originalWidth
+ * Original width of the connector
+ * @param lineDashLength
+ * Length of the dashes
+ * @param lineDashGap
+ * Length of the gap between dashes
+ */
+ private void setupLineStyle(PolylineConnectionEx polyline, String style, int originalWidth, int lineDashLength, int lineDashGap) {
+ if ("none".equals(style)) {
+ polyline.setLineStyle(Graphics.LINE_SOLID);
+ polyline.setLineWidth(0);
+ polyline.setVisible(false);
+ } else if ("hidden".equals(style)) {
+ polyline.setLineStyle(Graphics.LINE_SOLID);
+ polyline.setLineWidth(0);
+ polyline.setVisible(false);
+ } else if ("dotted".equals(style)) {
+ polyline.setLineStyle(Graphics.LINE_DOT);
+ polyline.setLineWidth(originalWidth);
+ } else if ("dashed".equals(style)) {
+ polyline.setLineStyle(Graphics.LINE_DASH);
+ polyline.setLineWidth(originalWidth);
+ polyline.setLineDash(new int[] { lineDashLength, lineDashGap });
+ } else if ("solid".equals(style)) {
+ polyline.setLineStyle(Graphics.LINE_SOLID);
+ polyline.setLineWidth(originalWidth);
+ } else if ("double".equals(style)) {
+ polyline.setLineWidth(originalWidth * 2);
+ }
+ }
+
+
+ /**
*
* @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart#createDefaultEditPolicies()
*
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
index 5b26496..7482681 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
@@ -46,11 +46,16 @@ import org.eclipse.ui.IEditorPart;
public abstract class PapyrusEdgeFigure extends PolylineConnectionEx {
/**
- * Diameter to use for the bendpoitns
+ * Diameter to use for the bendpoints
*/
private int bendpointDiameter;
/**
+ * Data of the dash style
+ */
+ private int[] lineDashData;
+
+ /**
*
* Constructor.
*
@@ -58,8 +63,15 @@ public abstract class PapyrusEdgeFigure extends PolylineConnectionEx {
public PapyrusEdgeFigure() {
super();
setBendPointDiameter(7);
+ lineDashData = null;
}
+ /**
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx#setLineDash(int[])
+ */
+ public void setLineDash(int[] data) {
+ lineDashData = data;
+ }
/**
* We override this method to circle on bendpoints when a segment of the link is shared with another link of the same kind
@@ -69,6 +81,10 @@ public abstract class PapyrusEdgeFigure extends PolylineConnectionEx {
* @param g
*/
protected void outlineShape(Graphics g) {
+ g.setLineStyle(getLineStyle());
+ if (getLineStyle() == Graphics.LINE_DASH) {
+ g.setLineDash(lineDashData);
+ }
super.outlineShape(g);
drawConnectionPoint(g);
}