001: package newprocess.diagram.providers;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Collections;
006: import java.util.HashSet;
007: import java.util.Iterator;
008: import java.util.List;
009:
010: import org.eclipse.core.runtime.IAdaptable;
011: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
012: import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
013: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
014: import org.eclipse.gmf.runtime.emf.ui.services.modelingassistant.ModelingAssistantProvider;
015: import org.eclipse.gmf.runtime.notation.Diagram;
016: import org.eclipse.jface.viewers.ILabelProvider;
017: import org.eclipse.jface.window.Window;
018: import org.eclipse.swt.widgets.Display;
019: import org.eclipse.swt.widgets.Shell;
020: import org.eclipse.ui.dialogs.ElementListSelectionDialog;
021: import org.eclipse.emf.ecore.EObject;
022: import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
023: import newprocess.diagram.edit.parts.ActorEditPart;
024: import newprocess.diagram.edit.parts.AsyncActivityAsyncActivityPostconditionCompartment2EditPart;
025: import newprocess.diagram.edit.parts.AsyncActivityAsyncActivityPostconditionCompartmentEditPart;
026: import newprocess.diagram.edit.parts.AsyncActivityAsyncActivityPreconditionCompartment2EditPart;
027: import newprocess.diagram.edit.parts.AsyncActivityAsyncActivityPreconditionCompartmentEditPart;
028: import newprocess.diagram.edit.parts.AsyncActivityEditPart;
029: import newprocess.diagram.edit.parts.ConclusionConclusionPostconditionCompartmentEditPart;
030: import newprocess.diagram.edit.parts.ConclusionEditPart;
031: import newprocess.diagram.edit.parts.ConditionProxyEditPart;
032: import newprocess.diagram.edit.parts.ConditionTermEditPart;
033: import newprocess.diagram.edit.parts.EventEditPart;
034: import newprocess.diagram.edit.parts.EventEventPostconditionCompartmentEditPart;
035: import newprocess.diagram.edit.parts.ExpansionEditPart;
036: import newprocess.diagram.edit.parts.ExpansionExpansionPostconditionCompartmentEditPart;
037: import newprocess.diagram.edit.parts.Expression2EditPart;
038: import newprocess.diagram.edit.parts.Expression3EditPart;
039: import newprocess.diagram.edit.parts.Expression4EditPart;
040: import newprocess.diagram.edit.parts.Expression5EditPart;
041: import newprocess.diagram.edit.parts.Expression6EditPart;
042: import newprocess.diagram.edit.parts.Expression7EditPart;
043: import newprocess.diagram.edit.parts.Expression8EditPart;
044: import newprocess.diagram.edit.parts.ExpressionEditPart;
045: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment2EditPart;
046: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment3EditPart;
047: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment4EditPart;
048: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment5EditPart;
049: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment6EditPart;
050: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment7EditPart;
051: import newprocess.diagram.edit.parts.ExpressionExpressionCompartment8EditPart;
052: import newprocess.diagram.edit.parts.ExpressionExpressionCompartmentEditPart;
053: import newprocess.diagram.edit.parts.GlobalsEditPart;
054: import newprocess.diagram.edit.parts.ListenerEditPart;
055: import newprocess.diagram.edit.parts.ListenerListenerPreconditionCompartmentEditPart;
056: import newprocess.diagram.edit.parts.ProcessEditPart;
057: import newprocess.diagram.edit.parts.RootEditPart;
058: import newprocess.diagram.edit.parts.SyncActivityEditPart;
059: import newprocess.diagram.edit.parts.SyncActivitySynActivityPostconditionCompartmentEditPart;
060: import newprocess.diagram.edit.parts.SyncActivitySynActivityPreconditionCompartmentEditPart;
061:
062: import newprocess.diagram.part.New_processDiagramEditorPlugin;
063:
064: /**
065: * @generated
066: */
067: public class New_processModelingAssistantProvider extends
068: ModelingAssistantProvider {
069:
070: /**
071: * @generated
072: */
073: public List getTypesForPopupBar(IAdaptable host) {
074: IGraphicalEditPart editPart = (IGraphicalEditPart) host
075: .getAdapter(IGraphicalEditPart.class);
076: if (editPart instanceof SyncActivityEditPart) {
077: List types = new ArrayList();
078: types.add(New_processElementTypes.Expression_3001);
079: types.add(New_processElementTypes.Expression_3006);
080: return types;
081: }
082: if (editPart instanceof ListenerEditPart) {
083: List types = new ArrayList();
084: types.add(New_processElementTypes.Expression_3007);
085: return types;
086: }
087: if (editPart instanceof AsyncActivityEditPart) {
088: List types = new ArrayList();
089: types.add(New_processElementTypes.Expression_3008);
090: types.add(New_processElementTypes.Expression_3009);
091: return types;
092: }
093: if (editPart instanceof EventEditPart) {
094: List types = new ArrayList();
095: types.add(New_processElementTypes.Expression_3010);
096: return types;
097: }
098: if (editPart instanceof ExpansionEditPart) {
099: List types = new ArrayList();
100: types.add(New_processElementTypes.Expression_3011);
101: return types;
102: }
103: if (editPart instanceof ConclusionEditPart) {
104: List types = new ArrayList();
105: types.add(New_processElementTypes.Expression_3012);
106: return types;
107: }
108: if (editPart instanceof GlobalsEditPart) {
109: List types = new ArrayList();
110: types.add(New_processElementTypes.Loader_3013);
111: types.add(New_processElementTypes.Condition_3014);
112: return types;
113: }
114: if (editPart instanceof ExpressionEditPart) {
115: List types = new ArrayList();
116: types.add(New_processElementTypes.Root_3002);
117: types.add(New_processElementTypes.ConditionTerm_3005);
118: return types;
119: }
120: if (editPart instanceof Expression2EditPart) {
121: List types = new ArrayList();
122: types.add(New_processElementTypes.Root_3002);
123: types.add(New_processElementTypes.ConditionTerm_3005);
124: return types;
125: }
126: if (editPart instanceof Expression3EditPart) {
127: List types = new ArrayList();
128: types.add(New_processElementTypes.Root_3002);
129: types.add(New_processElementTypes.ConditionTerm_3005);
130: return types;
131: }
132: if (editPart instanceof Expression4EditPart) {
133: List types = new ArrayList();
134: types.add(New_processElementTypes.Root_3002);
135: types.add(New_processElementTypes.ConditionTerm_3005);
136: return types;
137: }
138: if (editPart instanceof Expression5EditPart) {
139: List types = new ArrayList();
140: types.add(New_processElementTypes.Root_3002);
141: types.add(New_processElementTypes.ConditionTerm_3005);
142: return types;
143: }
144: if (editPart instanceof Expression6EditPart) {
145: List types = new ArrayList();
146: types.add(New_processElementTypes.Root_3002);
147: types.add(New_processElementTypes.ConditionTerm_3005);
148: return types;
149: }
150: if (editPart instanceof Expression7EditPart) {
151: List types = new ArrayList();
152: types.add(New_processElementTypes.Root_3002);
153: types.add(New_processElementTypes.ConditionTerm_3005);
154: return types;
155: }
156: if (editPart instanceof Expression8EditPart) {
157: List types = new ArrayList();
158: types.add(New_processElementTypes.Root_3002);
159: types.add(New_processElementTypes.ConditionTerm_3005);
160: return types;
161: }
162: if (editPart instanceof ExpressionExpressionCompartmentEditPart) {
163: List types = new ArrayList();
164: types.add(New_processElementTypes.OrOperator_3003);
165: types.add(New_processElementTypes.AndOperator_3004);
166: return types;
167: }
168: if (editPart instanceof ExpressionExpressionCompartment2EditPart) {
169: List types = new ArrayList();
170: types.add(New_processElementTypes.OrOperator_3003);
171: types.add(New_processElementTypes.AndOperator_3004);
172: return types;
173: }
174: if (editPart instanceof ExpressionExpressionCompartment3EditPart) {
175: List types = new ArrayList();
176: types.add(New_processElementTypes.OrOperator_3003);
177: types.add(New_processElementTypes.AndOperator_3004);
178: return types;
179: }
180: if (editPart instanceof ExpressionExpressionCompartment4EditPart) {
181: List types = new ArrayList();
182: types.add(New_processElementTypes.OrOperator_3003);
183: types.add(New_processElementTypes.AndOperator_3004);
184: return types;
185: }
186: if (editPart instanceof ExpressionExpressionCompartment5EditPart) {
187: List types = new ArrayList();
188: types.add(New_processElementTypes.OrOperator_3003);
189: types.add(New_processElementTypes.AndOperator_3004);
190: return types;
191: }
192: if (editPart instanceof ExpressionExpressionCompartment6EditPart) {
193: List types = new ArrayList();
194: types.add(New_processElementTypes.OrOperator_3003);
195: types.add(New_processElementTypes.AndOperator_3004);
196: return types;
197: }
198: if (editPart instanceof ExpressionExpressionCompartment7EditPart) {
199: List types = new ArrayList();
200: types.add(New_processElementTypes.OrOperator_3003);
201: types.add(New_processElementTypes.AndOperator_3004);
202: return types;
203: }
204: if (editPart instanceof ExpressionExpressionCompartment8EditPart) {
205: List types = new ArrayList();
206: types.add(New_processElementTypes.OrOperator_3003);
207: types.add(New_processElementTypes.AndOperator_3004);
208: return types;
209: }
210: if (editPart instanceof ProcessEditPart) {
211: List types = new ArrayList();
212: types.add(New_processElementTypes.SyncActivity_2001);
213: types.add(New_processElementTypes.Listener_2002);
214: types.add(New_processElementTypes.AsyncActivity_2003);
215: types.add(New_processElementTypes.Event_2005);
216: types.add(New_processElementTypes.ConditionProxy_2006);
217: types.add(New_processElementTypes.Actor_2007);
218: types.add(New_processElementTypes.Message_2008);
219: types.add(New_processElementTypes.Expansion_2009);
220: types.add(New_processElementTypes.Conclusion_2010);
221: types.add(New_processElementTypes.Globals_2011);
222: return types;
223: }
224: return Collections.EMPTY_LIST;
225: }
226:
227: /**
228: * @generated
229: */
230: public List getRelTypesOnSource(IAdaptable source) {
231: IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
232: .getAdapter(IGraphicalEditPart.class);
233: if (sourceEditPart instanceof AsyncActivityEditPart) {
234: List types = new ArrayList();
235: types.add(New_processElementTypes.AsyncActivityActor_4001);
236: return types;
237: }
238: if (sourceEditPart instanceof RootEditPart) {
239: List types = new ArrayList();
240: types.add(New_processElementTypes.RootTerm_4002);
241: return types;
242: }
243: if (sourceEditPart instanceof ConditionTermEditPart) {
244: List types = new ArrayList();
245: types
246: .add(New_processElementTypes.ConditionTermConditionProxy_4004);
247: return types;
248: }
249: if (sourceEditPart instanceof ConclusionEditPart) {
250: List types = new ArrayList();
251: types
252: .add(New_processElementTypes.ConclusionConclusionProxy_4005);
253: return types;
254: }
255: if (sourceEditPart instanceof ExpansionEditPart) {
256: List types = new ArrayList();
257: types
258: .add(New_processElementTypes.ExpansionExpansionProxy_4006);
259: return types;
260: }
261: return Collections.EMPTY_LIST;
262: }
263:
264: /**
265: * @generated
266: */
267: public List getRelTypesOnTarget(IAdaptable target) {
268: IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
269: .getAdapter(IGraphicalEditPart.class);
270: if (targetEditPart instanceof ActorEditPart) {
271: List types = new ArrayList();
272: types.add(New_processElementTypes.AsyncActivityActor_4001);
273: return types;
274: }
275: if (targetEditPart instanceof ConditionProxyEditPart) {
276: List types = new ArrayList();
277: types
278: .add(New_processElementTypes.ConditionTermConditionProxy_4004);
279: types
280: .add(New_processElementTypes.ConclusionConclusionProxy_4005);
281: types
282: .add(New_processElementTypes.ExpansionExpansionProxy_4006);
283: return types;
284: }
285: return Collections.EMPTY_LIST;
286: }
287:
288: /**
289: * @generated
290: */
291: public List getRelTypesOnSourceAndTarget(IAdaptable source,
292: IAdaptable target) {
293: IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
294: .getAdapter(IGraphicalEditPart.class);
295: IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
296: .getAdapter(IGraphicalEditPart.class);
297: if (sourceEditPart instanceof AsyncActivityEditPart) {
298: List types = new ArrayList();
299: if (targetEditPart instanceof ActorEditPart) {
300: types
301: .add(New_processElementTypes.AsyncActivityActor_4001);
302: }
303: return types;
304: }
305: if (sourceEditPart instanceof RootEditPart) {
306: List types = new ArrayList();
307: return types;
308: }
309: if (sourceEditPart instanceof ConditionTermEditPart) {
310: List types = new ArrayList();
311: if (targetEditPart instanceof ConditionProxyEditPart) {
312: types
313: .add(New_processElementTypes.ConditionTermConditionProxy_4004);
314: }
315: return types;
316: }
317: if (sourceEditPart instanceof ConclusionEditPart) {
318: List types = new ArrayList();
319: if (targetEditPart instanceof ConditionProxyEditPart) {
320: types
321: .add(New_processElementTypes.ConclusionConclusionProxy_4005);
322: }
323: return types;
324: }
325: if (sourceEditPart instanceof ExpansionEditPart) {
326: List types = new ArrayList();
327: if (targetEditPart instanceof ConditionProxyEditPart) {
328: types
329: .add(New_processElementTypes.ExpansionExpansionProxy_4006);
330: }
331: return types;
332: }
333: return Collections.EMPTY_LIST;
334: }
335:
336: /**
337: * @generated
338: */
339: public List getTypesForSource(IAdaptable target,
340: IElementType relationshipType) {
341: IGraphicalEditPart targetEditPart = (IGraphicalEditPart) target
342: .getAdapter(IGraphicalEditPart.class);
343: if (targetEditPart instanceof ActorEditPart) {
344: List types = new ArrayList();
345: if (relationshipType == New_processElementTypes.AsyncActivityActor_4001) {
346: types.add(New_processElementTypes.AsyncActivity_2003);
347: }
348: return types;
349: }
350: if (targetEditPart instanceof ConditionProxyEditPart) {
351: List types = new ArrayList();
352: if (relationshipType == New_processElementTypes.ConditionTermConditionProxy_4004) {
353: types.add(New_processElementTypes.ConditionTerm_3005);
354: }
355: if (relationshipType == New_processElementTypes.ConclusionConclusionProxy_4005) {
356: types.add(New_processElementTypes.Conclusion_2010);
357: }
358: if (relationshipType == New_processElementTypes.ExpansionExpansionProxy_4006) {
359: types.add(New_processElementTypes.Expansion_2009);
360: }
361: return types;
362: }
363: return Collections.EMPTY_LIST;
364: }
365:
366: /**
367: * @generated
368: */
369: public List getTypesForTarget(IAdaptable source,
370: IElementType relationshipType) {
371: IGraphicalEditPart sourceEditPart = (IGraphicalEditPart) source
372: .getAdapter(IGraphicalEditPart.class);
373: if (sourceEditPart instanceof AsyncActivityEditPart) {
374: List types = new ArrayList();
375: if (relationshipType == New_processElementTypes.AsyncActivityActor_4001) {
376: types.add(New_processElementTypes.Actor_2007);
377: }
378: return types;
379: }
380: if (sourceEditPart instanceof RootEditPart) {
381: List types = new ArrayList();
382: return types;
383: }
384: if (sourceEditPart instanceof ConditionTermEditPart) {
385: List types = new ArrayList();
386: if (relationshipType == New_processElementTypes.ConditionTermConditionProxy_4004) {
387: types.add(New_processElementTypes.ConditionProxy_2006);
388: }
389: return types;
390: }
391: if (sourceEditPart instanceof ConclusionEditPart) {
392: List types = new ArrayList();
393: if (relationshipType == New_processElementTypes.ConclusionConclusionProxy_4005) {
394: types.add(New_processElementTypes.ConditionProxy_2006);
395: }
396: return types;
397: }
398: if (sourceEditPart instanceof ExpansionEditPart) {
399: List types = new ArrayList();
400: if (relationshipType == New_processElementTypes.ExpansionExpansionProxy_4006) {
401: types.add(New_processElementTypes.ConditionProxy_2006);
402: }
403: return types;
404: }
405: return Collections.EMPTY_LIST;
406: }
407:
408: /**
409: * @generated
410: */
411: public EObject selectExistingElementForSource(IAdaptable target,
412: IElementType relationshipType) {
413: return selectExistingElement(target, getTypesForSource(target,
414: relationshipType));
415: }
416:
417: /**
418: * @generated
419: */
420: public EObject selectExistingElementForTarget(IAdaptable source,
421: IElementType relationshipType) {
422: return selectExistingElement(source, getTypesForTarget(source,
423: relationshipType));
424: }
425:
426: /**
427: * @generated
428: */
429: protected EObject selectExistingElement(IAdaptable host,
430: Collection types) {
431: if (types.isEmpty()) {
432: return null;
433: }
434: IGraphicalEditPart editPart = (IGraphicalEditPart) host
435: .getAdapter(IGraphicalEditPart.class);
436: if (editPart == null) {
437: return null;
438: }
439: Diagram diagram = (Diagram) editPart.getRoot().getContents()
440: .getModel();
441: Collection elements = new HashSet();
442: for (Iterator it = diagram.getElement().eAllContents(); it
443: .hasNext();) {
444: EObject element = (EObject) it.next();
445: if (isApplicableElement(element, types)) {
446: elements.add(element);
447: }
448: }
449: if (elements.isEmpty()) {
450: return null;
451: }
452: return selectElement((EObject[]) elements
453: .toArray(new EObject[elements.size()]));
454: }
455:
456: /**
457: * @generated
458: */
459: protected boolean isApplicableElement(EObject element,
460: Collection types) {
461: IElementType type = ElementTypeRegistry.getInstance()
462: .getElementType(element);
463: return types.contains(type);
464: }
465:
466: /**
467: * @generated
468: */
469: protected EObject selectElement(EObject[] elements) {
470: Shell shell = Display.getCurrent().getActiveShell();
471: ILabelProvider labelProvider = new AdapterFactoryLabelProvider(
472: New_processDiagramEditorPlugin.getInstance()
473: .getItemProvidersAdapterFactory());
474: ElementListSelectionDialog dialog = new ElementListSelectionDialog(
475: shell, labelProvider);
476: dialog.setMessage("Available domain model elements:");
477: dialog.setTitle("Select domain model element");
478: dialog.setMultipleSelection(false);
479: dialog.setElements(elements);
480: EObject selected = null;
481: if (dialog.open() == Window.OK) {
482: selected = (EObject) dialog.getFirstResult();
483: }
484: return selected;
485: }
486: }
|