Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cabe878b5b6a47184124e5f2559fd3647fbfe3cf (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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/******************************************************************************
 * Copyright (c) 2006, 2020 Borland Software Corporation, CEA LIST, Artal and others
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/ 
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: 
 *    Dmitry Stadnik (Borland) - initial API and implementation
 *    Alexander Shatalin (Borland) - initial API and implementation
 *    Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
 *****************************************************************************/

«IMPORT 'http://www.eclipse.org/papyrus/gmf/2020/GenModel'»
«EXTENSION xpt::diagram::ViewmapAttributesUtils»
«EXTENSION impl::diagram::editparts::ChoiceUtils»
«EXTENSION impl::diagram::editparts::RuntimeLabelsSupport»
«EXTENSION impl::parsers::expression»

«DEFINE fields FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gef.tools.DirectEditManager manager;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gmf.runtime.common.ui.services.parser.IParser parser;

	«IF isOclChoiceLabel() or isViewExpressionDefiedAndOcl()-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker.Registrator myOclRegistrator;
	«ELSE-»
	«EXPAND xpt::Common::generatedMemberComment»
 	private «EXPAND CodeStyle::G('java.util.List', '?')» parserElements;
	«ENDIF-»

	«EXPAND xpt::Common::generatedMemberComment»
	private String defaultText;	

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gmf.runtime.diagram.ui.label.ILabelDelegate labelDelegate;
«ENDDEFINE»

«DEFINE methods(needsRefreshBounds : Boolean, readOnly : Boolean, useElementIcon : Boolean, viewmap : gmfgen::Viewmap,
		modelFacet : gmfgen::LabelModelFacet, host : gmfgen::GenCommonBase, diagram : gmfgen::GenDiagram) FOR gmfgen::GenCommonBase-»
	«EXPAND getLabelTextHelper-»
	
	«EXPAND setLabelTextHelper-»
	
	«EXPAND getLabelIconHelper-»
	
	«EXPAND setLabelIconHelper-»
	
	«EXPAND labelSetter-»
	
	«EXPAND getModelChildren-»
	
	«EXPAND getChildBySemanticHint-»
	
	«EXPAND getParserElement(modelFacet)-»
	
	«EXPAND getLabelIcon(useElementIcon, diagram)-»
	
	«EXPAND getLabelText-»
	
	«EXPAND setLabelText(diagram)-»
	
	«EXPAND getEditText-»
	
	«EXPAND isEditable(readOnly)-»
	
	«EXPAND getEditTextValidator-»
	
	«EXPAND getCompletionProcessor-»
	
	«EXPAND getParserOptions-»
	
	«EXPAND getParser(modelFacet, diagram, host)-»
	
	«EXPAND getManager(diagram, modelFacet)-»
	
	«EXPAND setManager-»
	
	«EXPAND performDirectEdit-»
	
	«EXPAND performDirectEditAtPoint(modelFacet)-»

«IF not(isChoiceLabel(modelFacet))-»
	«EXPAND performDirectEditWithInitialChar-»
«ENDIF»	
	
	«EXPAND performDirectEditRequest(modelFacet)-»
	
	«EXPAND refreshVisuals(needsRefreshBounds)-»
	
	«EXPAND refreshLabel(diagram)-»
	
	«EXPAND refreshUnderline-»
	
	«EXPAND refreshStrikeThrough-»
	
	«EXPAND refreshFont-»
	
	«EXPAND refreshSelectionFeedback-»
	
	«EXPAND setFontColor-»
	
	«EXPAND addSemanticListeners-»
	
	«EXPAND removeSemanticListeners-»
	
	«EXPAND getAccessibleEditPart-»
	
	«EXPAND getFontStyleOwnerView(viewmap)-»
		
«IF isOclChoiceLabelWithShowExpr() or isViewExpressionDefiedAndOcl()-»
	«EXPAND getOclTracker-»
«ENDIF-»
	
«IF isOclChoiceLabel() or isViewExpressionDefiedAndOcl()-»
	«EXPAND getOclRegistrator-»
«ENDIF-»

  «EXPAND getLabelDelegate -»
    
  «EXPAND getAdapter -»
«ENDDEFINE»

«DEFINE labelSetterName FOR gmfgen::ParentAssignedViewmap-»
«IF setterName <> null»«setterName»«ELSE»setLabel«ENDIF-»
«ENDDEFINE»

«DEFINE labelSetterName FOR gmfgen::Viewmap»setLabel«ENDDEFINE»
«DEFINE labelSetterName FOR gmfgen::ModeledViewmap»setLabel«ENDDEFINE»

«DEFINE getLabelTextHelper FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected String getLabelTextHelper(org.eclipse.draw2d.IFigure figure) {
		if (figure instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			return ((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) figure).getText();
		} «IF isVerticalLabel(self)-»
		else if (figure instanceof «getVerticalLabelFQN()») {
			return ((«getVerticalLabelFQN()») figure).getText();
    	} «ENDIF-»
		else if (figure instanceof org.eclipse.draw2d.Label) {
			return ((org.eclipse.draw2d.Label) figure).getText();
		} else {
			return getLabelDelegate().getText();
		} 
	}
«ENDDEFINE»

«DEFINE setLabelTextHelper FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void setLabelTextHelper(org.eclipse.draw2d.IFigure figure, String text) {
		if (figure instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) figure).setText(text);
		} «IF isVerticalLabel(self)-»
		else if (figure instanceof «getVerticalLabelFQN()») {
			((«getVerticalLabelFQN()») figure).setText(text);
    	} «ENDIF-»
		else if (figure instanceof org.eclipse.draw2d.Label) {
			((org.eclipse.draw2d.Label) figure).setText(text);
		} else {
			getLabelDelegate().setText(text);
		}
	}
