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

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