Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1510a0a55ace3a77b121cd32e971eed8ff234a89 (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/*
 * Copyright (c) 2007 Borland Software Corporation
 * 
 * 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:
 *    bblajer (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2005/GenModel/2.0"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
«EXTENSION xpt::diagram::policies::ClassNames»
«EXTENSION xpt::diagram::parts::Common»
«EXTENSION xpt::diagram::parts::NodeEditPart»
«EXTENSION xpt::diagram::ViewmapAttributesUtils»
«EXTENSION xpt::diagram::Helper»

«DEFINE NodeEditPart FOR gmfgen::GenNode-»
«EXPAND xpt::Common::copyright FOR getDiagram().editorGen»
package «getDiagram().editPartsPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «editPartClassName» «EXPAND supertypes» {
	«EXPAND xpt::diagram::parts::Common::visualIDConstant-»
	«EXPAND primaryShapeAttribute-»
	«EXPAND xpt::diagram::parts::Common::ctors-»
	«EXPAND xpt::diagram::parts::Common::registerModel-»
	«EXPAND createEditPolicies-»
	«EXPAND getPrimaryDragEditPolicy-»

	«EXPAND createFigure-»

	«EXPAND createDecorationPane-»
	«EXPAND xpt::diagram::parts::decorations::decorationManager-»
	«EXPAND xpt::diagram::parts::decorations::createDecorationManager-»
«IF compartments.size() > 0 && hasDirectChildren()-»
	«EXPAND childNodesPane-»
	«EXPAND setupChildNodesPane-»
«ENDIF-»
	«EXPAND createNodeShape-»
	«EXPAND getPrimaryShape FOR primaryShapeQualifiedClassName(viewmap)-»
	«EXPAND setupContentPane-»
	«EXPAND xpt::diagram::parts::Common::contentPane-»

	«EXPAND xpt::diagram::parts::Common::declareViewCode-»
«IF getInnerFixedLabels().size() > 0 || getPinnedCompartments().size() > 0-»
	«EXPAND addFixedChild-»
	«EXPAND removeFixedChild-»
«ENDIF-»

	«EXPAND xpt::diagram::parts::requests::getPrimaryLabelEditPart-»
	«EXPAND xpt::diagram::parts::requests::performRequest-»
	«EXPAND xpt::diagram::parts::requests::getLabelEditPart-»
«IF getExternalLabels().size() > 0-»
	«EXPAND isExternalLabel-»
	«EXPAND getExternalLabelsContainer-»
«ENDIF-»

«IF compartments.size() > 0 && hasDirectChildren()-»
	«EXPAND isDirectChild-»
«ENDIF-»

«IF getExternalLabels().size() > 0 || (compartments.size() > 0 && hasDirectChildren()) || getPinnedCompartments().size() > 0 || getInnerFixedLabels().size() > 0-»
	«EXPAND addChildVisual-»
	«EXPAND removeChildVisual-»
«ENDIF-»
«IF getExternalLabels().size() > 0-»
	«EXPAND removeNotify-»
«ENDIF-»

	«EXPAND xpt::diagram::parts::Common::getModelChildren-»
	«EXPAND xpt::diagram::parts::Common::getModelSourceConnections-»
	«EXPAND xpt::diagram::parts::Common::getModelTargetConnections-»
	«EXPAND connectionAnchors-»
	«EXPAND xpt::diagram::parts::Common::getAdapter-»

	«EXPAND xpt::diagram::parts::TreeEditPart::getTreeEditPartAdapter-»

	«EXPAND xpt::diagram::parts::Common::activate-»
	«EXPAND xpt::diagram::parts::Common::deactivate-»
	«EXPAND xpt::diagram::parts::NotationModelRefresher::all-»
	«EXPAND xpt::diagram::parts::LinkNotationModelRefresher::all-»
	«EXPAND xpt::diagram::parts::Common::getTransactionalUpdateManager-»
	«EXPAND xpt::diagram::parts::refresh::refresher-»
	«EXPAND xpt::diagram::parts::refresh::externalRefreshers-»

	«EXPAND xpt::diagram::parts::Common::viewmap FOR viewmap-»
	«EXPAND xpt::diagram::parts::TreeEditPart::TreeEditPart-»
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE supertypes FOR gmfgen::GenNode»extends org.eclipse.gef.editparts.AbstractGraphicalEditPart implements org.eclipse.gef.NodeEditPart, org.eclipse.gmf.runtime.lite.edit.parts.update.IUpdatableEditPart, org.eclipse.gmf.runtime.lite.edit.parts.update.IExternallyUpdatableEditPart, org.eclipse.gmf.runtime.lite.edit.parts.decorations.IDecoratableEditPart«ENDDEFINE»

«DEFINE primaryShapeAttribute FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.draw2d.IFigure primaryShape;
«ENDDEFINE»

«DEFINE createEditPolicies FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected void createEditPolicies() {
	installEditPolicy(org.eclipse.gef.EditPolicy.COMPONENT_ROLE, new «getComponentEditPolicyQualifiedClassName()»());
	installEditPolicy(org.eclipse.gef.EditPolicy.GRAPHICAL_NODE_ROLE, new «getGraphicalNodeEditPolicyQualifiedClassName()»());
«IF getPrimaryLabel() != null-»
	installEditPolicy(org.eclipse.gef.EditPolicy.DIRECT_EDIT_ROLE, new org.eclipse.gmf.runtime.lite.edit.policies.DelegatingDirectEditPolicy());
«ENDIF-»
	installEditPolicy(org.eclipse.gef.EditPolicy.LAYOUT_ROLE, new «getLayoutEditPolicyQualifiedClassName()»());
	«EXPAND xpt::diagram::parts::Common::behaviour-»
	installEditPolicy(org.eclipse.gef.EditPolicy.PRIMARY_DRAG_ROLE, getPrimaryDragEditPolicy());
	«EXPAND xpt::diagram::parts::NotationModelRefresher::installClause-»
	«EXPAND xpt::diagram::parts::LinkNotationModelRefresher::installClause-»
	}
«ENDDEFINE»

«DEFINE getPrimaryDragEditPolicy FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.EditPolicy getPrimaryDragEditPolicy() {
«IF primaryDragEditPolicyQualifiedClassName != null-»
	return new «primaryDragEditPolicyQualifiedClassName»();
«ELSE-»
	«IF compartments.size() == 0-»
		org.eclipse.gef.editpolicies.ResizableEditPolicy result = new org.eclipse.gef.editpolicies.ResizableEditPolicy();
	«ELSE-»
		org.eclipse.gef.editpolicies.ResizableEditPolicy result = new org.eclipse.gef.editpolicies.ResizableEditPolicy() {
			protected java.util.List createSelectionHandles() {
				java.util.List result = super.createSelectionHandles();
				for(java.util.Iterator it = getChildren().iterator(); it.hasNext(); ) {
					org.eclipse.gef.EditPart next = (org.eclipse.gef.EditPart) it.next();
					org.eclipse.gmf.runtime.notation.View nextView = (org.eclipse.gmf.runtime.notation.View) next.getModel();
					switch («getDiagram().getVisualIDRegistryQualifiedClassName()».getVisualID(nextView)) {
					«EXPAND addSelectionHandles FOREACH compartments-»
					}
				}
				return result;
			}
		};
	«ENDIF-»
	«EXPAND setResizeConstraints FOR viewmap.getResizeConstraints()-»
		return result;
«ENDIF-»
}
«ENDDEFINE»

«DEFINE createFigure FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.draw2d.IFigure createFigure() {
	org.eclipse.draw2d.IFigure invisibleRectangle = new org.eclipse.draw2d.Figure();
	invisibleRectangle.setLayoutManager(new org.eclipse.draw2d.StackLayout());
	org.eclipse.draw2d.IFigure shape = createNodeShape();
	invisibleRectangle.add(shape);
	contentPane = setupContentPane(shape);
«IF compartments.size() > 0 && hasDirectChildren()-»
		childNodesPane = createChildNodesPane();
		shape.add(childNodesPane);
«ENDIF-»
	org.eclipse.draw2d.IFigure decorationShape = createDecorationPane();
	if (decorationShape != null) {
		myDecorationManager = createDecorationManager(decorationShape);
		invisibleRectangle.add(decorationShape, 0);
	}
	return invisibleRectangle;
}
«ENDDEFINE»

«DEFINE addSelectionHandles FOR gmfgen::GenCompartment-»
case «getEditPartQualifiedClassName()».VISUAL_ID:
	result.addAll(((«getEditPartQualifiedClassName()») next).createSelectionHandles());
	break;
«ENDDEFINE»

«DEFINE setResizeConstraints FOR gmfgen::ResizeConstraints-»
«IF resizeHandles == 0-»
		result.setResizeDirections(org.eclipse.draw2d.PositionConstants.NONE);
«ELSE-»
		result.setResizeDirections(«EXPAND resizeHandleName FOREACH resizeHandleNames SEPARATOR ' | '»);
«ENDIF-»
«ENDDEFINE»

«DEFINE resizeHandleName FOR ecore::EString»org.eclipse.draw2d.PositionConstants.«this»«ENDDEFINE»

«DEFINE childNodesPane FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.draw2d.IFigure childNodesPane;

«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.draw2d.IFigure createChildNodesPane() {
	org.eclipse.draw2d.IFigure result = new org.eclipse.draw2d.RectangleFigure()«IF isXYLayout()»«EXPAND forceUseLocalCoordinates»«ENDIF»;
	setupChildNodesPane(result);
	return result;
}
«ENDDEFINE»

«DEFINE createNodeShape FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.draw2d.IFigure createNodeShape() {
	«EXPAND initPrimaryShape(this) FOR viewmap-»
	return primaryShape;
}
«ENDDEFINE»

«DEFINE initPrimaryShape(gmfgen::GenNode node) FOR gmfgen::Viewmap»«ERROR "Unexpected viewmap type " + this»«ENDDEFINE»

«DEFINE initPrimaryShape(gmfgen::GenNode node) FOR gmfgen::FigureViewmap-»
primaryShape = new «primaryShapeQualifiedClassName(this)»()«IF node.compartments.size() == 0 && node.hasDirectChildren() && node.isXYLayout()»«EXPAND forceUseLocalCoordinates»«ENDIF»;
«ENDDEFINE»

«DEFINE initPrimaryShape(gmfgen::GenNode node) FOR gmfgen::SnippetViewmap-»
primaryShape = «body»;
«ENDDEFINE»

«DEFINE initPrimaryShape(gmfgen::GenNode node) FOR gmfgen::InnerClassViewmap-»
«primaryShapeQualifiedClassName(this)» figure = new «primaryShapeQualifiedClassName(this)»();
«IF node.compartments.size() == 0 && node.hasDirectChildren() && node.isXYLayout()-»
figure.setUseLocalCoordinates(true);
«ENDIF-»
primaryShape = figure;
«ENDDEFINE»

«DEFINE forceUseLocalCoordinates FOR Object-»
{
	protected boolean useLocalCoordinates() {
		return true;
	}
}«-»
«ENDDEFINE»

«DEFINE getPrimaryShape FOR ecore::EString-»
«EXPAND xpt::Common::generatedMemberComment»
public «this» getPrimaryShape() {
	return («this») primaryShape;
}
«ENDDEFINE»

«DEFINE setupContentPane FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment("Default implementation treats passed figure as content pane.\n" + 
 "Respects layout one may have set for generated figure.\n" + 
 "@param nodeShape instance of generated figure class")»
protected org.eclipse.draw2d.IFigure setupContentPane(org.eclipse.draw2d.IFigure nodeShape) {
	if (nodeShape.getLayoutManager() == null) {
		«EXPAND setLayoutManager("nodeShape", compartments.size() == 0 && isXYLayout())-»
	}
	return nodeShape; // use nodeShape itself as contentPane
}
«ENDDEFINE»

«DEFINE setupChildNodesPane FOR gmfgen::GenNode-»
protected void setupChildNodesPane(org.eclipse.draw2d.IFigure shape) {
	if (shape.getLayoutManager() == null) {
		«EXPAND setLayoutManager("shape", isXYLayout())-»
	}
}
«ENDDEFINE»

«DEFINE setLayoutManager(String shapeVar, Boolean xyLayout) FOR gmfgen::GenNode-»
«IF xyLayout-»
«shapeVar».setLayoutManager(new org.eclipse.draw2d.FreeformLayout() {
	public Object getConstraint(org.eclipse.draw2d.IFigure figure) {
		Object result = constraints.get(figure);
		if (result == null) {
			result = new org.eclipse.draw2d.geometry.Rectangle(0, 0, -1, -1);
		}
		return result;
	}
});
«ELSE-»
org.eclipse.draw2d.ToolbarLayout layout = new org.eclipse.draw2d.ToolbarLayout();
layout.setSpacing(5);
«shapeVar».setLayoutManager(layout);
«ENDIF-»
«ENDDEFINE»

«DEFINE createDecorationPane FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.draw2d.IFigure createDecorationPane() {
	return new org.eclipse.draw2d.Figure();
}
«ENDDEFINE»

«DEFINE addFixedChild FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected boolean addFixedChild(org.eclipse.gef.EditPart childEditPart) {
«EXPAND addFixedLabel FOREACH getInnerFixedLabels()-»
«EXPAND addFixedCompartment FOREACH getPinnedCompartments()-»
	return false;
}
«ENDDEFINE»

«DEFINE addFixedLabel FOR gmfgen::GenLabel-»
if (childEditPart instanceof «getEditPartQualifiedClassName()») {
	((«getEditPartQualifiedClassName()») childEditPart).«EXPAND setter FOR viewmap»(getPrimaryShape().«EXPAND getter FOR viewmap»());
	return true;
}
«ENDDEFINE»

«DEFINE getter FOR gmfgen::Viewmap»«ERROR "Unexpected type"»«ENDDEFINE»
«DEFINE getter FOR gmfgen::ParentAssignedViewmap»«getterName»«ENDDEFINE»

«DEFINE setter FOR gmfgen::Viewmap»«ERROR "Unexpected type"»«ENDDEFINE»
«DEFINE setter FOR gmfgen::ParentAssignedViewmap»«IF setterName == null»setLabel«ELSE»«setterName»«ENDIF»«ENDDEFINE»

«DEFINE addFixedCompartment FOR gmfgen::GenCompartment-»
if (childEditPart instanceof «getEditPartQualifiedClassName()») {
	org.eclipse.draw2d.IFigure pane = getPrimaryShape().«EXPAND getter FOR viewmap»();
	((«getEditPartQualifiedClassName()») childEditPart).setupCompartmentHolder(pane);
	pane.add(((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure());
	return true;
}	
«ENDDEFINE»

«DEFINE removeFixedChild FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected boolean removeFixedChild(org.eclipse.gef.EditPart childEditPart) {
«REM»ignore labels assuming that they never may be removed«ENDREM»
«EXPAND removeFixedCompartment FOREACH getPinnedCompartments()-»
	return false;
}
«ENDDEFINE»

«DEFINE removeFixedCompartment FOR gmfgen::GenCompartment-»
if (childEditPart instanceof «getEditPartQualifiedClassName()») {
	org.eclipse.draw2d.IFigure pane = getPrimaryShape().«EXPAND getter FOR viewmap»();
	pane.remove(((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure());
	return true;
}	
«ENDDEFINE»

«DEFINE isExternalLabel FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public boolean isExternalLabel(org.eclipse.gef.EditPart childEditPart) {
«EXPAND returnInstanceof("childEditPart") FOREACH getExternalLabels()-»
	return false;
}
«ENDDEFINE»

«DEFINE isDirectChild FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public boolean isDirectChild(org.eclipse.gef.EditPart childEditPart) {
«EXPAND returnInstanceof("childEditPart") FOREACH getDirectChildren()-»
	return false;
}
«ENDDEFINE»

«DEFINE returnInstanceof(String var) FOR gmfgen::GenCommonBase-»
if («var» instanceof «getEditPartQualifiedClassName()») {
	return true;
}
«ENDDEFINE»

«DEFINE addChildVisual FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected void addChildVisual(org.eclipse.gef.EditPart childEditPart, int index) {
«IF getExternalLabels().size() > 0-»
		if (isExternalLabel(childEditPart)) {
			org.eclipse.draw2d.IFigure labelFigure = ((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure();
			getExternalLabelsContainer().add(labelFigure);
			return;
		}
«ENDIF-»
«IF getInnerFixedLabels().size() > 0 || getPinnedCompartments().size() > 0-»
		if (addFixedChild(childEditPart)) {
			return;
		}
«ENDIF-»
«IF compartments.size() > 0 && hasDirectChildren()-»
		if (isDirectChild(childEditPart)) {
			org.eclipse.draw2d.IFigure childFigure = ((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure();
			childNodesPane.add(childFigure);
			return;
		}
«ENDIF-»
	super.addChildVisual(childEditPart, -1);
}
«ENDDEFINE»

«DEFINE removeChildVisual FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected void removeChildVisual(org.eclipse.gef.EditPart childEditPart) {
«IF getExternalLabels().size() > 0-»
		if (isExternalLabel(childEditPart)) {
			org.eclipse.draw2d.IFigure labelFigure = ((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure();
			getExternalLabelsContainer().remove(labelFigure);
			return;
		}
«ENDIF-»
«IF getInnerFixedLabels().size() > 0 || getPinnedCompartments().size() > 0-»
		if (removeFixedChild(childEditPart)){
			return;
		}
«ENDIF-»
«IF compartments.size() > 0 && hasDirectChildren()-»
		if (isDirectChild(childEditPart)) {
			org.eclipse.draw2d.IFigure childFigure = ((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure();
			childNodesPane.remove(childFigure);
			return;
		}
«ENDIF-»
	super.removeChildVisual(childEditPart);
}
«ENDDEFINE»

«DEFINE getExternalLabelsContainer FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.draw2d.IFigure getExternalLabelsContainer() {
	org.eclipse.gef.editparts.LayerManager root = (org.eclipse.gef.editparts.LayerManager) getRoot();
	return root.getLayer(«getDiagram().getEditPartFactoryQualifiedClassName()».EXTERNAL_NODE_LABELS_LAYER);
}
«ENDDEFINE»

«DEFINE removeNotify FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public void removeNotify() {
	for (java.util.Iterator it = getChildren().iterator(); it.hasNext(); ) {
		org.eclipse.gef.EditPart childEditPart = (org.eclipse.gef.EditPart) it.next();
		if (isExternalLabel(childEditPart)) {
			org.eclipse.draw2d.IFigure labelFigure = ((org.eclipse.gef.GraphicalEditPart) childEditPart).getFigure();
			getExternalLabelsContainer().remove(labelFigure);
		}
	}
	super.removeNotify();
}
«ENDDEFINE»

«DEFINE connectionAnchors FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.draw2d.ConnectionAnchor getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart connection) {
	return new org.eclipse.draw2d.ChopboxAnchor(getFigure());
}

«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.draw2d.ConnectionAnchor getSourceConnectionAnchor(org.eclipse.gef.Request request) {
	return new org.eclipse.draw2d.ChopboxAnchor(getFigure());
}

«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.draw2d.ConnectionAnchor  getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart connection) {
	return new org.eclipse.draw2d.ChopboxAnchor(getFigure());
}

«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.draw2d.ConnectionAnchor  getTargetConnectionAnchor(org.eclipse.gef.Request request) {
	return new org.eclipse.draw2d.ChopboxAnchor(getFigure());
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenNode»«ENDDEFINE»

Back to the top