«ENDDEFINE»

«DEFINE getLabelIconHelper FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.swt.graphics.Image getLabelIconHelper(org.eclipse.draw2d.IFigure figure) {
		if (figure instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			return ((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) figure).getIcon();
		} «IF isVerticalLabel(self)-»
		else if (figure instanceof «getVerticalLabelFQN()») {
			//icons are not supported for verical labels now
			return null;
    	} «ENDIF-»
		else if (figure instanceof org.eclipse.draw2d.Label) {
			return ((org.eclipse.draw2d.Label) figure).getIcon();
		} else {
			return getLabelDelegate().getIcon(0);
		}
	}
«ENDDEFINE»

«DEFINE setLabelIconHelper FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void setLabelIconHelper(org.eclipse.draw2d.IFigure figure, org.eclipse.swt.graphics.Image icon) {
		if (figure instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) figure).setIcon(icon);
			return;
		} «IF isVerticalLabel(self)-»
		else if (figure instanceof «getVerticalLabelFQN()») {
			//icons are not supported for verical labels now, nothing to do
			return;
    	} «ENDIF-»
		else if (figure instanceof org.eclipse.draw2d.Label) {
			((org.eclipse.draw2d.Label) figure).setIcon(icon);
			return;
		} else {
			getLabelDelegate().setIcon(icon, 0);
		}
	}
«ENDDEFINE»

«DEFINE getLabelDelegate FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gmf.runtime.diagram.ui.label.ILabelDelegate getLabelDelegate(){
		if (labelDelegate == null){
			org.eclipse.draw2d.IFigure label = getFigure();
      		if (label instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel){
        		labelDelegate = new org.eclipse.gmf.runtime.diagram.ui.label.WrappingLabelDelegate((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel)label);
      		} «IF isVerticalLabel(self)-»
      		else if (label instanceof «getVerticalLabelFQN()») {
        		labelDelegate = new «getVerticalLabelDelegateFQN()»((«getVerticalLabelFQN()»)label); 
      		} «ENDIF-»
      		else {
        		labelDelegate = new «getSimpleLabelDelegateFQN()»((org.eclipse.draw2d.Label)label);
      		}
    	}
		return labelDelegate;
	}
