1 | /* |
2 | *Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.edit.policies; |
5 | |
6 | import java.util.Collection; |
7 | import java.util.HashSet; |
8 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy; |
9 | import org.eclipse.gmf.runtime.notation.View; |
10 | import de.uka.ipd.sdq.pcm.allocation.Allocation; |
11 | import de.uka.ipd.sdq.pcm.allocation.AllocationContext; |
12 | |
13 | import de.uka.ipd.sdq.pcm.allocation.AllocationPackage; |
14 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationContextEditPart; |
15 | |
16 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelDiagramUpdater; |
17 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelNodeDescriptor; |
18 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelVisualIDRegistry; |
19 | |
20 | import java.util.Iterator; |
21 | import java.util.LinkedList; |
22 | import java.util.List; |
23 | |
24 | import java.util.Set; |
25 | import org.eclipse.emf.ecore.EObject; |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | public class ResourceContainerAllocationCompartmentCanonicalEditPolicy extends |
31 | CanonicalEditPolicy { |
32 | |
33 | /** |
34 | * @generated |
35 | */ |
36 | Set myFeaturesToSynchronize; |
37 | |
38 | /** |
39 | * @generated not |
40 | */ |
41 | protected List getSemanticChildrenList() { |
42 | List result = new LinkedList(); |
43 | EObject modelObject = ((View) getHost().getModel()).getElement(); |
44 | EObject allocation = ((View) getHost().getParent().getParent() |
45 | .getModel()).getElement(); |
46 | View viewObject = (View) getHost().getModel(); |
47 | EObject nextValue; |
48 | int nodeVID; |
49 | for (Iterator values = ((Allocation) allocation) |
50 | .getAllocationContexts_Allocation().iterator(); values |
51 | .hasNext();) { |
52 | nextValue = (EObject) values.next(); |
53 | AllocationContext ac = (AllocationContext) nextValue; |
54 | if (ac.getResourceContainer_AllocationContext() == modelObject) { |
55 | nodeVID = PalladioComponentModelVisualIDRegistry |
56 | .getNodeVisualID(viewObject, nextValue); |
57 | if (AllocationContextEditPart.VISUAL_ID == nodeVID) { |
58 | result.add(nextValue); |
59 | } |
60 | } |
61 | } |
62 | return result; |
63 | } |
64 | |
65 | /** |
66 | * @generated |
67 | */ |
68 | protected boolean isOrphaned(Collection semanticChildren, final View view) { |
69 | int visualID = PalladioComponentModelVisualIDRegistry.getVisualID(view); |
70 | switch (visualID) { |
71 | case AllocationContextEditPart.VISUAL_ID: |
72 | return !semanticChildren.contains(view.getElement()) |
73 | || visualID != PalladioComponentModelVisualIDRegistry |
74 | .getNodeVisualID((View) getHost().getModel(), view |
75 | .getElement()); |
76 | } |
77 | return false; |
78 | } |
79 | |
80 | /** |
81 | * @generated |
82 | */ |
83 | protected String getDefaultFactoryHint() { |
84 | return null; |
85 | } |
86 | |
87 | /** |
88 | * @generated |
89 | */ |
90 | protected Set getFeaturesToSynchronize() { |
91 | if (myFeaturesToSynchronize == null) { |
92 | myFeaturesToSynchronize = new HashSet(); |
93 | myFeaturesToSynchronize.add(AllocationPackage.eINSTANCE |
94 | .getAllocation_AllocationContexts_Allocation()); |
95 | } |
96 | return myFeaturesToSynchronize; |
97 | } |
98 | |
99 | } |