422
|
1 |
/*
|
|
2 |
* Copyright (c) 2007, 2008 Borland Software Corporation
|
|
3 |
*
|
|
4 |
* All rights reserved. This program and the accompanying materials
|
|
5 |
* are made available under the terms of the Eclipse Public License v1.0
|
|
6 |
* which accompanies this distribution, and is available at
|
|
7 |
* http://www.eclipse.org/legal/epl-v10.html
|
|
8 |
*
|
|
9 |
* Contributors:
|
|
10 |
* bblajer (Borland) - initial API and implementation
|
|
11 |
*/
|
|
12 |
|
|
13 |
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
|
|
14 |
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
|
|
15 |
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
|
|
16 |
«EXTENSION xpt::GenModelUtils»
|
|
17 |
«EXTENSION xpt::diagram::LinkFinder»
|
|
18 |
«EXTENSION xpt::diagram::parts::LinkNotationModelRefresher»
|
|
19 |
|
|
20 |
«DEFINE installClause FOR gmfgen::GenCommonBase-»
|
|
21 |
«IF needsLinkNotationModelRefresher()-»
|
|
22 |
installLinkNotationModelRefresher();
|
|
23 |
«ENDIF-»
|
|
24 |
«ENDDEFINE»
|
|
25 |
|
|
26 |
«DEFINE uninstallClause FOR gmfgen::GenCommonBase-»
|
|
27 |
«IF needsLinkNotationModelRefresher()-»
|
|
28 |
uninstallLinkNotationModelRefresher();
|
|
29 |
«ENDIF-»
|
|
30 |
«ENDDEFINE»
|
|
31 |
|
|
32 |
«DEFINE all FOR gmfgen::GenCommonBase-»
|
|
33 |
«IF needsLinkNotationModelRefresher()-»
|
|
34 |
«EXPAND install-»
|
|
35 |
«EXPAND uninstall-»
|
|
36 |
«EXPAND getLinkNotationModelRefresher-»
|
|
37 |
«EXPAND viewService-»
|
|
38 |
«EXPAND refresh-»
|
|
39 |
«EXPAND LinkNotationModelRefresher-»
|
|
40 |
«ENDIF-»
|
|
41 |
«ENDDEFINE»
|
|
42 |
|
|
43 |
«DEFINE className FOR gmfgen::GenCommonBase»LinkNotationModelRefresher«ENDDEFINE»
|
|
44 |
|
|
45 |
«DEFINE install FOR gmfgen::GenCommonBase-»
|
|
46 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
47 |
private void installLinkNotationModelRefresher() {
|
|
48 |
«EXPAND className» refresher = getLinkNotationModelRefresher();
|
|
49 |
if (!getTransactionalUpdateManager().isNotationModelRefresherInstalled(refresher)) {
|
|
50 |
getTransactionalUpdateManager().addNotationModelRefresher(refresher);
|
|
51 |
try {
|
|
52 |
refreshLinkNotationModel();
|
|
53 |
} catch (java.lang.IllegalStateException readOnlyContext) {
|
|
54 |
//Most likely, this means that the host element was created in a precommit notification of a transaction.
|
|
55 |
//While it is impossible to execute this command here, it will be executed as a trigger command.
|
|
56 |
//See org.eclipse.gmf.runtime.lite.edit.parts.update.TransactionalUpdateManager for details.
|
|
57 |
}
|
|
58 |
}
|
|
59 |
}
|
|
60 |
«ENDDEFINE»
|
|
61 |
|
|
62 |
«DEFINE uninstall FOR gmfgen::GenCommonBase-»
|
|
63 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
64 |
private void uninstallLinkNotationModelRefresher() {
|
|
65 |
«EXPAND className» refresher = getLinkNotationModelRefresher();
|
|
66 |
getTransactionalUpdateManager().removeNotationModelRefresher(refresher);
|
|
67 |
}
|
|
68 |
«ENDDEFINE»
|
|
69 |
|
|
70 |
«DEFINE getLinkNotationModelRefresher FOR gmfgen::GenCommonBase-»
|
|
71 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
72 |
private «EXPAND className» linkNotationModelRefresher;
|
|
73 |
|
|
74 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
75 |
private «EXPAND className» getLinkNotationModelRefresher() {
|
|
76 |
if (linkNotationModelRefresher == null) {
|
|
77 |
linkNotationModelRefresher = new «EXPAND className»(getViewService());
|
|
78 |
}
|
|
79 |
return linkNotationModelRefresher;
|
|
80 |
}
|
|
81 |
«ENDDEFINE»
|
|
82 |
|
|
83 |
«DEFINE viewService FOR gmfgen::GenCommonBase-»
|
|
84 |
«EXPAND xpt::Common::generatedMemberComment("Service to find a notational element that corresponds to the given underlying domain element.")»
|
|
85 |
private org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.IViewService viewService;
|
|
86 |
|
|
87 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
88 |
private org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.IViewService getViewService() {
|
|
89 |
if (viewService == null) {
|
|
90 |
viewService = new org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.EditPartRegistryBasedViewService(getViewer());
|
|
91 |
}
|
|
92 |
return viewService;
|
|
93 |
}
|
|
94 |
«ENDDEFINE»
|
|
95 |
|
|
96 |
«DEFINE refresh FOR gmfgen::GenCommonBase-»
|
|
97 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
98 |
protected void refreshLinkNotationModel() {
|
|
99 |
«EXPAND className» linkRefresher = getLinkNotationModelRefresher();
|
|
100 |
org.eclipse.emf.common.command.Command command = linkRefresher.buildRefreshNotationModelCommand();
|
|
101 |
if (command == null) {
|
|
102 |
return;
|
|
103 |
}
|
|
104 |
org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(«EXPAND xpt::diagram::parts::Common::getDiagramElementCode»);
|
|
105 |
getViewer().getEditDomain().getCommandStack().execute(new org.eclipse.gmf.runtime.lite.commands.WrappingCommand(domainModelEditDomain, command));
|
|
106 |
}
|
|
107 |
«ENDDEFINE»
|
|
108 |
|
|
109 |
«DEFINE LinkNotationModelRefresher FOR gmfgen::GenCommonBase-»
|
|
110 |
«EXPAND xpt::Common::generatedClassComment»
|
|
111 |
private class «EXPAND className» «EXPAND supertypes» {
|
|
112 |
«EXPAND ctors-»
|
|
113 |
«EXPAND getConstrainedChildrenFilter-»
|
|
114 |
«EXPAND createUncontainedLinksFilter-»
|
|
115 |
«EXPAND createFilter-»
|
|
116 |
«EXPAND getSemanticLinks-»
|
|
117 |
«EXPAND getNotationalLinks-»
|
|
118 |
«EXPAND getCreateNotationalElementCommand-»
|
|
119 |
«EXPAND shouldCreateView-»
|
|
120 |
«EXPAND getHost-»
|
|
121 |
«EXPAND additions-»
|
|
122 |
}
|
|
123 |
«ENDDEFINE»
|
|
124 |
|
|
125 |
«DEFINE supertypes FOR gmfgen::GenCommonBase»extends org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.OwnedLinksNotationModelRefresher«ENDDEFINE»
|
|
126 |
|
|
127 |
«DEFINE ctors FOR gmfgen::GenCommonBase-»
|
|
128 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
129 |
public «EXPAND className»(org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.IViewService viewService) {
|
|
130 |
super(viewService);
|
|
131 |
}
|
|
132 |
«ENDDEFINE»
|
|
133 |
|
|
134 |
«DEFINE getConstrainedChildrenFilter FOR gmfgen::GenCommonBase-»
|
|
135 |
«IF containedLinksWithSelector().size() > 0-»
|
|
136 |
«EXPAND xpt::Common::generatedMemberComment("TODO: Child links of this element are selected based on constraint declared in " + getDiagram().getVisualIDRegistryQualifiedClassName() + ". \n" +
|
|
137 |
"Since no assumptions may be made concerning the runtime behavior of the constraint, <b>any</b> non-touch notification may result in \n" +
|
|
138 |
"notational model having to be updated.\n" +
|
|
139 |
"<p/>User is encouraged to change implementation of this method to provide an optimization if it is safe to assume that not all notifications\n" +
|
|
140 |
"result in such an update.")»
|
|
141 |
private org.eclipse.emf.transaction.NotificationFilter getConstrainedChildLinksFilter() {
|
|
142 |
return org.eclipse.emf.transaction.NotificationFilter.NOT_TOUCH;
|
|
143 |
}
|
|
144 |
«ENDIF-»
|
|
145 |
«ENDDEFINE»
|
|
146 |
|
|
147 |
«DEFINE createUncontainedLinksFilter FOR gmfgen::GenCommonBase-»
|
|
148 |
«ENDDEFINE»
|
|
149 |
|
|
150 |
«DEFINE createUncontainedLinksFilter FOR gmfgen::GenDiagram-»
|
|
151 |
«EXPAND xpt::Common::generatedMemberComment("Creates a notification filter which filters notifications that may possibly result in uncontained links. ")»
|
|
152 |
private org.eclipse.emf.transaction.NotificationFilter createUncontainedLinksFilter() {
|
|
153 |
return org.eclipse.emf.transaction.NotificationFilter.createEventTypeFilter(org.eclipse.emf.common.notify.Notification.SET).or(
|
|
154 |
org.eclipse.emf.transaction.NotificationFilter.createEventTypeFilter(org.eclipse.emf.common.notify.Notification.UNSET).or(
|
|
155 |
org.eclipse.emf.transaction.NotificationFilter.createEventTypeFilter(org.eclipse.emf.common.notify.Notification.REMOVE).or(
|
|
156 |
org.eclipse.emf.transaction.NotificationFilter.createEventTypeFilter(org.eclipse.emf.common.notify.Notification.REMOVE_MANY)
|
|
157 |
)));
|
|
158 |
}
|
|
159 |
«ENDDEFINE»
|
|
160 |
|
|
161 |
«DEFINE createFilter FOR gmfgen::GenCommonBase-»
|
|
162 |
«EXPAND xpt::Common::generatedMemberComment("Creates a notification filter which filters notifications that may possibly affect the notational model")»
|
|
163 |
protected org.eclipse.emf.transaction.NotificationFilter createFilter() {
|
|
164 |
«LET getAffectingFeatures() AS affectingFeatures-»
|
|
165 |
«FOREACH affectingFeatures AS nextFeature ITERATOR it-»
|
|
166 |
«IF it.isFirstIteration()»org.eclipse.emf.transaction.NotificationFilter filter = «EXPAND createFeatureFilter FOR nextFeature»;«ELSE-»
|
|
167 |
filter = filter.or(«EXPAND createFeatureFilter FOR nextFeature»);«ENDIF-»
|
|
168 |
«ENDFOREACH-»
|
|
169 |
«IF containedLinksWithSelector().size() > 0-»
|
|
170 |
«IF affectingFeatures.size() > 0-»
|
|
171 |
filter = getConstrainedChildLinksFilter().or(filter);
|
|
172 |
«ELSE-»
|
|
173 |
org.eclipse.emf.transaction.NotificationFilter filter = getConstrainedChildLinksFilter();
|
|
174 |
«ENDIF-»
|
|
175 |
«ENDIF-»
|
|
176 |
«IF {this}.typeSelect(gmfgen::GenDiagram).size() > 0-»
|
|
177 |
«IF affectingFeatures.size() + containedLinksWithSelector().size() > 0-»
|
|
178 |
filter = filter.or(createUncontainedLinksFilter());
|
|
179 |
«ELSE-»
|
|
180 |
org.eclipse.emf.transaction.NotificationFilter filter = createUncontainedLinksFilter();
|
|
181 |
«ENDIF-»
|
|
182 |
«ELSE-»
|
|
183 |
«REM»Make sure filter var is declared«ENDREM-»
|
|
184 |
«IF affectingFeatures.size() + containedLinksWithSelector().size() == 0-»
|
|
185 |
org.eclipse.emf.transaction.NotificationFilter filter = org.eclipse.emf.transaction.NotificationFilter.NOT_TOUCH;
|
|
186 |
«ENDIF-»
|
|
187 |
«ENDIF-»
|
|
188 |
«ENDLET-»
|
|
189 |
return filter;
|
|
190 |
}
|
|
191 |
«ENDDEFINE»
|
|
192 |
|
|
193 |
«DEFINE createFeatureFilter FOR genmodel::GenFeature»org.eclipse.emf.transaction.NotificationFilter.createFeatureFilter(«EXPAND MetaModel::MetaFeature»)«ENDDEFINE»
|
|
194 |
|
|
195 |
«DEFINE getSemanticLinks FOR gmfgen::GenCommonBase-»
|
|
196 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
197 |
protected java.util.List getSemanticChildLinks() {
|
|
198 |
«EXPAND xpt::diagram::parts::semanticChildLinks::semanticChildLinks("getHost()")-»
|
|
199 |
}
|
|
200 |
«ENDDEFINE»
|
|
201 |
|
|
202 |
«DEFINE getNotationalLinks FOR gmfgen::GenCommonBase-»
|
|
203 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
204 |
protected java.util.List getNotationalChildLinks() {
|
|
205 |
java.util.List result = new java.util.LinkedList();
|
|
206 |
java.util.List allLinks = «EXPAND xpt::diagram::parts::Common::getDiagramCode».getEdges();
|
|
207 |
for(java.util.Iterator it = allLinks.iterator(); it.hasNext(); ) {
|
|
208 |
org.eclipse.gmf.runtime.notation.Edge next = (org.eclipse.gmf.runtime.notation.Edge) it.next();
|
|
209 |
«EXPAND uncontainedLinks-»
|
|
210 |
«EXPAND containedFeatureModelLinks-»
|
|
211 |
«EXPAND containedTypeModelLinks-»
|
|
212 |
}
|
|
213 |
return result;
|
|
214 |
}
|
|
215 |
«ENDDEFINE»
|
|
216 |
|
|
217 |
«DEFINE uncontainedLinks FOR gmfgen::GenCommonBase»«ENDDEFINE»
|
|
218 |
|
|
219 |
«DEFINE uncontainedLinks FOR gmfgen::GenDiagram-»
|
|
220 |
if (next.isSetElement() && next.getElement() != null && next.getElement().eResource() == null) {
|
|
221 |
result.add(next);
|
|
222 |
continue;
|
|
223 |
}
|
|
224 |
org.eclipse.gmf.runtime.notation.View source = next.getSource();
|
|
225 |
if (source == null || (source.isSetElement() && source.getElement() != null && source.getElement().eResource() == null)) {
|
|
226 |
result.add(next);
|
|
227 |
continue;
|
|
228 |
}
|
|
229 |
org.eclipse.gmf.runtime.notation.View target = next.getTarget();
|
|
230 |
if (target == null || (target.isSetElement() && target.getElement() != null && target.getElement().eResource() == null)) {
|
|
231 |
result.add(next);
|
|
232 |
continue;
|
|
233 |
}
|
|
234 |
«ENDDEFINE»
|
|
235 |
|
|
236 |
«DEFINE containedFeatureModelLinks FOR gmfgen::GenCommonBase-»
|
|
237 |
«IF containedFeatureModelFacetLinks().size() > 0-»
|
|
238 |
if (next.isSetElement() && next.getElement() == null) {
|
|
239 |
if (next.getSource() == getHost()) {
|
|
240 |
int linkVID = «getDiagram().getVisualIDRegistryQualifiedClassName()».getVisualID(next);
|
|
241 |
switch (linkVID) {
|
|
242 |
«EXPAND caseVisualId FOREACH containedFeatureModelFacetLinks()-»
|
|
243 |
result.add(next);
|
|
244 |
break;
|
|
245 |
}
|
|
246 |
}
|
|
247 |
}
|
|
248 |
«ENDIF-»
|
|
249 |
«ENDDEFINE»
|
|
250 |
|
|
251 |
«DEFINE containedTypeModelLinks FOR gmfgen::GenCommonBase-»
|
|
252 |
«IF containedTypeModelFacetLinks().size() > 0-»
|
|
253 |
if (next.isSetElement() && next.getElement() != null) {
|
|
254 |
if (next.getElement().eContainer() == «EXPAND xpt::diagram::parts::Common::getViewCode».getElement()) {
|
|
255 |
int linkVID = «getDiagram().getVisualIDRegistryQualifiedClassName()».getVisualID(next);
|
|
256 |
switch (linkVID) {
|
|
257 |
«EXPAND caseVisualId FOREACH containedTypeModelFacetLinks()-»
|
|
258 |
result.add(next);
|
|
259 |
break;
|
|
260 |
}
|
|
261 |
}
|
|
262 |
}
|
|
263 |
«ENDIF-»
|
|
264 |
«ENDDEFINE»
|
|
265 |
|
|
266 |
«DEFINE caseVisualId FOR gmfgen::GenLink-»
|
|
267 |
case «getEditPartQualifiedClassName()».VISUAL_ID:
|
|
268 |
«ENDDEFINE»
|
|
269 |
|
|
270 |
«DEFINE getCreateNotationalElementCommand FOR gmfgen::GenCommonBase-»
|
|
271 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
272 |
protected org.eclipse.gmf.runtime.lite.commands.CreateNotationalElementCommand getCreateNotationalElementCommand(org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.ElementDescriptor descriptor) {
|
|
273 |
«IF primNeedsLinkNotationModelRefresher()-»
|
|
274 |
org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.LinkDescriptor linkDescriptor = (org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.LinkDescriptor) descriptor;
|
|
275 |
«EXPAND xpt::commands::createNotationalElementCommand::defineDecorator-»
|
|
276 |
«IF getDiagram().shortcutsProvidedFor.size() > 0-»
|
|
277 |
String diagramModelID = «getDiagram().getVisualIDRegistryQualifiedClassName()».getModelID(getHost().getDiagram());
|
|
278 |
if (!«getDiagram().getEditPartQualifiedClassName()».MODEL_ID.equals(diagramModelID)) {
|
|
279 |
return new «EXPAND xpt::commands::CreateShortcutEdgeCommand::qualifiedClassName FOR getDiagram()»(getHost().getDiagram(), linkDescriptor.getElement(), sourceView, targetView, decorator);
|
|
280 |
}
|
|
281 |
«ENDIF-»
|
|
282 |
«EXPAND xpt::commands::createNotationalElementCommand::instantiateNotationalEdgeCommand("getHost().getDiagram()")-»
|
|
283 |
«ELSE-»
|
|
284 |
return null;
|
|
285 |
«ENDIF-»
|
|
286 |
}
|
|
287 |
«ENDDEFINE»
|
|
288 |
|
|
289 |
«DEFINE shouldCreateView FOR gmfgen::GenCommonBase-»
|
|
290 |
«EXPAND xpt::Common::generatedMemberComment("Returns whether a notational edge should be created for the given domain element. \n" +
|
|
291 |
"The generated code respects canonical style. If the canonycal style is not present, " + (getDiagram().synchronized ? "true" : "false") + " is always returned. \n" +
|
|
292 |
"User can change implementation of this method to handle a more sophisticated logic.")»
|
|
293 |
protected boolean shouldCreateView(org.eclipse.gmf.runtime.lite.edit.parts.update.canonical.ElementDescriptor descriptor) {
|
|
294 |
org.eclipse.gmf.runtime.notation.CanonicalStyle style = (org.eclipse.gmf.runtime.notation.CanonicalStyle) «EXPAND xpt::diagram::parts::Common::getViewCode».getStyle(org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getCanonicalStyle());
|
|
295 |
if (style == null) {
|
|
296 |
return «getDiagram().synchronized»;
|
|
297 |
}
|
|
298 |
return style.isCanonical();
|
|
299 |
}
|
|
300 |
«ENDDEFINE»
|
|
301 |
|
|
302 |
«DEFINE getHost FOR gmfgen::GenCommonBase-»
|
|
303 |
«EXPAND xpt::Common::generatedMemberComment»
|
|
304 |
protected org.eclipse.gmf.runtime.notation.View getHost() {
|
|
305 |
return «EXPAND xpt::diagram::parts::Common::getViewCode»;
|
|
306 |
}
|
|
307 |
«ENDDEFINE»
|
|
308 |
|
|
309 |
«DEFINE additions FOR gmfgen::GenCommonBase»«ENDDEFINE»
|