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

nameclass, %method, %block, %line, %
OpenCompositeDiagramEditPolicy.java0%   (0/3)0%   (0/14)0%   (0/267)0%   (0/71)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OpenCompositeDiagramEditPolicy0%   (0/1)0%   (0/2)0%   (0/36)0%   (0/11)
OpenCompositeDiagramEditPolicy (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getOpenCommand (Request): Command 0%   (0/1)0%   (0/33)0%   (0/10)
     
class OpenCompositeDiagramEditPolicy$OpenDiagramCommand0%   (0/1)0%   (0/10)0%   (0/188)0%   (0/45)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
OpenCompositeDiagramEditPolicy$OpenDiagramCommand (HintedDiagramLinkStyle): void 0%   (0/1)0%   (0/10)0%   (0/4)
access$0 (OpenCompositeDiagramEditPolicy$OpenDiagramCommand): HintedDiagramLi... 0%   (0/1)0%   (0/3)0%   (0/1)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/51)0%   (0/13)
getDiagramDomainElement (): EObject 0%   (0/1)0%   (0/6)0%   (0/1)
getDiagramKind (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getDiagramToOpen (): Diagram 0%   (0/1)0%   (0/4)0%   (0/1)
getEditorID (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getPreferencesHint (): PreferencesHint 0%   (0/1)0%   (0/2)0%   (0/1)
intializeNewDiagram (): Diagram 0%   (0/1)0%   (0/100)0%   (0/21)
     
class OpenCompositeDiagramEditPolicy$OpenDiagramCommand$10%   (0/1)0%   (0/2)0%   (0/43)0%   (0/16)
OpenCompositeDiagramEditPolicy$OpenDiagramCommand$1 (OpenCompositeDiagramEdit... 0%   (0/1)0%   (0/6)0%   (0/2)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/37)0%   (0/14)

1/*
2 * Copyright 2007, IPD, SDQ, University of Karlsruhe
3 */
4package de.uka.ipd.sdq.pcm.gmf.repository.edit.policies;
5 
6import java.io.IOException;
7import java.lang.reflect.InvocationTargetException;
8import java.util.Iterator;
9 
10import org.eclipse.core.commands.ExecutionException;
11import org.eclipse.core.runtime.CoreException;
12import org.eclipse.core.runtime.IAdaptable;
13import org.eclipse.core.runtime.IProgressMonitor;
14import org.eclipse.emf.common.ui.URIEditorInput;
15import org.eclipse.emf.common.util.URI;
16import org.eclipse.emf.ecore.EObject;
17import org.eclipse.emf.ecore.resource.Resource;
18import org.eclipse.emf.ecore.util.EcoreUtil;
19import org.eclipse.emf.transaction.util.TransactionUtil;
20import org.eclipse.gef.EditPart;
21import org.eclipse.gef.Request;
22import org.eclipse.gef.commands.Command;
23import org.eclipse.gmf.runtime.common.core.command.CommandResult;
24import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
25import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
26import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
27import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy;
28import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
29import org.eclipse.gmf.runtime.notation.Diagram;
30import org.eclipse.gmf.runtime.notation.HintedDiagramLinkStyle;
31import org.eclipse.gmf.runtime.notation.NotationPackage;
32import org.eclipse.gmf.runtime.notation.Style;
33import org.eclipse.gmf.runtime.notation.View;
34import org.eclipse.ui.IEditorInput;
35import org.eclipse.ui.IWorkbenchPage;
36import org.eclipse.ui.PlatformUI;
37import org.eclipse.ui.actions.WorkspaceModifyOperation;
38 
39import de.uka.ipd.sdq.pcm.gmf.repository.part.Messages;
40import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelDiagramEditorUtil;
41import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelRepositoryDiagramEditorPlugin;
42import de.uka.ipd.sdq.pcm.repository.BasicComponent;
43import de.uka.ipd.sdq.pcm.repository.CompositeComponent;
44import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF;
45 
46/**
47 * @generated
48 */
49public class OpenCompositeDiagramEditPolicy extends OpenEditPolicy {
50 
51        /**
52         * @generated
53         */
54        protected Command getOpenCommand(Request request) {
55                EditPart targetEditPart = getTargetEditPart(request);
56                if (false == targetEditPart.getModel() instanceof View) {
57                        return null;
58                }
59                View view = (View) targetEditPart.getModel();
60                Style link = view.getStyle(NotationPackage.eINSTANCE
61                                .getHintedDiagramLinkStyle());
62                if (false == link instanceof HintedDiagramLinkStyle) {
63                        return null;
64                }
65                return new ICommandProxy(new OpenDiagramCommand(
66                                (HintedDiagramLinkStyle) link));
67        }
68 
69        /**
70         * @generated
71         */
72        private static class OpenDiagramCommand extends
73                        AbstractTransactionalCommand {
74 
75                /**
76                 * @generated
77                 */
78                private final HintedDiagramLinkStyle diagramFacet;
79 
80                /**
81                 * @generated
82                 */
83                OpenDiagramCommand(HintedDiagramLinkStyle linkStyle) {
84                        // editing domain is taken for original diagram, 
85                        // if we open diagram from another file, we should use another editing domain
86                        super(TransactionUtil.getEditingDomain(linkStyle),
87                                        Messages.CommandName_OpenDiagram, null);
88                        diagramFacet = linkStyle;
89                }
90 
91                // FIXME canExecute if  !(readOnly && getDiagramToOpen == null), i.e. open works on ro diagrams only when there's associated diagram already
92 
93                /**
94                 * @generated not
95                 */
96                protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
97                                IAdaptable info) throws ExecutionException {
98 
99                        //                        try {
100                        //                                Diagram diagram = getDiagramToOpen();
101                        //                                if (diagram == null) {
102                        //                                        diagram = intializeNewDiagram();
103                        //                                }
104                        //                                URI uri = EcoreUtil.getURI(diagram);
105                        //                                String editorName = uri.lastSegment()
106                        //                                                + "#"
107                        //                                                + ((CompositeComponent) diagram.getElement().eContainer()).getEntityName(); 
108                        //                                IEditorInput editorInput = new URIEditorInput(uri, editorName);
109                        //                                IWorkbenchPage page = PlatformUI.getWorkbench()
110                        //                                                .getActiveWorkbenchWindow().getActivePage();
111                        //                                page.openEditor(editorInput, getEditorID());
112                        //                                return CommandResult.newOKCommandResult();
113                        //                        } catch (Exception ex) {
114                        //                                throw new ExecutionException("Can't open diagram", ex);
115                        //                        }
116 
117                        try {
118                                Diagram diagram = getDiagramToOpen();
119                                if (diagram == null) {
120                                        diagram = intializeNewDiagram();
121                                }
122                                URI uri = EcoreUtil.getURI(diagram);
123                                String editorName = uri.lastSegment()
124                                                + "#" + ((CompositeComponent) diagram.getElement()).getEntityName(); //$NON-NLS-1$
125                                IEditorInput editorInput = new URIEditorInput(uri, editorName);
126                                IWorkbenchPage page = PlatformUI.getWorkbench()
127                                                .getActiveWorkbenchWindow().getActivePage();
128                                page.openEditor(editorInput, getEditorID());
129                                return CommandResult.newOKCommandResult();
130                        } catch (Exception ex) {
131                                throw new ExecutionException("Can't open diagram", ex);
132                        }
133                }
134 
135                /**
136                 * @generated
137                 */
138                protected Diagram getDiagramToOpen() {
139                        return diagramFacet.getDiagramLink();
140                }
141 
142                /**
143                 * @generated
144                 */
145                protected Diagram intializeNewDiagram() throws ExecutionException {
146                        Diagram d = ViewService.createDiagram(getDiagramDomainElement(),
147                                        getDiagramKind(), getPreferencesHint());
148                        if (d == null) {
149                                throw new ExecutionException("Can't create diagram of '"
150                                                + getDiagramKind() + "' kind");
151                        }
152                        diagramFacet.setDiagramLink(d);
153                        assert diagramFacet.eResource() != null;
154                        diagramFacet.eResource().getContents().add(d);
155                        EObject container = diagramFacet.eContainer();
156                        while (container instanceof View) {
157                                ((View) container).persist();
158                                container = container.eContainer();
159                        }
160                        try {
161                                new WorkspaceModifyOperation() {
162                                        protected void execute(IProgressMonitor monitor)
163                                                        throws CoreException, InvocationTargetException,
164                                                        InterruptedException {
165                                                try {
166                                                        for (Iterator it = diagramFacet.eResource()
167                                                                        .getResourceSet().getResources().iterator(); it
168                                                                        .hasNext();) {
169                                                                Resource nextResource = (Resource) it.next();
170                                                                if (nextResource.isLoaded()
171                                                                                && !getEditingDomain().isReadOnly(
172                                                                                                nextResource)) {
173                                                                        nextResource
174                                                                                        .save(PalladioComponentModelDiagramEditorUtil
175                                                                                                        .getSaveOptions());
176                                                                }
177                                                        }
178                                                } catch (IOException ex) {
179                                                        throw new InvocationTargetException(ex,
180                                                                        "Save operation failed");
181                                                }
182                                        }
183                                }.run(null);
184                        } catch (InvocationTargetException e) {
185                                throw new ExecutionException("Can't create diagram of '"
186                                                + getDiagramKind() + "' kind", e);
187                        } catch (InterruptedException e) {
188                                throw new ExecutionException("Can't create diagram of '"
189                                                + getDiagramKind() + "' kind", e);
190                        }
191                        return d;
192                }
193 
194                /**
195                 * @generated
196                 */
197                protected EObject getDiagramDomainElement() {
198                        // use same element as associated with EP
199                        return ((View) diagramFacet.eContainer()).getElement();
200                }
201 
202                /**
203                 * @generated
204                 */
205                protected PreferencesHint getPreferencesHint() {
206                        // XXX prefhint from target diagram's editor?
207                        return PalladioComponentModelRepositoryDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
208                }
209 
210                /**
211                 * @generated
212                 */
213                protected String getDiagramKind() {
214                        return "CompositeModel";
215                }
216 
217                /**
218                 * @generated
219                 */
220                protected String getEditorID() {
221                        return "de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelDiagramEditorID";
222                }
223        }
224 
225}

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