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

nameclass, %method, %block, %line, %
OpenSeffDiagramEditPolicy.java0%   (0/3)0%   (0/14)0%   (0/277)0%   (0/76)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OpenSeffDiagramEditPolicy0%   (0/1)0%   (0/2)0%   (0/36)0%   (0/11)
OpenSeffDiagramEditPolicy (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getOpenCommand (Request): Command 0%   (0/1)0%   (0/33)0%   (0/10)
     
class OpenSeffDiagramEditPolicy$OpenDiagramCommand0%   (0/1)0%   (0/10)0%   (0/198)0%   (0/50)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
OpenSeffDiagramEditPolicy$OpenDiagramCommand (HintedDiagramLinkStyle): void 0%   (0/1)0%   (0/10)0%   (0/4)
access$0 (OpenSeffDiagramEditPolicy$OpenDiagramCommand): HintedDiagramLinkStyle 0%   (0/1)0%   (0/3)0%   (0/1)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/61)0%   (0/18)
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 OpenSeffDiagramEditPolicy$OpenDiagramCommand$10%   (0/1)0%   (0/2)0%   (0/43)0%   (0/16)
OpenSeffDiagramEditPolicy$OpenDiagramCommand$1 (OpenSeffDiagramEditPolicy$Ope... 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.seff.ResourceDemandingSEFF;
44 
45/**
46 * @generated
47 */
48public class OpenSeffDiagramEditPolicy extends OpenEditPolicy {
49 
50        /**
51         * @generated
52         */
53        protected Command getOpenCommand(Request request) {
54                EditPart targetEditPart = getTargetEditPart(request);
55                if (false == targetEditPart.getModel() instanceof View) {
56                        return null;
57                }
58                View view = (View) targetEditPart.getModel();
59                Style link = view.getStyle(NotationPackage.eINSTANCE
60                                .getHintedDiagramLinkStyle());
61                if (false == link instanceof HintedDiagramLinkStyle) {
62                        return null;
63                }
64                return new ICommandProxy(new OpenDiagramCommand(
65                                (HintedDiagramLinkStyle) link));
66        }
67 
68        /**
69         * @generated
70         */
71        private static class OpenDiagramCommand extends
72                        AbstractTransactionalCommand {
73 
74                /**
75                 * @generated
76                 */
77                private final HintedDiagramLinkStyle diagramFacet;
78 
79                /**
80                 * @generated
81                 */
82                OpenDiagramCommand(HintedDiagramLinkStyle linkStyle) {
83                        // editing domain is taken for original diagram, 
84                        // if we open diagram from another file, we should use another editing domain
85                        super(TransactionUtil.getEditingDomain(linkStyle),
86                                        Messages.CommandName_OpenDiagram, null);
87                        diagramFacet = linkStyle;
88                }
89 
90                // FIXME canExecute if  !(readOnly && getDiagramToOpen == null), i.e. open works on ro diagrams only when there's associated diagram already
91 
92                /**
93                 * @generated not
94                 */
95                protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
96                                IAdaptable info) throws ExecutionException {
97                        try {
98                                Diagram diagram = getDiagramToOpen();
99                                if (diagram == null) {
100                                        diagram = intializeNewDiagram();
101                                }
102                                URI uri = EcoreUtil.getURI(diagram);
103                                String editorName = uri.lastSegment()
104                                                + "#"
105                                                + ((BasicComponent) ((ResourceDemandingSEFF) diagram
106                                                                .getElement()).eContainer()).getEntityName()
107                                                + "."
108                                                + ((ResourceDemandingSEFF) diagram.getElement())
109                                                                .getDescribedService__SEFF().getEntityName(); //$NON-NLS-1$
110                                IEditorInput editorInput = new URIEditorInput(uri, editorName);
111                                IWorkbenchPage page = PlatformUI.getWorkbench()
112                                                .getActiveWorkbenchWindow().getActivePage();
113                                page.openEditor(editorInput, getEditorID());
114                                return CommandResult.newOKCommandResult();
115                        } catch (Exception ex) {
116                                throw new ExecutionException("Can't open diagram", ex);
117                        }
118                }
119 
120                /**
121                 * @generated
122                 */
123                protected Diagram getDiagramToOpen() {
124                        return diagramFacet.getDiagramLink();
125                }
126 
127                /**
128                 * @generated
129                 */
130                protected Diagram intializeNewDiagram() throws ExecutionException {
131                        Diagram d = ViewService.createDiagram(getDiagramDomainElement(),
132                                        getDiagramKind(), getPreferencesHint());
133                        if (d == null) {
134                                throw new ExecutionException("Can't create diagram of '"
135                                                + getDiagramKind() + "' kind");
136                        }
137                        diagramFacet.setDiagramLink(d);
138                        assert diagramFacet.eResource() != null;
139                        diagramFacet.eResource().getContents().add(d);
140                        EObject container = diagramFacet.eContainer();
141                        while (container instanceof View) {
142                                ((View) container).persist();
143                                container = container.eContainer();
144                        }
145                        try {
146                                new WorkspaceModifyOperation() {
147                                        protected void execute(IProgressMonitor monitor)
148                                                        throws CoreException, InvocationTargetException,
149                                                        InterruptedException {
150                                                try {
151                                                        for (Iterator it = diagramFacet.eResource()
152                                                                        .getResourceSet().getResources().iterator(); it
153                                                                        .hasNext();) {
154                                                                Resource nextResource = (Resource) it.next();
155                                                                if (nextResource.isLoaded()
156                                                                                && !getEditingDomain().isReadOnly(
157                                                                                                nextResource)) {
158                                                                        nextResource
159                                                                                        .save(PalladioComponentModelDiagramEditorUtil
160                                                                                                        .getSaveOptions());
161                                                                }
162                                                        }
163                                                } catch (IOException ex) {
164                                                        throw new InvocationTargetException(ex,
165                                                                        "Save operation failed");
166                                                }
167                                        }
168                                }.run(null);
169                        } catch (InvocationTargetException e) {
170                                throw new ExecutionException("Can't create diagram of '"
171                                                + getDiagramKind() + "' kind", e);
172                        } catch (InterruptedException e) {
173                                throw new ExecutionException("Can't create diagram of '"
174                                                + getDiagramKind() + "' kind", e);
175                        }
176                        return d;
177                }
178 
179                /**
180                 * @generated
181                 */
182                protected EObject getDiagramDomainElement() {
183                        // use same element as associated with EP
184                        return ((View) diagramFacet.eContainer()).getElement();
185                }
186 
187                /**
188                 * @generated
189                 */
190                protected PreferencesHint getPreferencesHint() {
191                        // XXX prefhint from target diagram's editor?
192                        return PalladioComponentModelRepositoryDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
193                }
194 
195                /**
196                 * @generated
197                 */
198                protected String getDiagramKind() {
199                        return "PCM SEFF Model";
200                }
201 
202                /**
203                 * @generated
204                 */
205                protected String getEditorID() {
206                        return "de.uka.ipd.sdq.pcm.gmf.seff.part.SeffDiagramEditorID";
207                }
208        }
209 
210}

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