001: package newprocess.diagram.edit.policies;
002:
003: import java.util.List;
004: import java.util.Collection;
005: import org.eclipse.gmf.runtime.notation.Edge;
006: import org.eclipse.emf.ecore.EObject;
007: import java.util.Collections;
008: import java.util.HashMap;
009: import java.util.Iterator;
010: import java.util.LinkedList;
011: import java.util.Map;
012:
013: import newprocess.AsyncActivity;
014: import newprocess.Conclusion;
015: import newprocess.ConditionTerm;
016: import newprocess.Expansion;
017: import newprocess.NewprocessPackage;
018: import newprocess.OperatorTerm;
019: import newprocess.Process;
020: import newprocess.Root;
021:
022: import newprocess.diagram.edit.parts.ActorEditPart;
023: import newprocess.diagram.edit.parts.AndOperatorEditPart;
024: import newprocess.diagram.edit.parts.AsyncActivity2EditPart;
025: import newprocess.diagram.edit.parts.AsyncActivityActorEditPart;
026: import newprocess.diagram.edit.parts.AsyncActivityEditPart;
027: import newprocess.diagram.edit.parts.ConclusionConclusionProxyEditPart;
028: import newprocess.diagram.edit.parts.ConclusionEditPart;
029: import newprocess.diagram.edit.parts.ConditionEditPart;
030: import newprocess.diagram.edit.parts.ConditionProxyEditPart;
031: import newprocess.diagram.edit.parts.ConditionTermConditionProxyEditPart;
032: import newprocess.diagram.edit.parts.ConditionTermEditPart;
033: import newprocess.diagram.edit.parts.EventEditPart;
034: import newprocess.diagram.edit.parts.ExpansionEditPart;
035: import newprocess.diagram.edit.parts.ExpansionExpansionProxyEditPart;
036: import newprocess.diagram.edit.parts.Expression2EditPart;
037: import newprocess.diagram.edit.parts.Expression3EditPart;
038: import newprocess.diagram.edit.parts.Expression4EditPart;
039: import newprocess.diagram.edit.parts.Expression5EditPart;
040: import newprocess.diagram.edit.parts.Expression6EditPart;
041: import newprocess.diagram.edit.parts.Expression7EditPart;
042: import newprocess.diagram.edit.parts.Expression8EditPart;
043: import newprocess.diagram.edit.parts.ExpressionEditPart;
044: import newprocess.diagram.edit.parts.GlobalsEditPart;
045: import newprocess.diagram.edit.parts.ListenerEditPart;
046: import newprocess.diagram.edit.parts.LoaderEditPart;
047: import newprocess.diagram.edit.parts.MessageEditPart;
048: import newprocess.diagram.edit.parts.OperatorTermSubTermEditPart;
049: import newprocess.diagram.edit.parts.OrOperatorEditPart;
050: import newprocess.diagram.edit.parts.ProcessEditPart;
051: import newprocess.diagram.edit.parts.RootEditPart;
052: import newprocess.diagram.edit.parts.RootTermEditPart;
053: import newprocess.diagram.edit.parts.SyncActivityEditPart;
054:
055: import newprocess.diagram.part.New_processVisualIDRegistry;
056:
057: import newprocess.diagram.providers.New_processElementTypes;
058:
059: import org.eclipse.core.runtime.IAdaptable;
060:
061: import org.eclipse.emf.ecore.EClass;
062:
063: import org.eclipse.gef.EditPart;
064:
065: import org.eclipse.gef.commands.Command;
066:
067: import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
068:
069: import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
070: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
071:
072: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
073:
074: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy;
075:
076: import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
077: import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
078:
079: import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
080:
081: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
082:
083: import org.eclipse.gmf.runtime.notation.Diagram;
084: import org.eclipse.gmf.runtime.notation.View;
085:
086: /**
087: * @generated
088: */
089: public class ProcessCanonicalEditPolicy extends
090: CanonicalConnectionEditPolicy {
091:
092: /**
093: * @generated
094: */
095: protected List getSemanticChildrenList() {
096: List result = new LinkedList();
097: EObject modelObject = ((View) getHost().getModel())
098: .getElement();
099: View viewObject = (View) getHost().getModel();
100: EObject nextValue;
101: int nodeVID;
102: for (Iterator values = ((Process) modelObject)
103: .getHasSyncActivities().iterator(); values.hasNext();) {
104: nextValue = (EObject) values.next();
105: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
106: viewObject, nextValue);
107: if (SyncActivityEditPart.VISUAL_ID == nodeVID) {
108: result.add(nextValue);
109: }
110: }
111: for (Iterator values = ((Process) modelObject)
112: .getHasListeners().iterator(); values.hasNext();) {
113: nextValue = (EObject) values.next();
114: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
115: viewObject, nextValue);
116: if (ListenerEditPart.VISUAL_ID == nodeVID) {
117: result.add(nextValue);
118: }
119: }
120: for (Iterator values = ((Process) modelObject)
121: .getHasAsyncActivities().iterator(); values.hasNext();) {
122: nextValue = (EObject) values.next();
123: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
124: viewObject, nextValue);
125: if (AsyncActivityEditPart.VISUAL_ID == nodeVID) {
126: result.add(nextValue);
127: }
128: }
129: for (Iterator values = ((Process) modelObject).getHasEvents()
130: .iterator(); values.hasNext();) {
131: nextValue = (EObject) values.next();
132: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
133: viewObject, nextValue);
134: if (EventEditPart.VISUAL_ID == nodeVID) {
135: result.add(nextValue);
136: }
137: }
138: for (Iterator values = ((Process) modelObject)
139: .getHasConditionProxy().iterator(); values.hasNext();) {
140: nextValue = (EObject) values.next();
141: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
142: viewObject, nextValue);
143: if (ConditionProxyEditPart.VISUAL_ID == nodeVID) {
144: result.add(nextValue);
145: }
146: }
147: for (Iterator values = ((Process) modelObject).getHasActors()
148: .iterator(); values.hasNext();) {
149: nextValue = (EObject) values.next();
150: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
151: viewObject, nextValue);
152: if (ActorEditPart.VISUAL_ID == nodeVID) {
153: result.add(nextValue);
154: }
155: }
156: for (Iterator values = ((Process) modelObject).getHasMessages()
157: .iterator(); values.hasNext();) {
158: nextValue = (EObject) values.next();
159: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
160: viewObject, nextValue);
161: if (MessageEditPart.VISUAL_ID == nodeVID) {
162: result.add(nextValue);
163: }
164: }
165: for (Iterator values = ((Process) modelObject)
166: .getHasExpansions().iterator(); values.hasNext();) {
167: nextValue = (EObject) values.next();
168: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
169: viewObject, nextValue);
170: if (ExpansionEditPart.VISUAL_ID == nodeVID) {
171: result.add(nextValue);
172: }
173: }
174: for (Iterator values = ((Process) modelObject)
175: .getHasConclusions().iterator(); values.hasNext();) {
176: nextValue = (EObject) values.next();
177: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
178: viewObject, nextValue);
179: if (ConclusionEditPart.VISUAL_ID == nodeVID) {
180: result.add(nextValue);
181: }
182: }
183: nextValue = ((Process) modelObject).getHasGlobals();
184: nodeVID = New_processVisualIDRegistry.getNodeVisualID(
185: viewObject, nextValue);
186: if (GlobalsEditPart.VISUAL_ID == nodeVID) {
187: result.add(nextValue);
188: }
189: return result;
190: }
191:
192: /**
193: * @generated
194: */
195: protected boolean shouldDeleteView(View view) {
196: return view.isSetElement() && view.getElement() != null
197: && view.getElement().eIsProxy();
198: }
199:
200: /**
201: * @generated
202: */
203: protected String getDefaultFactoryHint() {
204: return null;
205: }
206:
207: /**
208: * @generated
209: */
210: protected List getSemanticConnectionsList() {
211: return Collections.EMPTY_LIST;
212: }
213:
214: /**
215: * @generated
216: */
217: protected EObject getSourceElement(EObject relationship) {
218: return null;
219: }
220:
221: /**
222: * @generated
223: */
224: protected EObject getTargetElement(EObject relationship) {
225: return null;
226: }
227:
228: /**
229: * @generated
230: */
231: protected boolean shouldIncludeConnection(Edge connector,
232: Collection children) {
233: return false;
234: }
235:
236: /**
237: * @generated
238: */
239: protected void refreshSemantic() {
240: List createdViews = new LinkedList();
241: createdViews.addAll(refreshSemanticChildren());
242: List createdConnectionViews = new LinkedList();
243: createdConnectionViews.addAll(refreshSemanticConnections());
244: createdConnectionViews.addAll(refreshConnections());
245:
246: if (createdViews.size() > 1) {
247: // perform a layout of the container
248: DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(
249: host().getEditingDomain(), createdViews, host());
250: executeCommand(new ICommandProxy(layoutCmd));
251: }
252:
253: createdViews.addAll(createdConnectionViews);
254: makeViewsImmutable(createdViews);
255: }
256:
257: /**
258: * @generated
259: */
260: private Collection myLinkDescriptors = new LinkedList();
261:
262: /**
263: * @generated
264: */
265: private Map myEObject2ViewMap = new HashMap();
266:
267: /**
268: * @generated
269: */
270: private Collection refreshConnections() {
271: try {
272: collectAllLinks(getDiagram());
273: Collection existingLinks = new LinkedList(getDiagram()
274: .getEdges());
275: for (Iterator diagramLinks = existingLinks.iterator(); diagramLinks
276: .hasNext();) {
277: Edge nextDiagramLink = (Edge) diagramLinks.next();
278: EObject diagramLinkObject = nextDiagramLink
279: .getElement();
280: EObject diagramLinkSrc = nextDiagramLink.getSource()
281: .getElement();
282: EObject diagramLinkDst = nextDiagramLink.getTarget()
283: .getElement();
284: int diagramLinkVisualID = New_processVisualIDRegistry
285: .getVisualID(nextDiagramLink);
286: for (Iterator modelLinkDescriptors = myLinkDescriptors
287: .iterator(); modelLinkDescriptors.hasNext();) {
288: LinkDescriptor nextLinkDescriptor = (LinkDescriptor) modelLinkDescriptors
289: .next();
290: if (diagramLinkObject == nextLinkDescriptor
291: .getLinkElement()
292: && diagramLinkSrc == nextLinkDescriptor
293: .getSource()
294: && diagramLinkDst == nextLinkDescriptor
295: .getDestination()
296: && diagramLinkVisualID == nextLinkDescriptor
297: .getVisualID()) {
298: diagramLinks.remove();
299: modelLinkDescriptors.remove();
300: }
301: }
302: }
303: deleteViews(existingLinks.iterator());
304: return createConnections(myLinkDescriptors);
305: } finally {
306: myLinkDescriptors.clear();
307: myEObject2ViewMap.clear();
308: }
309: }
310:
311: /**
312: * @generated
313: */
314: private void collectAllLinks(View view) {
315: EObject modelElement = view.getElement();
316: int diagramElementVisualID = New_processVisualIDRegistry
317: .getVisualID(view);
318: switch (diagramElementVisualID) {
319: case SyncActivityEditPart.VISUAL_ID:
320: case ListenerEditPart.VISUAL_ID:
321: case AsyncActivityEditPart.VISUAL_ID:
322: case EventEditPart.VISUAL_ID:
323: case ConditionProxyEditPart.VISUAL_ID:
324: case ActorEditPart.VISUAL_ID:
325: case MessageEditPart.VISUAL_ID:
326: case ExpansionEditPart.VISUAL_ID:
327: case ConclusionEditPart.VISUAL_ID:
328: case GlobalsEditPart.VISUAL_ID:
329: case ExpressionEditPart.VISUAL_ID:
330: case RootEditPart.VISUAL_ID:
331: case OrOperatorEditPart.VISUAL_ID:
332: case AndOperatorEditPart.VISUAL_ID:
333: case ConditionTermEditPart.VISUAL_ID:
334: case Expression2EditPart.VISUAL_ID:
335: case Expression3EditPart.VISUAL_ID:
336: case Expression4EditPart.VISUAL_ID:
337: case Expression5EditPart.VISUAL_ID:
338: case Expression6EditPart.VISUAL_ID:
339: case Expression7EditPart.VISUAL_ID:
340: case Expression8EditPart.VISUAL_ID:
341: case LoaderEditPart.VISUAL_ID:
342: case ConditionEditPart.VISUAL_ID:
343: case ProcessEditPart.VISUAL_ID: {
344: myEObject2ViewMap.put(modelElement, view);
345: storeLinks(modelElement, getDiagram());
346: }
347: default: {
348: }
349: for (Iterator children = view.getChildren().iterator(); children
350: .hasNext();) {
351: View childView = (View) children.next();
352: collectAllLinks(childView);
353: }
354: }
355: }
356:
357: /**
358: * @generated
359: */
360: private Collection createConnections(Collection linkDescriptors) {
361: if (linkDescriptors.isEmpty()) {
362: return Collections.EMPTY_LIST;
363: }
364: List adapters = new LinkedList();
365: for (Iterator linkDescriptorsIterator = linkDescriptors
366: .iterator(); linkDescriptorsIterator.hasNext();) {
367: final LinkDescriptor nextLinkDescriptor = (LinkDescriptor) linkDescriptorsIterator
368: .next();
369: EditPart sourceEditPart = getEditPartFor(nextLinkDescriptor
370: .getSource());
371: EditPart targetEditPart = getEditPartFor(nextLinkDescriptor
372: .getDestination());
373: if (sourceEditPart == null || targetEditPart == null) {
374: continue;
375: }
376: CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
377: nextLinkDescriptor.getSemanticAdapter(), null,
378: ViewUtil.APPEND, false,
379: ((IGraphicalEditPart) getHost())
380: .getDiagramPreferencesHint());
381: CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(
382: descriptor);
383: ccr.setType(RequestConstants.REQ_CONNECTION_START);
384: ccr.setSourceEditPart(sourceEditPart);
385: sourceEditPart.getCommand(ccr);
386: ccr.setTargetEditPart(targetEditPart);
387: ccr.setType(RequestConstants.REQ_CONNECTION_END);
388: Command cmd = targetEditPart.getCommand(ccr);
389: if (cmd != null && cmd.canExecute()) {
390: executeCommand(cmd);
391: IAdaptable viewAdapter = (IAdaptable) ccr
392: .getNewObject();
393: if (viewAdapter != null) {
394: adapters.add(viewAdapter);
395: }
396: }
397: }
398: return adapters;
399: }
400:
401: /**
402: * @generated
403: */
404: private EditPart getEditPartFor(EObject modelElement) {
405: View view = (View) myEObject2ViewMap.get(modelElement);
406: if (view != null) {
407: return (EditPart) getHost().getViewer()
408: .getEditPartRegistry().get(view);
409: }
410: return null;
411: }
412:
413: /**
414: *@generated
415: */
416: private void storeLinks(EObject container, Diagram diagram) {
417: EClass containerMetaclass = container.eClass();
418: storeFeatureModelFacetLinks(container, containerMetaclass,
419: diagram);
420: storeTypeModelFacetLinks(container, containerMetaclass);
421: }
422:
423: /**
424: * @generated
425: */
426: private void storeTypeModelFacetLinks(EObject container,
427: EClass containerMetaclass) {
428: }
429:
430: /**
431: *@generated
432: */
433: private void storeFeatureModelFacetLinks(EObject container,
434: EClass containerMetaclass, Diagram diagram) {
435:
436: if (NewprocessPackage.eINSTANCE.getAsyncActivity()
437: .isSuperTypeOf(containerMetaclass)) {
438: EObject nextDestination = (EObject) ((AsyncActivity) container)
439: .getActor();
440: myLinkDescriptors.add(new LinkDescriptor(container,
441: nextDestination,
442: New_processElementTypes.AsyncActivityActor_4001,
443: AsyncActivityActorEditPart.VISUAL_ID));
444:
445: }
446: if (NewprocessPackage.eINSTANCE.getRoot().isSuperTypeOf(
447: containerMetaclass)) {
448: EObject nextDestination = (EObject) ((Root) container)
449: .getTerm();
450: myLinkDescriptors.add(new LinkDescriptor(container,
451: nextDestination,
452: New_processElementTypes.RootTerm_4002,
453: RootTermEditPart.VISUAL_ID));
454:
455: }
456: if (NewprocessPackage.eINSTANCE.getOperatorTerm()
457: .isSuperTypeOf(containerMetaclass)) {
458: for (Iterator destinations = ((OperatorTerm) container)
459: .getSubTerm().iterator(); destinations.hasNext();) {
460: EObject nextDestination = (EObject) destinations.next();
461: myLinkDescriptors
462: .add(new LinkDescriptor(
463: container,
464: nextDestination,
465: New_processElementTypes.OperatorTermSubTerm_4003,
466: OperatorTermSubTermEditPart.VISUAL_ID));
467:
468: }
469: }
470: if (NewprocessPackage.eINSTANCE.getConditionTerm()
471: .isSuperTypeOf(containerMetaclass)) {
472: EObject nextDestination = (EObject) ((ConditionTerm) container)
473: .getConditionProxy();
474: myLinkDescriptors
475: .add(new LinkDescriptor(
476: container,
477: nextDestination,
478: New_processElementTypes.ConditionTermConditionProxy_4004,
479: ConditionTermConditionProxyEditPart.VISUAL_ID));
480:
481: }
482: if (NewprocessPackage.eINSTANCE.getConclusion().isSuperTypeOf(
483: containerMetaclass)) {
484: EObject nextDestination = (EObject) ((Conclusion) container)
485: .getConclusionProxy();
486: myLinkDescriptors
487: .add(new LinkDescriptor(
488: container,
489: nextDestination,
490: New_processElementTypes.ConclusionConclusionProxy_4005,
491: ConclusionConclusionProxyEditPart.VISUAL_ID));
492:
493: }
494: if (NewprocessPackage.eINSTANCE.getExpansion().isSuperTypeOf(
495: containerMetaclass)) {
496: EObject nextDestination = (EObject) ((Expansion) container)
497: .getExpansionProxy();
498: myLinkDescriptors
499: .add(new LinkDescriptor(
500: container,
501: nextDestination,
502: New_processElementTypes.ExpansionExpansionProxy_4006,
503: ExpansionExpansionProxyEditPart.VISUAL_ID));
504:
505: }
506: }
507:
508: /**
509: * @generated
510: */
511: private Diagram getDiagram() {
512: return ((View) getHost().getModel()).getDiagram();
513: }
514:
515: /**
516: * @generated
517: */
518: private class LinkDescriptor {
519:
520: /**
521: * @generated
522: */
523: private EObject mySource;
524:
525: /**
526: * @generated
527: */
528: private EObject myDestination;
529:
530: /**
531: * @generated
532: */
533: private EObject myLinkElement;
534:
535: /**
536: * @generated
537: */
538: private int myVisualID;
539:
540: /**
541: * @generated
542: */
543: private IAdaptable mySemanticAdapter;
544:
545: /**
546: * @generated
547: */
548: protected LinkDescriptor(EObject source, EObject destination,
549: EObject linkElement, int linkVID) {
550: this (source, destination, linkVID);
551: myLinkElement = linkElement;
552: mySemanticAdapter = new EObjectAdapter(linkElement);
553: }
554:
555: /**
556: * @generated
557: */
558: protected LinkDescriptor(EObject source, EObject destination,
559: IElementType elementType, int linkVID) {
560: this (source, destination, linkVID);
561: myLinkElement = null;
562: final IElementType elementTypeCopy = elementType;
563: mySemanticAdapter = new IAdaptable() {
564: public Object getAdapter(Class adapter) {
565: if (IElementType.class.equals(adapter)) {
566: return elementTypeCopy;
567: }
568: return null;
569: }
570: };
571: }
572:
573: /**
574: * @generated
575: */
576: private LinkDescriptor(EObject source, EObject destination,
577: int linkVID) {
578: mySource = source;
579: myDestination = destination;
580: myVisualID = linkVID;
581: }
582:
583: /**
584: * @generated
585: */
586: protected EObject getSource() {
587: return mySource;
588: }
589:
590: /**
591: * @generated
592: */
593: protected EObject getDestination() {
594: return myDestination;
595: }
596:
597: /**
598: * @generated
599: */
600: protected EObject getLinkElement() {
601: return myLinkElement;
602: }
603:
604: /**
605: * @generated
606: */
607: protected int getVisualID() {
608: return myVisualID;
609: }
610:
611: /**
612: * @generated
613: */
614: protected IAdaptable getSemanticAdapter() {
615: return mySemanticAdapter;
616: }
617: }
618:
619: }
|