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 [PalladioComponentModelNavigatorActionProvider.java]

nameclass, %method, %block, %line, %
PalladioComponentModelNavigatorActionProvider.java0%   (0/2)0%   (0/9)0%   (0/201)0%   (0/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelNavigatorActionProvider0%   (0/1)0%   (0/5)0%   (0/55)0%   (0/19)
PalladioComponentModelNavigatorActionProvider (): void 0%   (0/1)0%   (0/3)0%   (0/1)
fillActionBars (IActionBars): void 0%   (0/1)0%   (0/23)0%   (0/9)
fillContextMenu (IMenuManager): void 0%   (0/1)0%   (0/1)0%   (0/1)
init (ICommonActionExtensionSite): void 0%   (0/1)0%   (0/20)0%   (0/6)
makeActions (ICommonViewerWorkbenchSite): void 0%   (0/1)0%   (0/8)0%   (0/2)
     
class PalladioComponentModelNavigatorActionProvider$OpenDiagramAction0%   (0/1)0%   (0/4)0%   (0/146)0%   (0/44)
PalladioComponentModelNavigatorActionProvider$OpenDiagramAction (PalladioComp... 0%   (0/1)0%   (0/10)0%   (0/4)
getEditorInput (): IEditorInput 0%   (0/1)0%   (0/60)0%   (0/13)
run (): void 0%   (0/1)0%   (0/27)0%   (0/10)
selectionChanged (IStructuredSelection): void 0%   (0/1)0%   (0/49)0%   (0/17)

1/*
2 * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.resource.navigator;
5 
6import java.util.Iterator;
7 
8import org.eclipse.core.runtime.IAdaptable;
9import org.eclipse.emf.common.ui.URIEditorInput;
10import org.eclipse.emf.common.util.URI;
11import org.eclipse.emf.ecore.EObject;
12import org.eclipse.emf.ecore.util.EcoreUtil;
13import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
14import org.eclipse.gmf.runtime.notation.Diagram;
15import org.eclipse.gmf.runtime.notation.View;
16import org.eclipse.jface.action.Action;
17import org.eclipse.jface.action.IMenuManager;
18import org.eclipse.jface.viewers.IStructuredSelection;
19import org.eclipse.ui.IActionBars;
20import org.eclipse.ui.IEditorInput;
21import org.eclipse.ui.IWorkbenchPage;
22import org.eclipse.ui.PartInitException;
23import org.eclipse.ui.navigator.CommonActionProvider;
24import org.eclipse.ui.navigator.ICommonActionConstants;
25import org.eclipse.ui.navigator.ICommonActionExtensionSite;
26import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
27import org.eclipse.ui.part.FileEditorInput;
28 
29import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceEnvironmentEditPart;
30import de.uka.ipd.sdq.pcm.gmf.resource.part.Messages;
31import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelDiagramEditor;
32import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelDiagramEditorPlugin;
33import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry;
34 
35/**
36 * @generated
37 */
38public class PalladioComponentModelNavigatorActionProvider extends
39                CommonActionProvider {
40 
41        /**
42         * @generated
43         */
44        private boolean myContribute;
45 
46        /**
47         * @generated
48         */
49        private OpenDiagramAction myOpenDiagramAction;
50 
51        /**
52         * @generated
53         */
54        public void init(ICommonActionExtensionSite aSite) {
55                super.init(aSite);
56                if (aSite.getViewSite() instanceof ICommonViewerWorkbenchSite) {
57                        myContribute = true;
58                        makeActions((ICommonViewerWorkbenchSite) aSite.getViewSite());
59                } else {
60                        myContribute = false;
61                }
62        }
63 
64        /**
65         * @generated
66         */
67        private void makeActions(ICommonViewerWorkbenchSite viewerSite) {
68                myOpenDiagramAction = new OpenDiagramAction(viewerSite);
69        }
70 
71        /**
72         * @generated
73         */
74        public void fillActionBars(IActionBars actionBars) {
75                if (!myContribute) {
76                        return;
77                }
78                IStructuredSelection selection = (IStructuredSelection) getContext()
79                                .getSelection();
80                myOpenDiagramAction.selectionChanged(selection);
81                if (myOpenDiagramAction.isEnabled()) {
82                        actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,
83                                        myOpenDiagramAction);
84                }
85        }
86 
87        /**
88         * @generated
89         */
90        public void fillContextMenu(IMenuManager menu) {
91        }
92 
93        /**
94         * @generated
95         */
96        private class OpenDiagramAction extends Action {
97 
98                /**
99                 * @generated
100                 */
101                private Diagram myDiagram;
102 
103                /**
104                 * @generated
105                 */
106                private ICommonViewerWorkbenchSite myViewerSite;
107 
108                /**
109                 * @generated
110                 */
111                public OpenDiagramAction(ICommonViewerWorkbenchSite viewerSite) {
112                        super(Messages.NavigatorActionProvider_OpenDiagramActionName);
113                        myViewerSite = viewerSite;
114                }
115 
116                /**
117                 * @generated
118                 */
119                public final void selectionChanged(IStructuredSelection selection) {
120                        myDiagram = null;
121                        if (selection.size() == 1) {
122                                Object selectedElement = selection.getFirstElement();
123                                if (selectedElement instanceof PalladioComponentModelNavigatorItem) {
124                                        selectedElement = ((PalladioComponentModelNavigatorItem) selectedElement)
125                                                        .getView();
126                                } else if (selectedElement instanceof IAdaptable) {
127                                        selectedElement = ((IAdaptable) selectedElement)
128                                                        .getAdapter(View.class);
129                                }
130                                if (selectedElement instanceof Diagram) {
131                                        Diagram diagram = (Diagram) selectedElement;
132                                        if (ResourceEnvironmentEditPart.MODEL_ID
133                                                        .equals(PalladioComponentModelVisualIDRegistry
134                                                                        .getModelID(diagram))) {
135                                                myDiagram = diagram;
136                                        }
137                                }
138                        }
139                        setEnabled(myDiagram != null);
140                }
141 
142                /**
143                 * @generated
144                 */
145                public void run() {
146                        if (myDiagram == null || myDiagram.eResource() == null) {
147                                return;
148                        }
149 
150                        IEditorInput editorInput = getEditorInput();
151                        IWorkbenchPage page = myViewerSite.getPage();
152                        try {
153                                page.openEditor(editorInput,
154                                                PalladioComponentModelDiagramEditor.ID);
155                        } catch (PartInitException e) {
156                                PalladioComponentModelDiagramEditorPlugin.getInstance()
157                                                .logError("Exception while openning diagram", e); //$NON-NLS-1$
158                        }
159                }
160 
161                /**
162                 * @generated
163                 */
164                private IEditorInput getEditorInput() {
165                        for (Iterator it = myDiagram.eResource().getContents().iterator(); it
166                                        .hasNext();) {
167                                EObject nextEObject = (EObject) it.next();
168                                if (nextEObject == myDiagram) {
169                                        return new FileEditorInput(WorkspaceSynchronizer
170                                                        .getFile(myDiagram.eResource()));
171                                }
172                                if (nextEObject instanceof Diagram) {
173                                        break;
174                                }
175                        }
176                        URI uri = EcoreUtil.getURI(myDiagram);
177                        String editorName = uri.lastSegment()
178                                        + "#" + myDiagram.eResource().getContents().indexOf(myDiagram); //$NON-NLS-1$
179                        IEditorInput editorInput = new URIEditorInput(uri, editorName);
180                        return editorInput;
181                }
182 
183        }
184 
185}

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