Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9138b043865c7d0ccfcd93472532e75fd4d44a1c (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
228
229
230
231
232
233
234
235
236
/**
 * @author: Manel Fredj - CEA
 * This class includes all the operations that are called in the transformation QVTO from java. 
 * These operations are wrapped into a black-box
 */

package org.eclipse.papyrus.conversion.di2todi.blackboxes;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
import org.eclipse.m2m.qvt.oml.blackbox.java.Operation;
import org.eclipse.papyrus.conversion.di2.GraphElement;
import org.eclipse.papyrus.conversion.di2.SemanticModelBridge;
import org.eclipse.papyrus.conversion.di2.Uml1SemanticModelBridge;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.Generalization;
import org.eclipse.uml2.uml.Realization;

public class UtilitiesLibrary {
	
	@Operation(contextual=true)
	public static String getName(Diagram self) 
	{
		return self.getName();
	}
	
	@Operation(contextual=true)
	public static EObject convertElement(Element self)
	{
		return self;
	}
	
	@Operation(contextual=true)
	public static String getElementType(Element self)
	{
		if (self instanceof Association )
			return "Association";
		if (self instanceof Generalization )
			return "Generalization";
		else return null;
	}
	
	@Operation(contextual=true)
	public static boolean isGeneralization(Element self)
	{
		if (self instanceof Generalization)
			return true;
		else return false;
	}
	
	
	@Operation(contextual=true)
	public static boolean isAssociation(Element self)
	{
		if (self instanceof Association)
			return true;
		else 
			return false;
	}
	
	@Operation(contextual=true)
	public static boolean isRealization(Element self)
	{
		if (self instanceof  Realization)
			return true;
		else 
			return false;
	}
	@Operation(contextual=true)
	public static boolean isDependency(Element self)
	{
		if (self instanceof Dependency)
			return true;
		else 
			return false;
	}
	
	@Operation(contextual=true)
	public static int dimensionGetWidth(Dimension self) 
	{   
		if (self!=null)
			return self.width;
		else
			return 0;
	}
	
	@Operation(contextual=true)
	public static int dimensionGetHeight(Dimension self) 
	{ 
		if (self!=null)
			return self.height;
		else
			return 0;
	}

	@Operation(contextual=true)
	public static int pointGetX(Point self)
	{ 
		if (self!=null)
		{
		
			return self.x;
		}else
			return 0;		
	}
	
	@Operation(contextual=true)
	public static int pointGetY(Point self) 
	{
		if (self!=null)
		{
			return self.y;
		}
		else
			return 0;
	}
	
	@Operation(contextual=true)
	public static String showcoordinates(Point self) 
	{
		if (self!=null)
		{
			return "the x is "+ self.x+ "and the y is "+ self.y;
		}
		else
			return "nothing to display";
	}
	
	@Operation(contextual=true)
	public static int rgb2int(RGB self) 
	{
		if (self!=null)
			return self.blue * 0x10000 + self.green *0x100 + self.red;
		else
			return 0;
	}
	
	@Operation(contextual=true)
	public static Element getElement(Uml1SemanticModelBridge bridge) {
		// difference to using element attribute directly: getElement will try to resolve proxies
		// and thus detects elements referenced by the di2 model that do not exist (anymore) in the
		// uml model
		Element element = bridge.getElement();
		if ((element != null) && element.eIsProxy()) {
			// is still proxy (the getElement implementation of Uml1SemanticModelBridge already tried to
			// resolve) => return null
			return null;
		}
		else {
			return element;
		}
	}

	/**
	 * Return the semantic model for a given di2 element
	 * @param di2Element existing di2 element
	 * @return the associated semantic model or null
	 */
	@Operation(contextual=true)
	public static Uml1SemanticModelBridge getSemanticModel(GraphElement di2Element) {
		SemanticModelBridge semanticModel;
		if (di2Element instanceof org.eclipse.papyrus.conversion.di2.Diagram) {
			semanticModel =((org.eclipse.papyrus.conversion.di2.Diagram) di2Element).getOwner();
		}
		else {
			semanticModel = di2Element.getSemanticModel();
		}
		if (semanticModel instanceof Uml1SemanticModelBridge) {
			return (Uml1SemanticModelBridge) semanticModel;
		}
		return null;
	}
	
	@Operation(contextual=true)
	public static Element getElement(GraphElement di2Element) {
		
		Uml1SemanticModelBridge semanticModel = getSemanticModel(di2Element);
		if (semanticModel != null) {
			return getElement (semanticModel);
		}
		else {
			System.err.println("no bridge found for di2Node" + di2Element);
		}
		return null;
	}
	
	// may be useful for debugging (use it instead of getElement in combination with a breakpoint)
	@Operation(contextual=true)
	public static Element getElementDebug(GraphElement di2Element) {
		
		Element element = getElement(di2Element);
		return element;
	}
	
	/**
	 * Papyrus 1 profile diagrams do not reference meta-class elements directly, but the
	 * associated element imported
	 * @param bridge
	 * @return
	 */
	@Operation(contextual=true)
	public static Element getMetaclassRef(Uml1SemanticModelBridge semanticModel) {
		Element element = getElement (semanticModel);
		if (element != null) {
			if (element instanceof ElementImport) {
				return ((ElementImport) element).getImportedElement();
			}
		}
		else {
			System.err.println("no element found");
		}
		return element;
	}
	
	public Object createBendpoints()
	{
		RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints();
		List<RelativeBendpoint> points = new ArrayList<RelativeBendpoint>(2);
		points.add(new RelativeBendpoint(0,0,0,0));
		points.add(new RelativeBendpoint(0,0,0,0));
		bendpoints.setPoints(points);
		return bendpoints;
	}
}

Back to the top