EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcm.gmf.resource.edit.policies]

COVERAGE SUMMARY FOR SOURCE FILE [ResourceEnvironmentCanonicalEditPolicy.java]

nameclass, %method, %block, %line, %
ResourceEnvironmentCanonicalEditPolicy.java0%   (0/1)0%   (0/16)0%   (0/519)0%   (0/158)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ResourceEnvironmentCanonicalEditPolicy0%   (0/1)0%   (0/16)0%   (0/519)0%   (0/158)
ResourceEnvironmentCanonicalEditPolicy (): void 0%   (0/1)0%   (0/3)0%   (0/1)
collectAllLinks (View, Map): Collection 0%   (0/1)0%   (0/179)0%   (0/49)
createConnections (Collection, Map): Collection 0%   (0/1)0%   (0/92)0%   (0/30)
getDefaultFactoryHint (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getDiagram (): Diagram 0%   (0/1)0%   (0/6)0%   (0/1)
getEditPart (EObject, Map): EditPart 0%   (0/1)0%   (0/17)0%   (0/5)
getFeaturesToSynchronize (): Set 0%   (0/1)0%   (0/23)0%   (0/9)
getSemanticChildrenList (): List 0%   (0/1)0%   (0/26)0%   (0/8)
getSemanticConnectionsList (): List 0%   (0/1)0%   (0/2)0%   (0/1)
getSourceElement (EObject): EObject 0%   (0/1)0%   (0/2)0%   (0/1)
getTargetElement (EObject): EObject 0%   (0/1)0%   (0/2)0%   (0/1)
isOrphaned (Collection, View): boolean 0%   (0/1)0%   (0/14)0%   (0/5)
refreshConnections (): Collection 0%   (0/1)0%   (0/96)0%   (0/32)
refreshSemantic (): void 0%   (0/1)0%   (0/51)0%   (0/12)
shouldDeleteView (View): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
shouldIncludeConnection (Edge, Collection): boolean 0%   (0/1)0%   (0/2)0%   (0/1)

1/*
2 * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.resource.edit.policies;
5 
6import java.util.Collection;
7import java.util.Collections;
8import java.util.HashMap;
9import java.util.HashSet;
10import java.util.Iterator;
11import java.util.LinkedList;
12import java.util.List;
13import java.util.Map;
14import java.util.Set;
15 
16import org.eclipse.core.runtime.IAdaptable;
17import org.eclipse.emf.ecore.EObject;
18import org.eclipse.gef.EditPart;
19import org.eclipse.gef.commands.Command;
20import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
21import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
22import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
23import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
24import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy;
25import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
26import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
27import org.eclipse.gmf.runtime.notation.Diagram;
28import org.eclipse.gmf.runtime.notation.Edge;
29import org.eclipse.gmf.runtime.notation.View;
30 
31import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationEditPart;
32import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResource2EditPart;
33import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationEditPart;
34import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEditPart;
35import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceEnvironmentEditPart;
36import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelDiagramUpdater;
37import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelLinkDescriptor;
38import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelNodeDescriptor;
39import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry;
40import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage;
41 
42/**
43 * @generated
44 */
45public class ResourceEnvironmentCanonicalEditPolicy extends
46                CanonicalConnectionEditPolicy {
47 
48        /**
49         * @generated
50         */
51        Set myFeaturesToSynchronize;
52 
53        /**
54         * @generated
55         */
56        protected List getSemanticChildrenList() {
57                View viewObject = (View) getHost().getModel();
58                List result = new LinkedList();
59                for (Iterator it = PalladioComponentModelDiagramUpdater
60                                .getResourceEnvironment_1000SemanticChildren(viewObject)
61                                .iterator(); it.hasNext();) {
62                        result.add(((PalladioComponentModelNodeDescriptor) it.next())
63                                        .getModelElement());
64                }
65                return result;
66        }
67 
68        /**
69         * @generated
70         */
71        protected boolean shouldDeleteView(View view) {
72                return true;
73        }
74 
75        /**
76         * @generated
77         */
78        protected boolean isOrphaned(Collection semanticChildren, final View view) {
79                int visualID = PalladioComponentModelVisualIDRegistry.getVisualID(view);
80                switch (visualID) {
81                case ResourceContainerEditPart.VISUAL_ID:
82                case LinkingResource2EditPart.VISUAL_ID:
83                        if (!semanticChildren.contains(view.getElement())) {
84                                return true;
85                        }
86                }
87                return false;
88        }
89 
90        /**
91         * @generated
92         */
93        protected String getDefaultFactoryHint() {
94                return null;
95        }
96 
97        /**
98         * @generated
99         */
100        protected Set getFeaturesToSynchronize() {
101                if (myFeaturesToSynchronize == null) {
102                        myFeaturesToSynchronize = new HashSet();
103                        myFeaturesToSynchronize
104                                        .add(ResourceenvironmentPackage.eINSTANCE
105                                                        .getResourceEnvironment_ResourceContainer_ResourceEnvironment());
106                        myFeaturesToSynchronize
107                                        .add(ResourceenvironmentPackage.eINSTANCE
108                                                        .getResourceEnvironment_LinkingResources__ResourceEnvironment());
109                }
110                return myFeaturesToSynchronize;
111        }
112 
113        /**
114         * @generated
115         */
116        protected List getSemanticConnectionsList() {
117                return Collections.EMPTY_LIST;
118        }
119 
120        /**
121         * @generated
122         */
123        protected EObject getSourceElement(EObject relationship) {
124                return null;
125        }
126 
127        /**
128         * @generated
129         */
130        protected EObject getTargetElement(EObject relationship) {
131                return null;
132        }
133 
134        /**
135         * @generated
136         */
137        protected boolean shouldIncludeConnection(Edge connector,
138                        Collection children) {
139                return false;
140        }
141 
142        /**
143         * @generated
144         */
145        protected void refreshSemantic() {
146                List createdViews = new LinkedList();
147                createdViews.addAll(refreshSemanticChildren());
148                List createdConnectionViews = new LinkedList();
149                createdConnectionViews.addAll(refreshSemanticConnections());
150                createdConnectionViews.addAll(refreshConnections());
151 
152                if (createdViews.size() > 1) {
153                        // perform a layout of the container
154                        DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host()
155                                        .getEditingDomain(), createdViews, host());
156                        executeCommand(new ICommandProxy(layoutCmd));
157                }
158 
159                createdViews.addAll(createdConnectionViews);
160                makeViewsImmutable(createdViews);
161        }
162 
163        /**
164         * @generated
165         */
166        private Diagram getDiagram() {
167                return ((View) getHost().getModel()).getDiagram();
168        }
169 
170        /**
171         * @generated
172         */
173        private Collection refreshConnections() {
174                Map domain2NotationMap = new HashMap();
175                Collection linkDescriptors = collectAllLinks(getDiagram(),
176                                domain2NotationMap);
177                Collection existingLinks = new LinkedList(getDiagram().getEdges());
178                for (Iterator linksIterator = existingLinks.iterator(); linksIterator
179                                .hasNext();) {
180                        Edge nextDiagramLink = (Edge) linksIterator.next();
181                        int diagramLinkVisualID = PalladioComponentModelVisualIDRegistry
182                                        .getVisualID(nextDiagramLink);
183                        if (diagramLinkVisualID == -1) {
184                                if (nextDiagramLink.getSource() != null
185                                                && nextDiagramLink.getTarget() != null) {
186                                        linksIterator.remove();
187                                }
188                                continue;
189                        }
190                        EObject diagramLinkObject = nextDiagramLink.getElement();
191                        EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
192                        EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
193                        for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator
194                                        .hasNext();) {
195                                PalladioComponentModelLinkDescriptor nextLinkDescriptor = (PalladioComponentModelLinkDescriptor) linkDescriptorsIterator
196                                                .next();
197                                if (diagramLinkObject == nextLinkDescriptor.getModelElement()
198                                                && diagramLinkSrc == nextLinkDescriptor.getSource()
199                                                && diagramLinkDst == nextLinkDescriptor
200                                                                .getDestination()
201                                                && diagramLinkVisualID == nextLinkDescriptor
202                                                                .getVisualID()) {
203                                        linksIterator.remove();
204                                        linkDescriptorsIterator.remove();
205                                        break;
206                                }
207                        }
208                }
209                deleteViews(existingLinks.iterator());
210                return createConnections(linkDescriptors, domain2NotationMap);
211        }
212 
213        /**
214         * @generated
215         */
216        private Collection collectAllLinks(View view, Map domain2NotationMap) {
217                if (!ResourceEnvironmentEditPart.MODEL_ID
218                                .equals(PalladioComponentModelVisualIDRegistry.getModelID(view))) {
219                        return Collections.EMPTY_LIST;
220                }
221                Collection result = new LinkedList();
222                switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) {
223                case ResourceEnvironmentEditPart.VISUAL_ID: {
224                        if (!domain2NotationMap.containsKey(view.getElement())) {
225                                result.addAll(PalladioComponentModelDiagramUpdater
226                                                .getResourceEnvironment_1000ContainedLinks(view));
227                        }
228                        if (!domain2NotationMap.containsKey(view.getElement())
229                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
230                                domain2NotationMap.put(view.getElement(), view);
231                        }
232                        break;
233                }
234                case ResourceContainerEditPart.VISUAL_ID: {
235                        if (!domain2NotationMap.containsKey(view.getElement())) {
236                                result.addAll(PalladioComponentModelDiagramUpdater
237                                                .getResourceContainer_2001ContainedLinks(view));
238                        }
239                        if (!domain2NotationMap.containsKey(view.getElement())
240                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
241                                domain2NotationMap.put(view.getElement(), view);
242                        }
243                        break;
244                }
245                case LinkingResource2EditPart.VISUAL_ID: {
246                        if (!domain2NotationMap.containsKey(view.getElement())) {
247                                result.addAll(PalladioComponentModelDiagramUpdater
248                                                .getLinkingResource_2003ContainedLinks(view));
249                        }
250                        if (!domain2NotationMap.containsKey(view.getElement())
251                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
252                                domain2NotationMap.put(view.getElement(), view);
253                        }
254                        break;
255                }
256                case ProcessingResourceSpecificationEditPart.VISUAL_ID: {
257                        if (!domain2NotationMap.containsKey(view.getElement())) {
258                                result
259                                                .addAll(PalladioComponentModelDiagramUpdater
260                                                                .getProcessingResourceSpecification_3001ContainedLinks(view));
261                        }
262                        if (!domain2NotationMap.containsKey(view.getElement())
263                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
264                                domain2NotationMap.put(view.getElement(), view);
265                        }
266                        break;
267                }
268                case CommunicationLinkResourceSpecificationEditPart.VISUAL_ID: {
269                        if (!domain2NotationMap.containsKey(view.getElement())) {
270                                result
271                                                .addAll(PalladioComponentModelDiagramUpdater
272                                                                .getCommunicationLinkResourceSpecification_3002ContainedLinks(view));
273                        }
274                        if (!domain2NotationMap.containsKey(view.getElement())
275                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
276                                domain2NotationMap.put(view.getElement(), view);
277                        }
278                        break;
279                }
280                }
281                for (Iterator children = view.getChildren().iterator(); children
282                                .hasNext();) {
283                        result.addAll(collectAllLinks((View) children.next(),
284                                        domain2NotationMap));
285                }
286                for (Iterator edges = view.getSourceEdges().iterator(); edges.hasNext();) {
287                        result.addAll(collectAllLinks((View) edges.next(),
288                                        domain2NotationMap));
289                }
290                return result;
291        }
292 
293        /**
294         * @generated
295         */
296        private Collection createConnections(Collection linkDescriptors,
297                        Map domain2NotationMap) {
298                List adapters = new LinkedList();
299                for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator
300                                .hasNext();) {
301                        final PalladioComponentModelLinkDescriptor nextLinkDescriptor = (PalladioComponentModelLinkDescriptor) linkDescriptorsIterator
302                                        .next();
303                        EditPart sourceEditPart = getEditPart(nextLinkDescriptor
304                                        .getSource(), domain2NotationMap);
305                        EditPart targetEditPart = getEditPart(nextLinkDescriptor
306                                        .getDestination(), domain2NotationMap);
307                        if (sourceEditPart == null || targetEditPart == null) {
308                                continue;
309                        }
310                        CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
311                                        nextLinkDescriptor.getSemanticAdapter(), String
312                                                        .valueOf(nextLinkDescriptor.getVisualID()),
313                                        ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost())
314                                                        .getDiagramPreferencesHint());
315                        CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(
316                                        descriptor);
317                        ccr.setType(RequestConstants.REQ_CONNECTION_START);
318                        ccr.setSourceEditPart(sourceEditPart);
319                        sourceEditPart.getCommand(ccr);
320                        ccr.setTargetEditPart(targetEditPart);
321                        ccr.setType(RequestConstants.REQ_CONNECTION_END);
322                        Command cmd = targetEditPart.getCommand(ccr);
323                        if (cmd != null && cmd.canExecute()) {
324                                executeCommand(cmd);
325                                IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
326                                if (viewAdapter != null) {
327                                        adapters.add(viewAdapter);
328                                }
329                        }
330                }
331                return adapters;
332        }
333 
334        /**
335         * @generated
336         */
337        private EditPart getEditPart(EObject domainModelElement,
338                        Map domain2NotationMap) {
339                View view = (View) domain2NotationMap.get(domainModelElement);
340                if (view != null) {
341                        return (EditPart) getHost().getViewer().getEditPartRegistry().get(
342                                        view);
343                }
344                return null;
345        }
346 
347}

[all classes][de.uka.ipd.sdq.pcm.gmf.resource.edit.policies]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov