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

COVERAGE SUMMARY FOR SOURCE FILE [PalladioComponentModelNavigatorContentProvider.java]

nameclass, %method, %block, %line, %
PalladioComponentModelNavigatorContentProvider.java0%   (0/4)0%   (0/33)0%   (0/791)0%   (0/221)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelNavigatorContentProvider0%   (0/1)0%   (0/24)0%   (0/654)0%   (0/189)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/2)
PalladioComponentModelNavigatorContentProvider (): void 0%   (0/1)0%   (0/33)0%   (0/9)
access$0 (PalladioComponentModelNavigatorContentProvider): Viewer 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (PalladioComponentModelNavigatorContentProvider): AdapterFactoryEdit... 0%   (0/1)0%   (0/3)0%   (0/1)
access$2 (PalladioComponentModelNavigatorContentProvider): Runnable 0%   (0/1)0%   (0/3)0%   (0/1)
createNavigatorItems (Collection, Object, boolean): Collection 0%   (0/1)0%   (0/24)0%   (0/5)
dispose (): void 0%   (0/1)0%   (0/33)0%   (0/10)
getChildren (Object): Object [] 0%   (0/1)0%   (0/71)0%   (0/20)
getChildrenByType (Collection, String): Collection 0%   (0/1)0%   (0/25)0%   (0/5)
getDiagramLinksByType (Collection, String): Collection 0%   (0/1)0%   (0/25)0%   (0/5)
getElements (Object): Object [] 0%   (0/1)0%   (0/4)0%   (0/1)
getIncomingLinksByType (Collection, String): Collection 0%   (0/1)0%   (0/25)0%   (0/5)
getLinksSourceByType (Collection, String): Collection 0%   (0/1)0%   (0/33)0%   (0/8)
getLinksTargetByType (Collection, String): Collection 0%   (0/1)0%   (0/33)0%   (0/8)
getOutgoingLinksByType (Collection, String): Collection 0%   (0/1)0%   (0/25)0%   (0/5)
getParent (Object): Object 0%   (0/1)0%   (0/11)0%   (0/4)
getViewChildren (View, Object): Object [] 0%   (0/1)0%   (0/245)0%   (0/85)
hasChildren (Object): boolean 0%   (0/1)0%   (0/12)0%   (0/1)
init (ICommonContentExtensionSite): void 0%   (0/1)0%   (0/1)0%   (0/1)
inputChanged (Viewer, Object, Object): void 0%   (0/1)0%   (0/4)0%   (0/2)
isOwnView (View): boolean 0%   (0/1)0%   (0/5)0%   (0/2)
restoreState (IMemento): void 0%   (0/1)0%   (0/1)0%   (0/1)
saveState (IMemento): void 0%   (0/1)0%   (0/1)0%   (0/1)
selectViewsByType (Collection, String): Collection 0%   (0/1)0%   (0/30)0%   (0/6)
     
