Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b8f6174c347df9c545177c64e35f26ae57603b21 (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
/*****************************************************************************
 * Copyright (c) 2006, 2009, 2013, 2021 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
 * Michael Golubev (Montages) - #386838 - migrate to Xtend2
 * Etienne Allogo (ARTAL) - etienne.allogo@artal.fr - Bug 569174 : 1.4 Merge papyrus extension templates into codegen.xtend
 *****************************************************************************/
package diagram.editparts

import com.google.inject.Inject
import com.google.inject.Singleton
import impl.diagram.editparts.TextAwareExtent
import org.eclipse.papyrus.gmf.codegen.gmfgen.CustomBehaviour
import org.eclipse.papyrus.gmf.codegen.gmfgen.GenLinkLabel
import org.eclipse.papyrus.gmf.codegen.gmfgen.LinkLabelAlignment
import xpt.Common
import xpt.diagram.ViewmapAttributesUtils_qvto
import xpt.editor.VisualIDRegistry
import xpt.CodeStyle
import org.eclipse.papyrus.gmf.codegen.gmfgen.ParentAssignedViewmap

@Singleton class LinkLabelEditPart {
	@Inject extension Common;
	@Inject extension CodeStyle;
	
	@Inject TextAwareExtent xptTextAware;
	@Inject xpt.diagram.editparts.Common xptEditpartsCommon;
	@Inject VisualIDRegistry xptVisualIDRegistry;
	@Inject extension ViewmapAttributesUtils_qvto;

	def className(GenLinkLabel it) '''«editPartClassName»'''

	def Main(GenLinkLabel it) '''
		«copyright(getDiagram().editorGen)»
		package «packageName(it)»;
		
		«generatedClassComment»
		public class «className(it)» «extendsList(it)» «implementsList(it)» {
		
			«attributes(it)»

			«initializer(it)»
			«constructor(it)»
			«createDefaultEditPolicies(it)»
			«getKeyPointExtent(it)»
			«xptTextAware.getLabelIconNotUseElementIcon(it, elementIcon, diagram)»
			«xptTextAware.methodsExtent(it, false, readOnly, modelFacet, link)»
			«handleNotificationEvent(it)»
			«IF !(viewmap instanceof ParentAssignedViewmap /* default overriden */)»
				«xptEditpartsCommon.labelFigure(it.viewmap)»
			«ENDIF»
			
			«additions(it)»
		}
	'''

	def packageName(GenLinkLabel it) '''«getDiagram().editPartsPackageName»'''

	def initializer(GenLinkLabel it) '''
		«generatedMemberComment»
		static {
			registerSnapBackPosition(«xptVisualIDRegistry.typeMethodCall(it)», new org.eclipse.draw2d.geometry.Point(«labelOffsetX(viewmap, 0)», «labelOffsetY(viewmap, 0)»));
		}
	'''
	
	def qualifiedClassName(GenLinkLabel it) '''«packageName(it)».«className(it)»'''

	def fullPath(GenLinkLabel it) '''«qualifiedClassName(it)»'''

	
	def extendsList(GenLinkLabel it) '''extends org.eclipse.papyrus.uml.diagram.common.editparts.AbstractLinkLabelEditPart'''

	def implementsList(GenLinkLabel it) '''
		«/* BEGIN:	PapyrusGenCode */IF labelVisibilityPreference !== null»
			implements org.eclipse.papyrus.uml.diagram.common.editparts.ILabelRoleProvider
		«/* END:	PapyrusGenCode */ENDIF»
	'''

	def attributes(GenLinkLabel it) '''
		«xptEditpartsCommon.visualIDConstant(it)»
	'''


	def constructor(GenLinkLabel it) '''
		«generatedMemberComment»
		public «className(it)»(org.eclipse.gmf.runtime.notation.View view) {
			super(view);
		}
	'''


	def getKeyPointExtent(GenLinkLabel it) '''
		«IF alignment != LinkLabelAlignment.MIDDLE_LITERAL»
			«generatedMemberComment»
			«overrideC»
			public int getKeyPoint() {
				return org.eclipse.draw2d.ConnectionLocator.«alignment»;
			}
		«ENDIF»
	'''

	def createDefaultEditPolicies(GenLinkLabel it) '''
		/**
		 * @generated Papyrus Generation
		 */
		«overrideC»
		protected void createDefaultEditPolicies() {	
			super.createDefaultEditPolicies();
			installEditPolicy(org.eclipse.gef.EditPolicy.DIRECT_EDIT_ROLE, new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy());
			installEditPolicy(org.eclipse.gef.EditPolicy.SELECTION_FEEDBACK_ROLE, new org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextSelectionEditPolicy());
			installEditPolicy(org.eclipse.gef.EditPolicy.PRIMARY_DRAG_ROLE, new org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusLinkLabelDragPolicy());
			«FOR CustomBehaviour:it.behaviour.filter(typeof (CustomBehaviour))
			// Get the added custom behavoir
			»
			installEditPolicy(«CustomBehaviour.key», new «CustomBehaviour.editPolicyQualifiedClassName»());
			«ENDFOR»
		}
	'''

	def handleNotificationEvent(GenLinkLabel it) '''
		«IF elementIcon»
			«generatedMemberComment»
			«overrideC»
			protected void handleNotificationEvent(org.eclipse.emf.common.notify.Notification event) {
				if(event.getNewValue() instanceof org.eclipse.emf.ecore.EAnnotation && org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((org.eclipse.emf.ecore.EAnnotation)event.getNewValue()).getSource())){	
					refreshLabel();
				}
				super.handleNotificationEvent(event);
			}
		«ENDIF»
	'''

	def additions(GenLinkLabel it) '''
		«IF labelVisibilityPreference !== null»
			«generatedClassComment»
			«overrideI»
			public String getLabelRole(){
				return "«labelVisibilityPreference.role»";//$NON-NLS-1$
			}

			«generatedClassComment»
			«overrideI»
			public String getIconPathRole(){
				return "«labelVisibilityPreference.iconPathRole»";//$NON-NLS-1$
			}
		«ENDIF»
 	'''
}

Back to the top