«ENDDEFINE»

«DEFINE getAdapter FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	«EXPAND CodeStyle::override-»
	public Object getAdapter(Class key) {
		if (org.eclipse.gmf.runtime.diagram.ui.label.ILabelDelegate.class.equals(key)){
			return getLabelDelegate();
		}
		return super.getAdapter(key);
	}
«ENDDEFINE»

«DEFINE labelSetter FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void «EXPAND labelSetterName FOR viewmap»(«EXPAND labelSetterFigureClassName FOR viewmap» figure) {
		unregisterVisuals();
		setFigure(figure);
		defaultText = getLabelTextHelper(figure);
		registerVisuals();
		refreshVisuals();
	}
«ENDDEFINE»

«DEFINE labelSetterFigureClassName FOR gmfgen::ParentAssignedViewmap-»
	«IF figureQualifiedClassName <> null-»
	«figureQualifiedClassName»
	«ELSE-»
	org.eclipse.draw2d.IFigure
	«ENDIF-»
«ENDDEFINE»

«DEFINE labelSetterFigureClassName FOR gmfgen::ModeledViewmap-»
«EXPAND impl::diagram::editparts::viewmaps::modeledViewmapProducer::viewmapFigureFQN FOR self-»
«ENDDEFINE»

«DEFINE labelSetterFigureClassName FOR gmfgen::Viewmap-»
	org.eclipse.draw2d.IFigure
«ENDDEFINE»

«DEFINE getModelChildren FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	«EXPAND CodeStyle::SuppressWarnings('"rawtypes"')-»
	protected java.util.List getModelChildren() {
		return java.util.Collections.EMPTY_LIST;
	}
«ENDDEFINE»

«DEFINE getChildBySemanticHint FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
		return null;
	}
«ENDDEFINE»

«DEFINE getParserElement(modelFacet : gmfgen::LabelModelFacet) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.emf.ecore.EObject getParserElement() {
«IF modelFacet = null»
		org.eclipse.emf.ecore.EObject element = resolveSemanticElement();
		return element != null ? element : (org.eclipse.gmf.runtime.notation.View) getModel();
«ELSE»«EXPAND getParserElement FOR modelFacet»«ENDIF-»
	}
«ENDDEFINE»

«DEFINE getParserElement FOR gmfgen::LabelModelFacet-»
		return resolveSemanticElement();
«ENDDEFINE»

«DEFINE getParserElement FOR gmfgen::DesignLabelModelFacet-»
		return (org.eclipse.gmf.runtime.notation.View) getModel();
«ENDDEFINE»

«DEFINE getLabelIcon(useElementIcon : Boolean, diagram : gmfgen::GenDiagram) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.swt.graphics.Image getLabelIcon() {
		«IF useElementIcon-»
		org.eclipse.emf.ecore.EObject parserElement = getParserElement();
		if (parserElement == null) {
			return null;
		}
		return «diagram.getElementTypesQualifiedClassName()».getImage(parserElement.eClass());
		«ELSE-»
		return null;
		«ENDIF-»
	}
«ENDDEFINE»

«DEFINE getLabelText FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected String getLabelText() {
		String text = null;
		org.eclipse.emf.ecore.EObject parserElement = getParserElement();
		if (parserElement != null && getParser() != null) {
			text = getParser().getPrintString(
				new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(parserElement),
				getParserOptions().intValue());
		}
		if (text == null || text.length() == 0) {
			text = defaultText;
		}
		return text;
	}
«ENDDEFINE»

«DEFINE setLabelText(diagram : gmfgen::GenDiagram) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void setLabelText(String text) {
		setLabelTextHelper(getFigure(), text);
		refreshSelectionFeedback();
	}
«ENDDEFINE»

«DEFINE getEditText FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public String getEditText() {
		if (getParserElement() == null || getParser() == null) {
			return ""; «EXPAND xpt::Common::nonNLS»
		}
		return getParser().getEditString(
			new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(getParserElement()),
			getParserOptions().intValue());
	}
