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

nameclass, %method, %block, %line, %
OpenDiagramEditPolicy.java0%   (0/3)0%   (0/14)0%   (0/268)0%   (0/71)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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