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

COVERAGE SUMMARY FOR SOURCE FILE [PalladioComponentModelNewDiagramFileWizard.java]

nameclass, %method, %block, %line, %
PalladioComponentModelNewDiagramFileWizard.java0%   (0/3)0%   (0/10)0%   (0/294)0%   (0/100)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelNewDiagramFileWizard0%   (0/1)0%   (0/5)0%   (0/218)0%   (0/69)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
PalladioComponentModelNewDiagramFileWizard (URI, EObject, TransactionalEditin... 0%   (0/1)0%   (0/120)0%   (0/35)
access$0 (PalladioComponentModelNewDiagramFileWizard): ModelElementSelectionPage 0%   (0/1)0%   (0/3)0%   (0/1)
addPages (): void 0%   (0/1)0%   (0/9)0%   (0/3)
performFinish (): boolean 0%   (0/1)0%   (0/78)0%   (0/29)
     
class PalladioComponentModelNewDiagramFileWizard$10%   (0/1)0%   (0/2)0%   (0/40)0%   (0/16)
PalladioComponentModelNewDiagramFileWizard$1 (PalladioComponentModelNewDiagra... 0%   (0/1)0%   (0/12)0%   (0/2)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/28)0%   (0/14)
     
class PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage0%   (0/1)0%   (0/3)0%   (0/36)0%   (0/16)
PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage (S... 0%   (0/1)0%   (0/4)0%   (0/2)
getSelectionTitle (): String 0%   (0/1)0%   (0/2)0%   (0/1)
validatePage (): boolean 0%   (0/1)0%   (0/30)0%   (0/13)

1/*
2 * Copyright 2007, SDQ, IPD, University of Karlsruhe
3 */
4package de.uka.ipd.sdq.pcm.gmf.usage.part;
5 
6import java.io.IOException;
7import java.util.LinkedList;
8import java.util.List;
9 
10import org.eclipse.core.commands.ExecutionException;
11import org.eclipse.core.commands.operations.OperationHistoryFactory;
12import org.eclipse.core.resources.IFile;
13import org.eclipse.core.runtime.IAdaptable;
14import org.eclipse.core.runtime.IPath;
15import org.eclipse.core.runtime.IProgressMonitor;
16import org.eclipse.core.runtime.NullProgressMonitor;
17import org.eclipse.core.runtime.Path;
18import org.eclipse.emf.common.util.URI;
19import org.eclipse.emf.ecore.EObject;
20import org.eclipse.emf.ecore.resource.Resource;
21import org.eclipse.emf.ecore.resource.ResourceSet;
22import org.eclipse.emf.transaction.TransactionalEditingDomain;
23import org.eclipse.gmf.runtime.common.core.command.CommandResult;
24import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
25import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
26import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
27import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
28import org.eclipse.gmf.runtime.notation.Diagram;
29import org.eclipse.jface.viewers.StructuredSelection;
30import org.eclipse.jface.wizard.Wizard;
31import org.eclipse.osgi.util.NLS;
32import org.eclipse.ui.PartInitException;
33import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
34 
35import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.UsageScenarioEditPart;
36 
37/**
38 * @generated
39 */
40public class PalladioComponentModelNewDiagramFileWizard extends Wizard {
41 
42        /**
43         * @generated
44         */
45        private TransactionalEditingDomain myEditingDomain;
46 
47        /**
48         * @generated
49         */
50        public PalladioComponentModelNewDiagramFileWizard(URI domainModelURI,
51                        EObject diagramRoot, TransactionalEditingDomain editingDomain) {
52                assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
53                assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$
54                assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$
55 
56                myFileCreationPage = new WizardNewFileCreationPage(
57                                Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageName,
58                                StructuredSelection.EMPTY);
59                myFileCreationPage
60                                .setTitle(Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageTitle);
61                myFileCreationPage
62                                .setDescription(NLS
63                                                .bind(
64                                                                Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageDescription,
65                                                                UsageScenarioEditPart.MODEL_ID));
66                IPath filePath;
67                String fileName = URI.decode(domainModelURI.trimFileExtension()
68                                .lastSegment());
69                if (domainModelURI.isPlatformResource()) {
70                        filePath = new Path(domainModelURI.trimSegments(1)
71                                        .toPlatformString(true));
72                } else if (domainModelURI.isFile()) {
73                        filePath = new Path(domainModelURI.trimSegments(1).toFileString());
74                } else {
75                        // TODO : use some default path
76                        throw new IllegalArgumentException(
77                                        "Unsupported URI: " + domainModelURI); //$NON-NLS-1$
78                }
79                myFileCreationPage.setContainerFullPath(filePath);
80                myFileCreationPage.setFileName(PalladioComponentModelDiagramEditorUtil
81                                .getUniqueFileName(filePath, fileName, "usagemodel_diagram")); //$NON-NLS-1$
82 
83                diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(
84                                Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageName);
85                diagramRootElementSelectionPage
86                                .setTitle(Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageTitle);
87                diagramRootElementSelectionPage
88                                .setDescription(Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageDescription);
89                diagramRootElementSelectionPage.setModelElement(diagramRoot);
90 
91                myEditingDomain = editingDomain;
92        }
93 
94        /**
95         * @generated
96         */
97        private WizardNewFileCreationPage myFileCreationPage;
98 
99        /**
100         * @generated
101         */
102        private ModelElementSelectionPage diagramRootElementSelectionPage;
103 
104        /**
105         * @generated
106         */
107        public void addPages() {
108                addPage(myFileCreationPage);
109                addPage(diagramRootElementSelectionPage);
110        }
111 
112        /**
113         * @generated
114         */
115        public boolean performFinish() {
116                List affectedFiles = new LinkedList();
117                IFile diagramFile = myFileCreationPage.createNewFile();
118                PalladioComponentModelDiagramEditorUtil.setCharset(diagramFile);
119                affectedFiles.add(diagramFile);
120                URI diagramModelURI = URI.createPlatformResourceURI(diagramFile
121                                .getFullPath().toString(), true);
122                ResourceSet resourceSet = myEditingDomain.getResourceSet();
123                final Resource diagramResource = resourceSet
124                                .createResource(diagramModelURI);
125                AbstractTransactionalCommand command = new AbstractTransactionalCommand(
126                                myEditingDomain,
127                                Messages.PalladioComponentModelNewDiagramFileWizard_InitDiagramCommand,
128                                affectedFiles) {
129 
130                        protected CommandResult doExecuteWithResult(
131                                        IProgressMonitor monitor, IAdaptable info)
132                                        throws ExecutionException {
133                                int diagramVID = PalladioComponentModelVisualIDRegistry
134                                                .getDiagramVisualID(diagramRootElementSelectionPage
135                                                                .getModelElement());
136                                if (diagramVID != UsageScenarioEditPart.VISUAL_ID) {
137                                        return CommandResult
138                                                        .newErrorCommandResult(Messages.PalladioComponentModelNewDiagramFileWizard_IncorrectRootError);
139                                }
140                                Diagram diagram = ViewService
141                                                .createDiagram(
142                                                                diagramRootElementSelectionPage
143                                                                                .getModelElement(),
144                                                                UsageScenarioEditPart.MODEL_ID,
145                                                                PalladioComponentModelUsageDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
146                                diagramResource.getContents().add(diagram);
147                                return CommandResult.newOKCommandResult();
148                        }
149                };
150                try {
151                        OperationHistoryFactory.getOperationHistory().execute(command,
152                                        new NullProgressMonitor(), null);
153                        diagramResource.save(PalladioComponentModelDiagramEditorUtil
154                                        .getSaveOptions());
155                        PalladioComponentModelDiagramEditorUtil
156                                        .openDiagram(diagramResource);
157                } catch (ExecutionException e) {
158                        PalladioComponentModelUsageDiagramEditorPlugin.getInstance()
159                                        .logError("Unable to create model and diagram", e); //$NON-NLS-1$
160                } catch (IOException ex) {
161                        PalladioComponentModelUsageDiagramEditorPlugin
162                                        .getInstance()
163                                        .logError(
164                                                        "Save operation failed for: " + diagramModelURI, ex); //$NON-NLS-1$
165                } catch (PartInitException ex) {
166                        PalladioComponentModelUsageDiagramEditorPlugin.getInstance()
167                                        .logError("Unable to open editor", ex); //$NON-NLS-1$
168                }
169                return true;
170        }
171 
172        /**
173         * @generated
174         */
175        private static class DiagramRootElementSelectionPage extends
176                        ModelElementSelectionPage {
177 
178                /**
179                 * @generated
180                 */
181                protected DiagramRootElementSelectionPage(String pageName) {
182                        super(pageName);
183                }
184 
185                /**
186                 * @generated
187                 */
188                protected String getSelectionTitle() {
189                        return Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageSelectionTitle;
190                }
191 
192                /**
193                 * @generated
194                 */
195                protected boolean validatePage() {
196                        if (selectedModelElement == null) {
197                                setErrorMessage(Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageNoSelectionMessage);
198                                return false;
199                        }
200                        boolean result = ViewService
201                                        .getInstance()
202                                        .provides(
203                                                        new CreateDiagramViewOperation(
204                                                                        new EObjectAdapter(selectedModelElement),
205                                                                        UsageScenarioEditPart.MODEL_ID,
206                                                                        PalladioComponentModelUsageDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
207                        setErrorMessage(result ? null
208                                        : Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage);
209                        return result;
210                }
211        }
212}

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