Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d39bc264f7a82528a5d91d8942516eaea79ebcd8 (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
/**
 * Copyright (c) 2006, 2009 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 *    Alexander Shatalin (Borland) - initial API and implementation
 *    Michael Golubev (Montages) - #386838 - migrate to Xtend2
 */
package impl.diagram.editparts

import com.google.inject.Inject
import xpt.Common
import xpt.diagram.editparts.Utils_qvto
import org.eclipse.gmf.codegen.gmfgen.GenCompartment
import xpt.Externalizer
import xpt.Common_qvto
import org.eclipse.gmf.codegen.gmfgen.ViewmapLayoutType
import org.eclipse.gmf.codegen.gmfgen.GenDiagram
import org.eclipse.gmf.codegen.xtend.annotations.Localization
import xpt.providers.ElementTypes

@com.google.inject.Singleton class CompartmentEditPart {
	@Inject extension Common;
	@Inject extension Common_qvto;

	@Inject extension Utils_qvto;

	@Inject Externalizer xptExternalizer;
	@Inject xpt.diagram.editparts.Common xptEditpartsCommon;
	@Inject ElementTypes xptElementTypes;

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

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

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

	def hasModelChildrenChanged(GenCompartment it) '''
		«IF listLayout»
			«generatedMemberComment»
			protected boolean hasModelChildrenChanged(org.eclipse.emf.common.notify.Notification evt) {
				return false;
			}
		«ENDIF»
	'''

	def getCompartmentName(GenCompartment it) '''
		«generatedMemberComment»
		public String getCompartmentName() {
			return «xptExternalizer.accessorCall(diagram.editorGen, i18nKeyForCompartmentTitle(it))»;
		}
	'''

	def createFigure(GenCompartment it) '''
		«IF !needsTitle»
			«/*By default titles are shown even if there are no TitleStyle, we need to switch it off*/generatedMemberComment»
			public org.eclipse.draw2d.IFigure createFigure() {
				org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure result = (org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure) super.createFigure();
				result.setTitleVisibility(false);
				return result;
			}
		«ENDIF»
	'''

	def createDefaultEditPoliciesBody(GenCompartment it) '''
		super.createDefaultEditPolicies();
		«IF canCollapse»
			installEditPolicy(org.eclipse.gef.EditPolicy.PRIMARY_DRAG_ROLE, new org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy());
		«ENDIF»
		«xptEditpartsCommon.installSemanticEditPolicy(it)»
		«IF childNodes.notEmpty»
			«xptEditpartsCommon.installCreationEditPolicy(it)»
			installEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.DRAG_DROP_ROLE, new org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy());
		«ENDIF»
		«xptEditpartsCommon.installCanonicalEditPolicy(it)»
		«xptEditpartsCommon.behaviour(it)»
	'''

	def refreshVisuals(GenCompartment it) '''
		«IF isStoringChildPositions(node)»
			«generatedMemberComment»
			protected void refreshVisuals() {
				super.refreshVisuals();
				refreshBounds();
			}
		«ENDIF»
	'''

	def handleNotificationEventBody(GenCompartment it) '''
		super.handleNotificationEvent(notification);
		Object feature = notification.getFeature();
		if (org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getSize_Width().equals(feature)
				|| org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getSize_Height().equals(feature)
				|| org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getLocation_X().equals(feature)
				|| org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getLocation_Y().equals(feature)) {
			refreshBounds();
		} 
	'''

	def refreshBounds(GenCompartment it) '''
		«IF isStoringChildPositions(node)»
			«generatedMemberComment»
			protected void refreshBounds() {
				int x = ((Integer) getStructuralFeatureValue(org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getLocation_X())).intValue();
				int y = ((Integer) getStructuralFeatureValue(org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getLocation_Y())).intValue();
				int width = ((Integer) getStructuralFeatureValue(org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getSize_Width())).intValue();
				int height = ((Integer) getStructuralFeatureValue(org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getSize_Height())).intValue();
				((org.eclipse.gef.GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new org.eclipse.draw2d.geometry.Rectangle(x, y, width, height));
			}
		«ENDIF»
	'''

	def setRatio(GenCompartment it) '''
		«generatedMemberComment»
		protected void setRatio(Double ratio) {
			«IF ViewmapLayoutType::UNKNOWN_LITERAL == node.layoutType»
				if (getFigure().getParent().getLayoutManager() instanceof org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout) {
					super.setRatio(ratio);
				}
			«ELSE»
				// nothing to do -- parent layout does not accept Double constraints as ratio
				// super.setRatio(ratio); 
			«ENDIF»
		}
	'''

	def getTargetEditPartMethod(GenCompartment it) '''
		«generatedMemberComment»
		public org.eclipse.gef.EditPart getTargetEditPart(org.eclipse.gef.Request request) {
			if (request instanceof org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest) {
				org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter adapter = ((org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
				org.eclipse.gmf.runtime.emf.type.core.IElementType type = (org.eclipse.gmf.runtime.emf.type.core.IElementType) adapter.getAdapter(org.eclipse.gmf.runtime.emf.type.core.IElementType.class);
				«FOR childNode : it.childNodes»
					if (type == «xptElementTypes.accessElementType(childNode)») {
						return this;
					}
				«ENDFOR»
			«IF listCompartmentHasChildren(it)»
			}
			return getParent().getTargetEditPart(request);
			«ELSE»
				return getParent().getTargetEditPart(request);
			}
			return super.getTargetEditPart(request);
			«ENDIF»
		}
	'''

	@Localization def i18nAccessors(GenDiagram it) '''
	«FOR compartment : it.compartments»
		«internal_i18nAccessors(compartment)»
	«ENDFOR»
	'''

	@Localization def internal_i18nAccessors(GenCompartment it) //
	'''«IF null != title»«xptExternalizer.accessorField(i18nKeyForCompartmentTitle(it))»«ENDIF»'''

	@Localization def i18nValues(GenDiagram it) '''
		«FOR compartment : it.compartments»
			«internal_i18nValues(compartment)»
		«ENDFOR»
	'''

	@Localization def internal_i18nValues(GenCompartment it) '''
		«IF null != title»«xptExternalizer.messageEntry(i18nKeyForCompartmentTitle(it), title)»«ENDIF»
	'''

	@Localization def String i18nKeyForCompartmentTitle(GenCompartment compartment) {
		return className(compartment) + '.title'
	}
	

}

Back to the top