«ENDDEFINE»

«DEFINE isEditable(readOnly : Boolean) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean isEditable() {
		«IF readOnly-»
		return false;
		«ELSE-»
		return getParser() != null;
		«ENDIF-»
	}
«ENDDEFINE»

«DEFINE getEditTextValidator FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.jface.viewers.ICellEditorValidator getEditTextValidator() {
		return new org.eclipse.jface.viewers.ICellEditorValidator() {

			public String isValid(final Object value) {
				if (value instanceof String) {
					final org.eclipse.emf.ecore.EObject element = getParserElement();
					final org.eclipse.gmf.runtime.common.ui.services.parser.IParser parser = getParser();
					try {
						org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus valid =
							(org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus) getEditingDomain().runExclusive(
								new org.eclipse.emf.transaction.RunnableWithResult.Impl«EXPAND CodeStyle::G('org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus')»() {

							public void run() {
								setResult(parser.isValidEditString(new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(element), (String) value));
							}
						});
						return valid.getCode() == org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.EDITABLE ? null : valid.getMessage();
					} catch (InterruptedException ie) {
						ie.printStackTrace();
					}
				}

				// shouldn't get here
				return null;
			}
		};
	}
«ENDDEFINE»

«DEFINE getCompletionProcessor FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.jface.text.contentassist.IContentAssistProcessor getCompletionProcessor() {
		if (getParserElement() == null || getParser() == null) {
			return null;
		}
		return getParser().getCompletionProcessor(new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(getParserElement()));
	}
«ENDDEFINE»

«DEFINE getParserOptions FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions getParserOptions() {
		return org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions.NONE;
	}
«ENDDEFINE»

«DEFINE getParser(modelFacet : gmfgen::LabelModelFacet, diagram : gmfgen::GenDiagram, host : gmfgen::GenCommonBase) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.common.ui.services.parser.IParser getParser() {
		if (parser == null) {
			parser = «EXPAND parsers::ParserProvider::accessorCall(host, modelFacet, 'getParserElement()')»;
		}
		return parser;
	}
«ENDDEFINE»

«DEFINE getManager(diagram : gmfgen::GenDiagram, modelFacet : gmfgen::LabelModelFacet) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gef.tools.DirectEditManager getManager() {
		if (manager == null) {
			setManager(new «getDirectManagerFQN(modelFacet)»(this,
				null,
				«diagram.getEditPartFactoryQualifiedClassName()».getTextCellEditorLocator(this)));
		}
		return manager;
	}
«ENDDEFINE»

«DEFINE setManager FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void setManager(org.eclipse.gef.tools.DirectEditManager manager) {
		this.manager = manager;
	}
«ENDDEFINE»

«DEFINE performDirectEdit FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void performDirectEdit() {
		getManager().show();
	}
«ENDDEFINE»
	
«DEFINE performDirectEditAtPoint(modelFacet : gmfgen::LabelModelFacet) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void performDirectEdit(org.eclipse.draw2d.geometry.Point eventLocation) {
		if (getManager().getClass() == «getDirectManagerFQN(modelFacet)».class) {
			((«getDirectManagerFQN(modelFacet)») getManager()).show(eventLocation.getSWTPoint());
		}
	}
«ENDDEFINE»
	
«DEFINE performDirectEditWithInitialChar FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	private void performDirectEdit(char initialCharacter) {
		if (getManager() instanceof org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager) {
			((org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager) getManager()).show(initialCharacter);
		} else //
		{
			performDirectEdit();
		}
	}
«ENDDEFINE»
	