class PalladioComponentModelNavigatorContentProvider$10%   (0/1)0%   (0/2)0%   (0/19)0%   (0/5)
PalladioComponentModelNavigatorContentProvider$1 (PalladioComponentModelNavig... 0%   (0/1)0%   (0/6)0%   (0/2)
get (Object): Object 0%   (0/1)0%   (0/13)0%   (0/3)
     
class PalladioComponentModelNavigatorContentProvider$20%   (0/1)0%   (0/2)0%   (0/15)0%   (0/5)
PalladioComponentModelNavigatorContentProvider$2 (PalladioComponentModelNavig... 0%   (0/1)0%   (0/6)0%   (0/2)
run (): void 0%   (0/1)0%   (0/9)0%   (0/3)
     
class PalladioComponentModelNavigatorContentProvider$30%   (0/1)0%   (0/5)0%   (0/103)0%   (0/27)
PalladioComponentModelNavigatorContentProvider$3 (PalladioComponentModelNavig... 0%   (0/1)0%   (0/6)0%   (0/2)
dispose (): void 0%   (0/1)0%   (0/1)0%   (0/1)
handleResourceChanged (Resource): boolean 0%   (0/1)0%   (0/32)0%   (0/8)
handleResourceDeleted (Resource): boolean 0%   (0/1)0%   (0/32)0%   (0/8)
handleResourceMoved (Resource, URI): boolean 0%   (0/1)0%   (0/32)0%   (0/8)

1/*
2 * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.resource.navigator;
5 
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.Collections;
9import java.util.HashMap;
10import java.util.Iterator;
11 
12import org.eclipse.core.resources.IFile;
13import org.eclipse.emf.common.util.URI;
14import org.eclipse.emf.ecore.resource.Resource;
15import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
16import org.eclipse.emf.transaction.TransactionalEditingDomain;
17import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
18import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
19import org.eclipse.gmf.runtime.notation.Diagram;
20import org.eclipse.gmf.runtime.notation.Edge;
21import org.eclipse.gmf.runtime.notation.View;
22import org.eclipse.jface.viewers.Viewer;
23import org.eclipse.ui.IMemento;
24import org.eclipse.ui.navigator.ICommonContentExtensionSite;
25import org.eclipse.ui.navigator.ICommonContentProvider;
26 
27import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationEditPart;
28import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResource2EditPart;
29import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceConnectedResourceContainers_LinkingResourceEditPart;
30import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceNetworkSwitchCompartmentEditPart;
31import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationEditPart;
32import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEditPart;
33import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerResourceContainerCompartmentEditPart;
34import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceEnvironmentEditPart;
35import de.uka.ipd.sdq.pcm.gmf.resource.part.Messages;
36import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry;
37 
38/**
39 * @generated
40 */
41public class PalladioComponentModelNavigatorContentProvider implements
42                ICommonContentProvider {
43 
44        /**
45         * @generated
46         */
47        private static final Object[] EMPTY_ARRAY = new Object[0];
48 
49        /**
50         * @generated
51         */
52        private Viewer myViewer;
53 
54        /**
55         * @generated
56         */
57        private AdapterFactoryEditingDomain myEditingDomain;
58 
59        /**
60         * @generated
61         */
62        private WorkspaceSynchronizer myWorkspaceSynchronizer;
63 
64        /**
65         * @generated
66         */
67        private Runnable myViewerRefreshRunnable;
68 
69        /**
70         * @generated
71         */
72        public PalladioComponentModelNavigatorContentProvider() {
73                TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
74                                .createEditingDomain();
75                myEditingDomain = (AdapterFactoryEditingDomain) editingDomain;
76                myEditingDomain.setResourceToReadOnlyMap(new HashMap() {
77                        public Object get(Object key) {
78                                if (!containsKey(key)) {
79                                        put(key, Boolean.TRUE);
80                                }
81                                return super.get(key);
82                        }
83                });
84                myViewerRefreshRunnable = new Runnable() {
85                        public void run() {
86                                if (myViewer != null) {
87                                        myViewer.refresh();
88                                }
89                        }
90                };
91                myWorkspaceSynchronizer = new WorkspaceSynchronizer(editingDomain,
92                                new WorkspaceSynchronizer.Delegate() {
93                                        public void dispose() {
94                                        }
95 
96                                        public boolean handleResourceChanged(final Resource resource) {
97                                                for (Iterator it = myEditingDomain.getResourceSet()
98                                                                .getResources().iterator(); it.hasNext();) {
99                                                        Resource nextResource = (Resource) it.next();
100                                                        nextResource.unload();
101                                                }
102                                                if (myViewer != null) {
103                                                        myViewer.getControl().getDisplay().asyncExec(
104                                                                        myViewerRefreshRunnable);
105                                                }
106                                                return true;
107                                        }
108 
109                                        public boolean handleResourceDeleted(Resource resource) {
110                                                for (Iterator it = myEditingDomain.getResourceSet()
111                                                                .getResources().iterator(); it.hasNext();) {
112                                                        Resource nextResource = (Resource) it.next();
113                                                        nextResource.unload();
114                                                }
115                                                if (myViewer != null) {
116                                                        myViewer.getControl().getDisplay().asyncExec(
117                                                                        myViewerRefreshRunnable);
118                                                }
119                                                return true;
120                                        }
121 
122                                        public boolean handleResourceMoved(Resource resource,
123                                                        final URI newURI) {
124                                                for (Iterator it = myEditingDomain.getResourceSet()
125                                                                .getResources().iterator(); it.hasNext();) {
126                                                        Resource nextResource = (Resource) it.next();
127                                                        nextResource.unload();
128                                                }
129                                                if (myViewer != null) {
130                                                        myViewer.getControl().getDisplay().asyncExec(
131                                                                        myViewerRefreshRunnable);
132                                                }
133                                                return true;
134                                        }
135                                });
136        }
137 
138        /**
139         * @generated
140         */
141        public void dispose() {
142                myWorkspaceSynchronizer.dispose();
143                myWorkspaceSynchronizer = null;
144                myViewerRefreshRunnable = null;
145                for (Iterator it = myEditingDomain.getResourceSet().getResources()
146                                .iterator(); it.hasNext();) {
147                        Resource resource = (Resource) it.next();
148                        resource.unload();
149                }
150                ((TransactionalEditingDomain) myEditingDomain).dispose();
151                myEditingDomain = null;
152        }
153 
154        /**
155         * @generated
156         */
157        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
158                myViewer = viewer;
159        }
160 
161        /**
162         * @generated
163         */
164        public Object[] getElements(Object inputElement) {
165                return getChildren(inputElement);
166        }
167 
168        /**
169         * @generated
170         */
171        public void restoreState(IMemento aMemento) {
172        }
173 
174        /**
175         * @generated
176         */
177        public void saveState(IMemento aMemento) {
178        }
179 
180        /**
181         * @generated
182         */
183        public void init(ICommonContentExtensionSite aConfig) {
184        }
185 
186        /**
187         * @generated
188         */
189        public Object[] getChildren(Object parentElement) {
190                if (parentElement instanceof IFile) {
191                        IFile file = (IFile) parentElement;
192                        URI fileURI = URI.createPlatformResourceURI(file.getFullPath()
193                                        .toString(), true);
194                        Resource resource = myEditingDomain.getResourceSet().getResource(
195                                        fileURI, true);
196                        Collection result = new ArrayList();
197                        result.addAll(createNavigatorItems(selectViewsByType(resource
198                                        .getContents(), ResourceEnvironmentEditPart.MODEL_ID),
199                                        file, false));
200                        return result.toArray();
201                }
202 
203                if (parentElement instanceof PalladioComponentModelNavigatorGroup) {
204                        PalladioComponentModelNavigatorGroup group = (PalladioComponentModelNavigatorGroup) parentElement;
205                        return group.getChildren();
206                }
207 
208                if (parentElement instanceof PalladioComponentModelNavigatorItem) {
209                        PalladioComponentModelNavigatorItem navigatorItem = (PalladioComponentModelNavigatorItem) parentElement;
210                        if (navigatorItem.isLeaf() || !isOwnView(navigatorItem.getView())) {
211                                return EMPTY_ARRAY;
212                        }
213                        return getViewChildren(navigatorItem.getView(), parentElement);
214                }
215 
216                return EMPTY_ARRAY;
217        }
218 
219        /**
220         * @generated
221         */
222        private Object[] getViewChildren(View view, Object parentElement) {
223                switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) {
224 
225                case ResourceEnvironmentEditPart.VISUAL_ID: {
226                        Collection result = new ArrayList();
227                        PalladioComponentModelNavigatorGroup links = new PalladioComponentModelNavigatorGroup(
228                                        Messages.NavigatorGroupName_ResourceEnvironment_1000_links,
229                                        "icons/linksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
230                        Collection connectedViews = getChildrenByType(Collections
231                                        .singleton(view), PalladioComponentModelVisualIDRegistry
232                                        .getType(ResourceContainerEditPart.VISUAL_ID));
233                        result.addAll(createNavigatorItems(connectedViews, parentElement,
234                                        false));
235                        connectedViews = getChildrenByType(Collections.singleton(view),
236                                        PalladioComponentModelVisualIDRegistry
237                                                        .getType(LinkingResource2EditPart.VISUAL_ID));
238                        result.addAll(createNavigatorItems(connectedViews, parentElement,
239                                        false));
240                        connectedViews = getDiagramLinksByType(
241                                        Collections.singleton(view),
242                                        PalladioComponentModelVisualIDRegistry
243                                                        .getType(LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID));
244                        links
245                                        .addChildren(createNavigatorItems(connectedViews, links,
246                                                        false));
247                        if (!links.isEmpty()) {
248                                result.add(links);
249                        }
250                        return result.toArray();
251                }
252 
253                case ResourceContainerEditPart.VISUAL_ID: {
254                        Collection result = new ArrayList();
255                        PalladioComponentModelNavigatorGroup incominglinks = new PalladioComponentModelNavigatorGroup(
256                                        Messages.NavigatorGroupName_ResourceContainer_2001_incominglinks,
257                                        "icons/incomingLinksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
258                        Collection connectedViews = getChildrenByType(
259                                        Collections.singleton(view),
260                                        PalladioComponentModelVisualIDRegistry
261                                                        .getType(ResourceContainerResourceContainerCompartmentEditPart.VISUAL_ID));
262                        connectedViews = getChildrenByType(
263                                        connectedViews,
264                                        PalladioComponentModelVisualIDRegistry
265                                                        .getType(ProcessingResourceSpecificationEditPart.VISUAL_ID));
266                        result.addAll(createNavigatorItems(connectedViews, parentElement,
267                                        false));
268                        connectedViews = getIncomingLinksByType(
269                                        Collections.singleton(view),
270                                        PalladioComponentModelVisualIDRegistry
271                                                        .getType(LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID));
272                        incominglinks.addChildren(createNavigatorItems(connectedViews,
273                                        incominglinks, true));
274                        if (!incominglinks.isEmpty()) {
275                                result.add(incominglinks);
276                        }
277                        return result.toArray();
278                }
279 
280                case LinkingResource2EditPart.VISUAL_ID: {
281                        Collection result = new ArrayList();
282                        PalladioComponentModelNavigatorGroup outgoinglinks = new PalladioComponentModelNavigatorGroup(
283                                        Messages.NavigatorGroupName_LinkingResource_2003_outgoinglinks,
284                                        "icons/outgoingLinksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
285                        Collection connectedViews = getChildrenByType(
286                                        Collections.singleton(view),
287                                        PalladioComponentModelVisualIDRegistry
288                                                        .getType(LinkingResourceNetworkSwitchCompartmentEditPart.VISUAL_ID));
289                        connectedViews = getChildrenByType(
290                                        connectedViews,
291                                        PalladioComponentModelVisualIDRegistry
292                                                        .getType(CommunicationLinkResourceSpecificationEditPart.VISUAL_ID));
293                        result.addAll(createNavigatorItems(connectedViews, parentElement,
294                                        false));
295                        connectedViews = getOutgoingLinksByType(
296                                        Collections.singleton(view),
297                                        PalladioComponentModelVisualIDRegistry
298                                                        .getType(LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID));
299                        outgoinglinks.addChildren(createNavigatorItems(connectedViews,
300                                        outgoinglinks, true));
301                        if (!outgoinglinks.isEmpty()) {
302                                result.add(outgoinglinks);
303                        }
304                        return result.toArray();
305                }
306 
307                case LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID: {
308                        Collection result = new ArrayList();
309                        PalladioComponentModelNavigatorGroup target = new PalladioComponentModelNavigatorGroup(
310                                        Messages.NavigatorGroupName_LinkingResourceConnectedResourceContainers_LinkingResource_4002_target,
311                                        "icons/linkTargetNavigatorGroup.gif", parentElement); //$NON-NLS-1$
312                        PalladioComponentModelNavigatorGroup source = new PalladioComponentModelNavigatorGroup(
313                                        Messages.NavigatorGroupName_LinkingResourceConnectedResourceContainers_LinkingResource_4002_source,
314                                        "icons/linkSourceNavigatorGroup.gif", parentElement); //$NON-NLS-1$
315                        Collection connectedViews = getLinksTargetByType(Collections
316                                        .singleton(view), PalladioComponentModelVisualIDRegistry
317                                        .getType(ResourceContainerEditPart.VISUAL_ID));
318                        target.addChildren(createNavigatorItems(connectedViews, target,
319                                        true));
320                        connectedViews = getLinksSourceByType(Collections.singleton(view),
321                                        PalladioComponentModelVisualIDRegistry
322                                                        .getType(LinkingResource2EditPart.VISUAL_ID));
323                        source.addChildren(createNavigatorItems(connectedViews, source,
324                                        true));
325                        if (!target.isEmpty()) {
326                                result.add(target);
327                        }
328                        if (!source.isEmpty()) {
329                                result.add(source);
330                        }
331                        return result.toArray();
332                }
333                }
334                return EMPTY_ARRAY;
335        }
336 
337        /**
338         * @generated
339         */
340        private Collection getLinksSourceByType(Collection edges, String type) {
341                Collection result = new ArrayList();
342                for (Iterator it = edges.iterator(); it.hasNext();) {
343                        Edge nextEdge = (Edge) it.next();
344                        View nextEdgeSource = nextEdge.getSource();
345                        if (type.equals(nextEdgeSource.getType())
346                                        && isOwnView(nextEdgeSource)) {
347                                result.add(nextEdgeSource);
348                        }
349                }
350                return result;
351        }
352 
353        /**
354         * @generated
355         */
356        private Collection getLinksTargetByType(Collection edges, String type) {
357                Collection result = new ArrayList();
358                for (Iterator it = edges.iterator(); it.hasNext();) {
359                        Edge nextEdge = (Edge) it.next();
360                        View nextEdgeTarget = nextEdge.getTarget();
361                        if (type.equals(nextEdgeTarget.getType())
362                                        && isOwnView(nextEdgeTarget)) {
363                                result.add(nextEdgeTarget);
364                        }
365                }
366                return result;
367        }
368 
369        /**
370         * @generated
371         */
372        private Collection getOutgoingLinksByType(Collection nodes, String type) {
373                Collection result = new ArrayList();
374                for (Iterator it = nodes.iterator(); it.hasNext();) {
375                        View nextNode = (View) it.next();
376                        result.addAll(selectViewsByType(nextNode.getSourceEdges(), type));
377                }
378                return result;
379        }
380 
381        /**
382         * @generated
383         */
384        private Collection getIncomingLinksByType(Collection nodes, String type) {
385                Collection result = new ArrayList();
386                for (Iterator it = nodes.iterator(); it.hasNext();) {
387                        View nextNode = (View) it.next();
388                        result.addAll(selectViewsByType(nextNode.getTargetEdges(), type));
389                }
390                return result;
391        }
392 
393        /**
394         * @generated
395         */
396        private Collection getChildrenByType(Collection nodes, String type) {
397                Collection result = new ArrayList();
398                for (Iterator it = nodes.iterator(); it.hasNext();) {
399                        View nextNode = (View) it.next();
400                        result.addAll(selectViewsByType(nextNode.getChildren(), type));
401                }
402                return result;
403        }
404 
405        /**
406         * @generated
407         */
408        private Collection getDiagramLinksByType(Collection diagrams, String type) {
409                Collection result = new ArrayList();
410                for (Iterator it = diagrams.iterator(); it.hasNext();) {
411                        Diagram nextDiagram = (Diagram) it.next();
412                        result.addAll(selectViewsByType(nextDiagram.getEdges(), type));
413                }
414                return result;
415        }
416 
417        /**
418         * @generated
419         */
420        private Collection selectViewsByType(Collection views, String type) {
421                Collection result = new ArrayList();
422                for (Iterator it = views.iterator(); it.hasNext();) {
423                        View nextView = (View) it.next();
424                        if (type.equals(nextView.getType()) && isOwnView(nextView)) {
425                                result.add(nextView);
426                        }
427                }
428                return result;
429        }
430 
431        /**
432         * @generated
433         */
434        private boolean isOwnView(View view) {
435                return ResourceEnvironmentEditPart.MODEL_ID
436                                .equals(PalladioComponentModelVisualIDRegistry.getModelID(view));
437        }
438 
439        /**
440         * @generated
441         */
442        private Collection createNavigatorItems(Collection views, Object parent,
443                        boolean isLeafs) {
444                Collection result = new ArrayList();
445                for (Iterator it = views.iterator(); it.hasNext();) {
446                        result.add(new PalladioComponentModelNavigatorItem(
447                                        (View) it.next(), parent, isLeafs));
448                }
449                return result;
450        }
451 
452        /**
453         * @generated
454         */
455        public Object getParent(Object element) {
456                if (element instanceof PalladioComponentModelAbstractNavigatorItem) {
457                        PalladioComponentModelAbstractNavigatorItem abstractNavigatorItem = (PalladioComponentModelAbstractNavigatorItem) element;
458                        return abstractNavigatorItem.getParent();
459                }
460                return null;
461        }
462 
463        /**
464         * @generated
465         */
466        public boolean hasChildren(Object element) {
467                return element instanceof IFile || getChildren(element).length > 0;
468        }
469 
470}

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