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

COVERAGE SUMMARY FOR SOURCE FILE [PalladioComponentModelNewDiagramFileWizard.java]

nameclass, %method, %block, %line, %
PalladioComponentModelNewDiagramFileWizard.java0%   (0/3)0%   (0/10)0%   (0/293)0%   (0/99)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelNewDiagramFileWizard0%   (0/1)0%   (0/5)0%   (0/217)0%   (0/68)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
PalladioComponentModelNewDiagramFileWizard (URI, EObject, TransactionalEditin... 0%   (0/1)0%   (0/119)0%   (0/34)
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, U KA
3 */
4package de.uka.ipd.sdq.pcm.gmf.allocation.part;
5 
6import java.io.IOException;
7import java.util.Collections;
8import java.util.LinkedList;
9import java.util.List;
10 
11import org.eclipse.core.commands.ExecutionException;
12import org.eclipse.core.commands.operations.OperationHistoryFactory;
13import org.eclipse.core.resources.IFile;
14import org.eclipse.core.runtime.CoreException;
15import org.eclipse.core.runtime.IAdaptable;
16import org.eclipse.core.runtime.IPath;
17import org.eclipse.core.runtime.IProgressMonitor;
18import org.eclipse.core.runtime.NullProgressMonitor;
19import org.eclipse.core.runtime.Path;
20import org.eclipse.emf.common.util.URI;
21import org.eclipse.emf.ecore.EObject;
22import org.eclipse.emf.ecore.resource.Resource;
23import org.eclipse.emf.ecore.resource.ResourceSet;
24import org.eclipse.emf.transaction.TransactionalEditingDomain;
25import org.eclipse.gmf.runtime.common.core.command.CommandResult;
26import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
27import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
28import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
29import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
30import org.eclipse.gmf.runtime.notation.Diagram;
31import org.eclipse.jface.viewers.StructuredSelection;
32import org.eclipse.jface.wizard.Wizard;
33import org.eclipse.osgi.util.NLS;
34import org.eclipse.ui.PartInitException;
35import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
36 
37import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationEditPart;
38 
39/**
40 * @generated
41 */
42public class PalladioComponentModelNewDiagramFileWizard extends Wizard {
43 
44        /**
45         * @generated
46         */
47        private WizardNewFileCreationPage myFileCreationPage;
48 
49        /**
50         * @generated
51         */
52        private ModelElementSelectionPage diagramRootElementSelectionPage;
53 
54        /**
55         * @generated
56         */
57        private TransactionalEditingDomain myEditingDomain;
58 
59        /**
60         * @generated
61         */
62        public PalladioComponentModelNewDiagramFileWizard(URI domainModelURI,
63                        EObject diagramRoot, TransactionalEditingDomain editingDomain) {
64                assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
65                assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$
66                assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$
67 
68                myFileCreationPage = new WizardNewFileCreationPage(
69                                Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageName,
70                                StructuredSelection.EMPTY);
71                myFileCreationPage
72                                .setTitle(Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageTitle);
73                myFileCreationPage
74                                .setDescription(NLS
75                                                .bind(
76                                                                Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageDescription,
77                                                                AllocationEditPart.MODEL_ID));
78                IPath filePath;
79                String fileName = domainModelURI.trimFileExtension().lastSegment();
80                if (domainModelURI.isPlatformResource()) {
81                        filePath = new Path(domainModelURI.trimSegments(1)
82                                        .toPlatformString(true));
83                } else if (domainModelURI.isFile()) {
84                        filePath = new Path(domainModelURI.trimSegments(1).toFileString());
85                } else {
86                        // TODO : use some default path
87                        throw new IllegalArgumentException(
88                                        "Unsupported URI: " + domainModelURI); //$NON-NLS-1$
89                }
90                myFileCreationPage.setContainerFullPath(filePath);
91                myFileCreationPage.setFileName(PalladioComponentModelDiagramEditorUtil
92                                .getUniqueFileName(filePath, fileName, "allocation_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 != AllocationEditPart.VISUAL_ID) {
138                                        return CommandResult
139                                                        .newErrorCommandResult(Messages.PalladioComponentModelNewDiagramFileWizard_IncorrectRootError);
140                                }
141                                Diagram diagram = ViewService
142                                                .createDiagram(
143                                                                diagramRootElementSelectionPage
144                                                                                .getModelElement(),
145                                                                AllocationEditPart.MODEL_ID,
146                                                                PalladioComponentModelAllocationDiagramEditorPlugin.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                        PalladioComponentModelAllocationDiagramEditorPlugin.getInstance()
160                                        .logError("Unable to create model and diagram", e); //$NON-NLS-1$
161                } catch (IOException ex) {
162                        PalladioComponentModelAllocationDiagramEditorPlugin
163                                        .getInstance()
164                                        .logError(
165                                                        "Save operation failed for: " + diagramModelURI, ex); //$NON-NLS-1$
166                } catch (PartInitException ex) {
167                        PalladioComponentModelAllocationDiagramEditorPlugin.getInstance()
168                                        .logError("Unable to open editor", ex); //$NON-NLS-1$
169                }
170                return true;
171        }
172 
173        /**
174         * @generated
175         */
176        private static class DiagramRootElementSelectionPage extends
177                        ModelElementSelectionPage {
178 
179                /**
180                 * @generated
181                 */
182                protected DiagramRootElementSelectionPage(String pageName) {
183                        super(pageName);
184                }
185 
186                /**
187                 * @generated
188                 */
189                protected String getSelectionTitle() {
190                        return Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageSelectionTitle;
191                }
192 
193                /**
194                 * @generated
195                 */
196                protected boolean validatePage() {
197                        if (selectedModelElement == null) {
198                                setErrorMessage(Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageNoSelectionMessage);
199                                return false;
200                        }
201                        boolean result = ViewService
202                                        .getInstance()
203                                        .provides(
204                                                        new CreateDiagramViewOperation(
205                                                                        new EObjectAdapter(selectedModelElement),
206                                                                        AllocationEditPart.MODEL_ID,
207                                                                        PalladioComponentModelAllocationDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
208                        setErrorMessage(result ? null
209                                        : Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage);
210                        return result;
211                }
212        }
213}

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