«DEFINE performDirectEditRequest(modelFacet : gmfgen::LabelModelFacet) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void performDirectEditRequest(org.eclipse.gef.Request request) {
		final org.eclipse.gef.Request theRequest = request;
		try {
			getEditingDomain().runExclusive(new Runnable() {

				public void run() {
					if (isActive() && isEditable()) {
						«IF not(isChoiceLabel(modelFacet))-»
						if (theRequest.getExtendedData().get(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
							Character initialChar = (Character) theRequest.getExtendedData().get(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
							performDirectEdit(initialChar.charValue());
						} else «ENDIF» if ((theRequest instanceof org.eclipse.gef.requests.DirectEditRequest) && (getEditText().equals(getLabelText()))) {
							org.eclipse.gef.requests.DirectEditRequest editRequest = (org.eclipse.gef.requests.DirectEditRequest) theRequest;
							performDirectEdit(editRequest.getLocation());
						} else {
							performDirectEdit();
						}
					}
				}
			});
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
«ENDDEFINE»
	
«DEFINE refreshVisuals(needsRefreshBounds : Boolean) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshVisuals() {
		super.refreshVisuals();
		refreshLabel();
		refreshFont();
		refreshFontColor();
		refreshUnderline();
		refreshStrikeThrough();
		«IF needsRefreshBounds-»
		refreshBounds();
		«ENDIF-»
	}
«ENDDEFINE»
	
«DEFINE refreshLabel(diagram : gmfgen::GenDiagram) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshLabel() {
		setLabelTextHelper(getFigure(), getLabelText());
		setLabelIconHelper(getFigure(), getLabelIcon());
		refreshSelectionFeedback();
	}
«ENDDEFINE»
	
«DEFINE refreshUnderline FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshUnderline() {
		org.eclipse.gmf.runtime.notation.FontStyle style =
			(org.eclipse.gmf.runtime.notation.FontStyle) getFontStyleOwnerView().getStyle(
				org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getFontStyle());
		if (style != null && getFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getFigure()).setTextUnderline(style.isUnderline());
		}
	}
«ENDDEFINE»
	
«DEFINE refreshStrikeThrough FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshStrikeThrough() {
		org.eclipse.gmf.runtime.notation.FontStyle style =
			(org.eclipse.gmf.runtime.notation.FontStyle) getFontStyleOwnerView().getStyle(
				org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getFontStyle());
		if (style != null && getFigure() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) {
			((org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
		}
	}
«ENDDEFINE»
	
«DEFINE refreshFont FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void refreshFont() {
		org.eclipse.gmf.runtime.notation.FontStyle style =
			(org.eclipse.gmf.runtime.notation.FontStyle) getFontStyleOwnerView().getStyle(
				org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getFontStyle());
		if (style != null) {
			org.eclipse.swt.graphics.FontData fontData = new org.eclipse.swt.graphics.FontData(
				style.getFontName(), style.getFontHeight(),
				(style.isBold() ? org.eclipse.swt.SWT.BOLD : org.eclipse.swt.SWT.NORMAL) |
				(style.isItalic() ? org.eclipse.swt.SWT.ITALIC : org.eclipse.swt.SWT.NORMAL));
			setFont(fontData);
		}
	}
«ENDDEFINE»

«DEFINE refreshSelectionFeedback FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	private void refreshSelectionFeedback() {
		requestEditPolicyFeedbackRefresh(org.eclipse.gef.EditPolicy.PRIMARY_DRAG_ROLE);
		requestEditPolicyFeedbackRefresh(org.eclipse.gef.EditPolicy.SELECTION_FEEDBACK_ROLE);
	}
	
	«EXPAND xpt::Common::generatedMemberComment»
	private void requestEditPolicyFeedbackRefresh(String editPolicyKey) {
		Object editPolicy = getEditPolicy(editPolicyKey);
		if (editPolicy instanceof org.eclipse.gmf.tooling.runtime.edit.policies.labels.IRefreshableFeedbackEditPolicy) {
			((org.eclipse.gmf.tooling.runtime.edit.policies.labels.IRefreshableFeedbackEditPolicy)editPolicy).refreshFeedback();
		}
	}
«ENDDEFINE»

	
«DEFINE setFontColor FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void setFontColor(org.eclipse.swt.graphics.Color color) {
		getFigure().setForegroundColor(color);
	}
«ENDDEFINE»
	
«DEFINE addSemanticListeners FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void addSemanticListeners() {
«IF isOclChoiceLabel() or isViewExpressionDefiedAndOcl()-»
		«IF isOclChoiceLabelWithShowExpr() or isViewExpressionDefiedAndOcl()-»
		org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker tracker = getTracker();
		tracker.initialize(resolveSemanticElement());
		tracker.installListeners(getEditingDomain(), this, getOclRegistrator());
		«ELSE-»
		super.addSemanticListeners();
		«ENDIF-»
		«IF isOclChoiceLabel()-»
		((org.eclipse.gmf.tooling.runtime.parsers.OclChoiceParser) getParser()).installListeners(this, getOclRegistrator());
		«ENDIF-»		
«ELSE-»
		if (getParser() instanceof org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) {
			org.eclipse.emf.ecore.EObject element = resolveSemanticElement();
			parserElements = ((org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
			for (int i = 0; i < parserElements.size(); i++) {
				addListenerFilter("SemanticModel" + i, this, (org.eclipse.emf.ecore.EObject) parserElements.get(i)); «EXPAND xpt::Common::nonNLS»
			}
		} else {
			super.addSemanticListeners();
		}
«ENDIF-»	
	}
«ENDDEFINE»
	
«DEFINE removeSemanticListeners FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected void removeSemanticListeners() {
«IF isOclChoiceLabel() or isViewExpressionDefiedAndOcl()-»			
		«IF isOclChoiceLabel()-»
		((org.eclipse.gmf.tooling.runtime.parsers.OclChoiceParser) getParser()).uninstallListeners();
		«ENDIF-»
		«IF isOclChoiceLabelWithShowExpr() or isViewExpressionDefiedAndOcl()-»
		getTracker().uninstallListeners();	
		«ELSE-»
		super.removeSemanticListeners();
		«ENDIF-»	
«ELSE-»		
		if (parserElements != null) {
			for (int i = 0; i < parserElements.size(); i++) {
				removeListenerFilter("SemanticModel" + i); «EXPAND xpt::Common::nonNLS»
			}
		} else {
			super.removeSemanticListeners();
		}
«ENDIF-»
	}
«ENDDEFINE»
	
«DEFINE getAccessibleEditPart FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.gef.AccessibleEditPart getAccessibleEditPart() {
		if (accessibleEP == null) {
			accessibleEP = new AccessibleGraphicalEditPart() {

				public void getName(org.eclipse.swt.accessibility.AccessibleEvent e) {
					e.result = getLabelTextHelper(getFigure());
				}
			};
		}
		return accessibleEP;
	}
«ENDDEFINE»
	
«DEFINE getFontStyleOwnerView(viewmap : gmfgen::Viewmap) FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	 private org.eclipse.gmf.runtime.notation.View getFontStyleOwnerView() {
		«IF viewmap.isFixedFont()-»
		return (org.eclipse.gmf.runtime.notation.View) getModel();
		«ELSE-»
		return getPrimaryView();
		«ENDIF-»
	 }
«ENDDEFINE»

«DEFINE getOclTracker FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker getTracker() {
		return ((org.eclipse.gmf.tooling.runtime.ocl.tracker.HasOclTracker) getParser()).getOclTracker();
	}
«ENDDEFINE»

«DEFINE getOclRegistrator FOR gmfgen::GenCommonBase-»
	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker.Registrator getOclRegistrator() {
		if (myOclRegistrator == null) {
			myOclRegistrator = new org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker.Registrator() {

				«EXPAND CodeStyle::overrideI-»
				public void registerListener(String filterId, org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener listener, org.eclipse.emf.ecore.EObject element) {
					addListenerFilter(filterId, listener, element);
 				}

				«EXPAND CodeStyle::overrideI-»
				public void unregisterListener(String filterId) {
					removeListenerFilter(filterId);
				}
			};
		}
		return myOclRegistrator;
	}
«ENDDEFINE»

Back to the top