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

COVERAGE SUMMARY FOR SOURCE FILE [RepositoryCanonicalEditPolicy.java]

nameclass, %method, %block, %line, %
RepositoryCanonicalEditPolicy.java0%   (0/1)0%   (0/16)0%   (0/818)0%   (0/236)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RepositoryCanonicalEditPolicy0%   (0/1)0%   (0/16)0%   (0/818)0%   (0/236)
RepositoryCanonicalEditPolicy (): void 0%   (0/1)0%   (0/3)0%   (0/1)
collectAllLinks (View, Map): Collection 0%   (0/1)0%   (0/465)0%   (0/126)
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/7)
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/21)0%   (0/8)
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/8)0%   (0/1)
shouldIncludeConnection (Edge, Collection): boolean 0%   (0/1)0%   (0/2)0%   (0/1)

1/*
2 *Copyright 2007, IPD, SDQ, University of Karlsruhe
3 */
4package de.uka.ipd.sdq.pcm.gmf.repository.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.repository.edit.parts.BasicComponentEditPart;
32import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.CompleteComponentTypeEditPart;
33import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.CompositeComponentEditPart;
34import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.EventGroupEditPart;
35import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureInterfaceEditPart;
36import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureProvidedRoleEditPart;
37import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureRequiredRoleEditPart;
38import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationInterfaceEditPart;
39import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationProvidedRoleEditPart;
40import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationRequiredRoleEditPart;
41import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.ProvidesComponentTypeEditPart;
42import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.RepositoryEditPart;
43import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SinkRoleEditPart;
44import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SourceRoleEditPart;
45import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SubSystemEditPart;
46import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.VariableUsageEditPart;
47import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelDiagramUpdater;
48import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelLinkDescriptor;
49import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelNodeDescriptor;
50import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry;
51import de.uka.ipd.sdq.pcm.repository.RepositoryPackage;
52 
53/**
54 * @generated
55 */
56public class RepositoryCanonicalEditPolicy extends
57                CanonicalConnectionEditPolicy {
58 
59        /**
60         * @generated
61         */
62        Set myFeaturesToSynchronize;
63 
64        /**
65         * @generated
66         */
67        protected List getSemanticChildrenList() {
68                View viewObject = (View) getHost().getModel();
69                List result = new LinkedList();
70                for (Iterator it = PalladioComponentModelDiagramUpdater
71                                .getRepository_1000SemanticChildren(viewObject).iterator(); it
72                                .hasNext();) {
73                        result.add(((PalladioComponentModelNodeDescriptor) it.next())
74                                        .getModelElement());
75                }
76                return result;
77        }
78 
79        /**
80         * @generated not
81         * to fix gmf bug 189589
82         */
83        protected boolean shouldDeleteView(View view) {
84                return view.getEAnnotation("Shortcut") == null;
85        }
86 
87        /**
88         * @generated
89         */
90        protected boolean isOrphaned(Collection semanticChildren, final View view) {
91                if (view.getEAnnotation("Shortcut") != null) { //$NON-NLS-1$
92                        return PalladioComponentModelDiagramUpdater
93                                        .isShortcutOrphaned(view);
94                }
95                int visualID = PalladioComponentModelVisualIDRegistry.getVisualID(view);
96                switch (visualID) {
97                case OperationInterfaceEditPart.VISUAL_ID:
98                case EventGroupEditPart.VISUAL_ID:
99                case BasicComponentEditPart.VISUAL_ID:
100                case CompositeComponentEditPart.VISUAL_ID:
101                case CompleteComponentTypeEditPart.VISUAL_ID:
102                case ProvidesComponentTypeEditPart.VISUAL_ID:
103                case SubSystemEditPart.VISUAL_ID:
104                case InfrastructureInterfaceEditPart.VISUAL_ID:
105                        if (!semanticChildren.contains(view.getElement())) {
106                                return true;
107                        }
108                }
109                return false;
110        }
111 
112        /**
113         * @generated
114         */
115        protected String getDefaultFactoryHint() {
116                return null;
117        }
118 
119        /**
120         * @generated
121         */
122        protected Set getFeaturesToSynchronize() {
123                if (myFeaturesToSynchronize == null) {
124                        myFeaturesToSynchronize = new HashSet();
125                        myFeaturesToSynchronize.add(RepositoryPackage.eINSTANCE
126                                        .getRepository_Interfaces__Repository());
127                        myFeaturesToSynchronize.add(RepositoryPackage.eINSTANCE
128                                        .getRepository_Components__Repository());
129                }
130                return myFeaturesToSynchronize;
131        }
132 
133        /**
134         * @generated
135         */
136        protected List getSemanticConnectionsList() {
137                return Collections.EMPTY_LIST;
138        }
139 
140        /**
141         * @generated
142         */
143        protected EObject getSourceElement(EObject relationship) {
144                return null;
145        }
146 
147        /**
148         * @generated
149         */
150        protected EObject getTargetElement(EObject relationship) {
151                return null;
152        }
153 
154        /**
155         * @generated
156         */
157        protected boolean shouldIncludeConnection(Edge connector,
158                        Collection children) {
159                return false;
160        }
161 
162        /**
163         * @generated
164         */
165        protected void refreshSemantic() {
166                List createdViews = new LinkedList();
167                createdViews.addAll(refreshSemanticChildren());
168                List createdConnectionViews = new LinkedList();
169                createdConnectionViews.addAll(refreshSemanticConnections());
170                createdConnectionViews.addAll(refreshConnections());
171 
172                if (createdViews.size() > 1) {
173                        // perform a layout of the container
174                        DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host()
175                                        .getEditingDomain(), createdViews, host());
176                        executeCommand(new ICommandProxy(layoutCmd));
177                }
178 
179                createdViews.addAll(createdConnectionViews);
180                makeViewsImmutable(createdViews);
181        }
182 
183        /**
184         * @generated
185         */
186        private Collection refreshConnections() {
187                Map domain2NotationMap = new HashMap();
188                Collection linkDescriptors = collectAllLinks(getDiagram(),
189                                domain2NotationMap);
190                Collection existingLinks = new LinkedList(getDiagram().getEdges());
191                for (Iterator linksIterator = existingLinks.iterator(); linksIterator
192                                .hasNext();) {
193                        Edge nextDiagramLink = (Edge) linksIterator.next();
194                        int diagramLinkVisualID = PalladioComponentModelVisualIDRegistry
195                                        .getVisualID(nextDiagramLink);
196                        if (diagramLinkVisualID == -1) {
197                                if (nextDiagramLink.getSource() != null
198                                                && nextDiagramLink.getTarget() != null) {
199                                        linksIterator.remove();
200                                }
201                                continue;
202                        }
203                        EObject diagramLinkObject = nextDiagramLink.getElement();
204                        EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
205                        EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
206                        for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator
207                                        .hasNext();) {
208                                PalladioComponentModelLinkDescriptor nextLinkDescriptor = (PalladioComponentModelLinkDescriptor) linkDescriptorsIterator
209                                                .next();
210                                if (diagramLinkObject == nextLinkDescriptor.getModelElement()
211                                                && diagramLinkSrc == nextLinkDescriptor.getSource()
212                                                && diagramLinkDst == nextLinkDescriptor
213                                                                .getDestination()
214                                                && diagramLinkVisualID == nextLinkDescriptor
215                                                                .getVisualID()) {
216                                        linksIterator.remove();
217                                        linkDescriptorsIterator.remove();
218                                        break;
219                                }
220                        }
221                }
222                deleteViews(existingLinks.iterator());
223                return createConnections(linkDescriptors, domain2NotationMap);
224        }
225 
226        /**
227         * @generated
228         */
229        private Collection collectAllLinks(View view, Map domain2NotationMap) {
230                if (!RepositoryEditPart.MODEL_ID
231                                .equals(PalladioComponentModelVisualIDRegistry.getModelID(view))) {
232                        return Collections.EMPTY_LIST;
233                }
234                Collection result = new LinkedList();
235                switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) {
236                case RepositoryEditPart.VISUAL_ID: {
237                        if (!domain2NotationMap.containsKey(view.getElement())) {
238                                result.addAll(PalladioComponentModelDiagramUpdater
239                                                .getRepository_1000ContainedLinks(view));
240                        }
241                        if (!domain2NotationMap.containsKey(view.getElement())
242                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
243                                domain2NotationMap.put(view.getElement(), view);
244                        }
245                        break;
246                }
247                case OperationInterfaceEditPart.VISUAL_ID: {
248                        if (!domain2NotationMap.containsKey(view.getElement())) {
249                                result.addAll(PalladioComponentModelDiagramUpdater
250                                                .getOperationInterface_2107ContainedLinks(view));
251                        }
252                        if (!domain2NotationMap.containsKey(view.getElement())
253                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
254                                domain2NotationMap.put(view.getElement(), view);
255                        }
256                        break;
257                }
258                case EventGroupEditPart.VISUAL_ID: {
259                        if (!domain2NotationMap.containsKey(view.getElement())) {
260                                result.addAll(PalladioComponentModelDiagramUpdater
261                                                .getEventGroup_2108ContainedLinks(view));
262                        }
263                        if (!domain2NotationMap.containsKey(view.getElement())
264                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
265                                domain2NotationMap.put(view.getElement(), view);
266                        }
267                        break;
268                }
269                case BasicComponentEditPart.VISUAL_ID: {
270                        if (!domain2NotationMap.containsKey(view.getElement())) {
271                                result.addAll(PalladioComponentModelDiagramUpdater
272                                                .getBasicComponent_2102ContainedLinks(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                case CompositeComponentEditPart.VISUAL_ID: {
281                        if (!domain2NotationMap.containsKey(view.getElement())) {
282                                result.addAll(PalladioComponentModelDiagramUpdater
283                                                .getCompositeComponent_2103ContainedLinks(view));
284                        }
285                        if (!domain2NotationMap.containsKey(view.getElement())
286                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
287                                domain2NotationMap.put(view.getElement(), view);
288                        }
289                        break;
290                }
291                case CompleteComponentTypeEditPart.VISUAL_ID: {
292                        if (!domain2NotationMap.containsKey(view.getElement())) {
293                                result.addAll(PalladioComponentModelDiagramUpdater
294                                                .getCompleteComponentType_2104ContainedLinks(view));
295                        }
296                        if (!domain2NotationMap.containsKey(view.getElement())
297                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
298                                domain2NotationMap.put(view.getElement(), view);
299                        }
300                        break;
301                }
302                case ProvidesComponentTypeEditPart.VISUAL_ID: {
303                        if (!domain2NotationMap.containsKey(view.getElement())) {
304                                result.addAll(PalladioComponentModelDiagramUpdater
305                                                .getProvidesComponentType_2105ContainedLinks(view));
306                        }
307                        if (!domain2NotationMap.containsKey(view.getElement())
308                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
309                                domain2NotationMap.put(view.getElement(), view);
310                        }
311                        break;
312                }
313                case SubSystemEditPart.VISUAL_ID: {
314                        if (!domain2NotationMap.containsKey(view.getElement())) {
315                                result.addAll(PalladioComponentModelDiagramUpdater
316                                                .getSubSystem_2106ContainedLinks(view));
317                        }
318                        if (!domain2NotationMap.containsKey(view.getElement())
319                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
320                                domain2NotationMap.put(view.getElement(), view);
321                        }
322                        break;
323                }
324                case InfrastructureInterfaceEditPart.VISUAL_ID: {
325                        if (!domain2NotationMap.containsKey(view.getElement())) {
326                                result.addAll(PalladioComponentModelDiagramUpdater
327                                                .getInfrastructureInterface_2109ContainedLinks(view));
328                        }
329                        if (!domain2NotationMap.containsKey(view.getElement())
330                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
331                                domain2NotationMap.put(view.getElement(), view);
332                        }
333                        break;
334                }
335                case VariableUsageEditPart.VISUAL_ID: {
336                        if (!domain2NotationMap.containsKey(view.getElement())) {
337                                result.addAll(PalladioComponentModelDiagramUpdater
338                                                .getVariableUsage_3104ContainedLinks(view));
339                        }
340                        if (!domain2NotationMap.containsKey(view.getElement())
341                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
342                                domain2NotationMap.put(view.getElement(), view);
343                        }
344                        break;
345                }
346                case OperationProvidedRoleEditPart.VISUAL_ID: {
347                        if (!domain2NotationMap.containsKey(view.getElement())) {
348                                result.addAll(PalladioComponentModelDiagramUpdater
349                                                .getOperationProvidedRole_4105ContainedLinks(view));
350                        }
351                        if (!domain2NotationMap.containsKey(view.getElement())
352                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
353                                domain2NotationMap.put(view.getElement(), view);
354                        }
355                        break;
356                }
357                case InfrastructureProvidedRoleEditPart.VISUAL_ID: {
358                        if (!domain2NotationMap.containsKey(view.getElement())) {
359                                result
360                                                .addAll(PalladioComponentModelDiagramUpdater
361                                                                .getInfrastructureProvidedRole_4111ContainedLinks(view));
362                        }
363                        if (!domain2NotationMap.containsKey(view.getElement())
364                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
365                                domain2NotationMap.put(view.getElement(), view);
366                        }
367                        break;
368                }
369                case InfrastructureRequiredRoleEditPart.VISUAL_ID: {
370                        if (!domain2NotationMap.containsKey(view.getElement())) {
371                                result
372                                                .addAll(PalladioComponentModelDiagramUpdater
373                                                                .getInfrastructureRequiredRole_4112ContainedLinks(view));
374                        }
375                        if (!domain2NotationMap.containsKey(view.getElement())
376                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
377                                domain2NotationMap.put(view.getElement(), view);
378                        }
379                        break;
380                }
381                case SinkRoleEditPart.VISUAL_ID: {
382                        if (!domain2NotationMap.containsKey(view.getElement())) {
383                                result.addAll(PalladioComponentModelDiagramUpdater
384                                                .getSinkRole_4109ContainedLinks(view));
385                        }
386                        if (!domain2NotationMap.containsKey(view.getElement())
387                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
388                                domain2NotationMap.put(view.getElement(), view);
389                        }
390                        break;
391                }
392                case OperationRequiredRoleEditPart.VISUAL_ID: {
393                        if (!domain2NotationMap.containsKey(view.getElement())) {
394                                result.addAll(PalladioComponentModelDiagramUpdater
395                                                .getOperationRequiredRole_4106ContainedLinks(view));
396                        }
397                        if (!domain2NotationMap.containsKey(view.getElement())
398                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
399                                domain2NotationMap.put(view.getElement(), view);
400                        }
401                        break;
402                }
403                case SourceRoleEditPart.VISUAL_ID: {
404                        if (!domain2NotationMap.containsKey(view.getElement())) {
405                                result.addAll(PalladioComponentModelDiagramUpdater
406                                                .getSourceRole_4110ContainedLinks(view));
407                        }
408                        if (!domain2NotationMap.containsKey(view.getElement())
409                                        || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
410                                domain2NotationMap.put(view.getElement(), view);
411                        }
412                        break;
413                }
414                }
415                for (Iterator children = view.getChildren().iterator(); children
416                                .hasNext();) {
417                        result.addAll(collectAllLinks((View) children.next(),
418                                        domain2NotationMap));
419                }
420                for (Iterator edges = view.getSourceEdges().iterator(); edges.hasNext();) {
421                        result.addAll(collectAllLinks((View) edges.next(),
422                                        domain2NotationMap));
423                }
424                return result;
425        }
426 
427        /**
428         * @generated
429         */
430        private Collection createConnections(Collection linkDescriptors,
431                        Map domain2NotationMap) {
432                List adapters = new LinkedList();
433                for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator
434                                .hasNext();) {
435                        final PalladioComponentModelLinkDescriptor nextLinkDescriptor = (PalladioComponentModelLinkDescriptor) linkDescriptorsIterator
436                                        .next();
437                        EditPart sourceEditPart = getEditPart(nextLinkDescriptor
438                                        .getSource(), domain2NotationMap);
439                        EditPart targetEditPart = getEditPart(nextLinkDescriptor
440                                        .getDestination(), domain2NotationMap);
441                        if (sourceEditPart == null || targetEditPart == null) {
442                                continue;
443                        }
444                        CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
445                                        nextLinkDescriptor.getSemanticAdapter(), String
446                                                        .valueOf(nextLinkDescriptor.getVisualID()),
447                                        ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost())
448                                                        .getDiagramPreferencesHint());
449                        CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(
450                                        descriptor);
451                        ccr.setType(RequestConstants.REQ_CONNECTION_START);
452                        ccr.setSourceEditPart(sourceEditPart);
453                        sourceEditPart.getCommand(ccr);
454                        ccr.setTargetEditPart(targetEditPart);
455                        ccr.setType(RequestConstants.REQ_CONNECTION_END);
456                        Command cmd = targetEditPart.getCommand(ccr);
457                        if (cmd != null && cmd.canExecute()) {
458                                executeCommand(cmd);
459                                IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
460                                if (viewAdapter != null) {
461                                        adapters.add(viewAdapter);
462                                }
463                        }
464                }
465                return adapters;
466        }
467 
468        /**
469         * @generated
470         */
471        private EditPart getEditPart(EObject domainModelElement,
472                        Map domain2NotationMap) {
473                View view = (View) domain2NotationMap.get(domainModelElement);
474                if (view != null) {
475                        return (EditPart) getHost().getViewer().getEditPartRegistry().get(
476                                        view);
477                }
478                return null;
479        }
480 
481        /**
482         * @generated
483         */
484        private Diagram getDiagram() {
485                return ((View) getHost().getModel()).getDiagram();
486        }
487 
488}

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