Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5a05cc34ef98b29fc628912b70542f92e037f552 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*****************************************************************************
 * Copyright (c) 2010, 2014 CEA LIST 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:
 *   Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.helper;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.gef.editparts.AbstractEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.NamedStyle;
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.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ShapeDisplayCompartmentEditPart;
import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IRoundedRectangleFigure;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;

/**
 * The Class RoundedCompartmentEditPart provides refresh method to apply notation properties specific to roundedRectangleFigure
 */
public abstract class PapyrusRoundedEditPartHelper {

	/** The Constant HAS_HEADER. */
	public static final String HAS_HEADER = "displayHeader";//$NON-NLS-N$

	/** The Constant USE_ORIGINAL_COLORS. */
	private static final String USE_ORIGINAL_COLORS = "useOriginalColors";//$NON-NLS-N$

	/** The Constant BORDER_STYLE. */
	protected static final String BORDER_STYLE = "borderStyle"; //$NON-NLS-N$

	/** CSS boolean property controlling whether label should be constrained. */
	public static final String FLOATING_LABEL_CONSTRAINED = "isFloatingLabelConstrained";//$NON-NLS-N$

	/** The Constant FLOATING_NAME_OFFSET_HEIGHT. */
	public static final String FLOATING_LABEL_OFFSET_HEIGHT = "floatingLabelOffsetHeight";//$NON-NLS-N$

	/** The Constant FLOATING_NAME_OFFSET_WIDTH. */
	public static final String FLOATING_LABEL_OFFSET_WIDTH = "floatingLabelOffsetWidth";//$NON-NLS-N$

	/** CSS boolean property controlling whether. */
	public static final String IS_OVAL = "isOval";//$NON-NLS-N$

	/** CSS boolean property controlling whether. */
	public static final String RADIUS_HEIGHT = "radiusHeight";//$NON-NLS-N$

	/** CSS boolean property controlling whether. */
	public static final String RADIUS_WIDTH = "radiusWidth";//$NON-NLS-N$

	private static final String LINE_CUSTOM_VALUE = "customDash";//$NON-NLS-N$

	/**
	 * Refresh border style.
	 */
	public static void refreshBorderStyle(IPapyrusEditPart editpart, int defaultBorderStyle, int[] defaultLineCustomValue) {
		// get the Figure
		if (editpart.getPrimaryShape() instanceof IRoundedRectangleFigure) {
			IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) editpart.getPrimaryShape();

			EClass stringValueStyle = NotationPackage.eINSTANCE.getStringValueStyle();

			int borderStyle = defaultBorderStyle;

			if (stringValueStyle != null) {

				if (((GraphicalEditPart) editpart).getModel() instanceof View) {
					// Get the border style on notation
					NamedStyle borderValueStyle = ((View) ((GraphicalEditPart) editpart).getModel()).getNamedStyle(stringValueStyle, BORDER_STYLE);
					// convert the string style name in integer
					if (borderValueStyle instanceof StringValueStyle) {
						String value = ((StringValueStyle) borderValueStyle).getStringValue();

						if ("dash".equals(value)) {
							borderStyle = Graphics.LINE_DASH;
						}
						if ("dashDot".equals(value)) {
							borderStyle = Graphics.LINE_DASHDOT;
						}
						if ("dashDotDot".equals(value)) {
							borderStyle = Graphics.LINE_DASHDOTDOT;
						}
						if ("dot".equals(value)) {
							borderStyle = Graphics.LINE_DOT;
						}
						if ("solid".equals(value)) {
							borderStyle = Graphics.LINE_SOLID;
						}
						if ("custom".equals(value)) {
							borderStyle = Graphics.LINE_CUSTOM;
						}
					}
				}
			}
			// set the border style of the figure
			roundedRectangleFigure.setBorderStyle(borderStyle);

			// get/set the custom dash value
			int[] customDash = NotationUtils.getIntListValue((View) ((GraphicalEditPart) editpart).getModel(), LINE_CUSTOM_VALUE, defaultLineCustomValue);
			roundedRectangleFigure.setCustomDash(customDash);

		}
	}

	/**
	 * Refresh floating name.
	 */
	public static void refreshFloatingName(IPapyrusEditPart editpart, boolean defaultIsFloatingNameConstrained, int defaultFloatingLabelOffsetWidth, int defaultFloatingLabelOffsetHeight) {
		if (editpart.getPrimaryShape() instanceof IRoundedRectangleFigure) {
			// The figure
			IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) editpart.getPrimaryShape();

			if (((GraphicalEditPart) editpart).getModel() instanceof View) {
				// Get CSS value for the name attached properties
				boolean isNameConstrained = NotationUtils.getBooleanValue((View) ((GraphicalEditPart) editpart).getModel(), FLOATING_LABEL_CONSTRAINED, defaultIsFloatingNameConstrained);

				// get CSS the value of offset width and height
				int width = NotationUtils.getIntValue((View) ((GraphicalEditPart) editpart).getModel(), FLOATING_LABEL_OFFSET_WIDTH, defaultFloatingLabelOffsetWidth);
				int height = NotationUtils.getIntValue((View) ((GraphicalEditPart) editpart).getModel(), FLOATING_LABEL_OFFSET_HEIGHT, defaultFloatingLabelOffsetHeight);

				// Set the name attached properties in figure
				roundedRectangleFigure.setFloatingNameConstrained(isNameConstrained);

				// Set the floating name offset
				roundedRectangleFigure.setFloatingNameOffset(new Dimension(width, height));
			}
		}
	}

	/**
	 * Refresh oval.
	 */
	public static void refreshOval(IPapyrusEditPart editpart, boolean defaultIsOvalValue) {
		if (editpart.getPrimaryShape() instanceof IRoundedRectangleFigure) {
			if (((GraphicalEditPart) editpart).getModel() instanceof View) {
				// The figure
				IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) editpart.getPrimaryShape();

				// get the CSS value of isOval
				boolean isOval = NotationUtils.getBooleanValue((View) ((GraphicalEditPart) editpart).getModel(), IS_OVAL, defaultIsOvalValue);

				// Set isOval
				roundedRectangleFigure.setOval(isOval);
			}
		}
	}

	/**
	 * Refresh radius.
	 */
	public static void refreshRadius(IPapyrusEditPart editpart, int defaultCornerWidth, int defaultCornerHeight) {
		if (editpart.getPrimaryShape() instanceof IRoundedRectangleFigure) {
			// The figure
			IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) editpart.getPrimaryShape();

			if (((GraphicalEditPart) editpart).getModel() instanceof View) {
				// get CSS the value of radius Width
				int width = NotationUtils.getIntValue((View) ((GraphicalEditPart) editpart).getModel(), RADIUS_WIDTH, defaultCornerWidth);

				// get CSS the value of radius Height
				int height = NotationUtils.getIntValue((View) ((GraphicalEditPart) editpart).getModel(), RADIUS_HEIGHT, defaultCornerHeight);

				// Set the corner dimension
				roundedRectangleFigure.setCornerDimensions(new Dimension(width, height));
			}
		}
	}

	/**
	 * Refresh svg original colors.
	 */
	public static void refreshSVGOriginalColors(IPapyrusEditPart editpart, boolean defaultUseOriginalColors) {
		if (editpart.getPrimaryShape() instanceof IRoundedRectangleFigure) {
			if (((GraphicalEditPart) editpart).getModel() instanceof View) {

				// get the CSS value if SVG use original colors
				boolean useOriginalColors = NotationUtils.getBooleanValue((View) ((AbstractEditPart) editpart).getModel(), USE_ORIGINAL_COLORS, defaultUseOriginalColors);

				if (((AbstractEditPart) editpart).getChildren() != null) {
					for (Object object : ((AbstractEditPart) editpart).getChildren()) {
						if (object instanceof ShapeDisplayCompartmentEditPart) {
							ShapeDisplayCompartmentEditPart shapeCompartment = (ShapeDisplayCompartmentEditPart) object;
							// Set useOriginalColors to the figure
							shapeCompartment.setUseOriginalColors(useOriginalColors);
						}
					}
				}
			}
		}

	}

	/**
	 * Refresh has header.
	 *
	 * @param editpart
	 *            the editpart
	 * @param defaultHasHeader
	 *            the default has header
	 */
	public static void refreshHasHeader(IPapyrusEditPart editpart, boolean defaultHasHeader) {
		if (editpart.getPrimaryShape() instanceof IRoundedRectangleFigure) {
			if (((GraphicalEditPart) editpart).getModel() instanceof View) {
				// The figure
				IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) editpart.getPrimaryShape();

				// get the CSS value of hasHeader
				boolean hasHeader = NotationUtils.getBooleanValue((View) ((GraphicalEditPart) editpart).getModel(), HAS_HEADER, defaultHasHeader);

				// Set hasHeader
				roundedRectangleFigure.setHasHeader(hasHeader);
			}
		}

	}

}

Back to the top