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

COVERAGE SUMMARY FOR SOURCE FILE [PalladioComponentModelNewDiagramFileWizard.java]

nameclass, %method, %block, %line, %
PalladioComponentModelNewDiagramFileWizard.java0%   (0/4)0%   (0/23)0%   (0/547)0%   (0/153)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelNewDiagramFileWizard0%   (0/1)0%   (0/6)0%   (0/221)0%   (0/68)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
PalladioComponentModelNewDiagramFileWizard (URI, EObject, TransactionalEditin... 0%   (0/1)0%   (0/110)0%   (0/32)
access$0 (PalladioComponentModelNewDiagramFileWizard): WizardNewFileCreationPage 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (PalladioComponentModelNewDiagramFileWizard): PalladioComponentModel... 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/88)0%   (0/30)
     
class PalladioComponentModelNewDiagramFileWizard$10%   (0/1)0%   (0/2)0%   (0/40)0%   (0/15)
PalladioComponentModelNewDiagramFileWizard$1 (PalladioComponentModelNewDiagra... 0%   (0/1)0%   (0/12)0%   (0/2)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/28)0%   (0/13)
     
class PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage0%   (0/1)0%   (0/11)0%   (0/262)0%   (0/66)
PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage (P... 0%   (0/1)0%   (0/7)0%   (0/3)
PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage (P... 0%   (0/1)0%   (0/21)0%   (0/7)
createControl (Composite): void 0%   (0/1)0%   (0/35)0%   (0/9)
createPageContent (Composite): void 0%   (0/1)0%   (0/54)0%   (0/13)
findSeffs (): void 0%   (0/1)0%   (0/25)0%   (0/7)
getComponentNameFromSEFF (ResourceDemandingSEFF): String 0%   (0/1)0%   (0/14)0%   (0/5)
getSeff (): ResourceDemandingSEFF 0%   (0/1)0%   (0/3)0%   (0/1)
getSelectionTitle (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getServiceNameFromSEFF (ResourceDemandingSEFF): String 0%   (0/1)0%   (0/9)0%   (0/2)
populateComboBox (): void 0%   (0/1)0%   (0/43)0%   (0/8)
validatePage (): boolean 0%   (0/1)0%   (0/49)0%   (0/10)
     
class PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage$ComboSelectionListener0%   (0/1)0%   (0/4)0%   (0/24)0%   (0/5)
PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage$Co... 0%   (0/1)0%   (0/6)0%   (0/1)
PalladioComponentModelNewDiagramFileWizard$DiagramRootElementSelectionPage$Co... 0%   (0/1)0%   (0/4)0%   (0/1)
widgetDefaultSelected (SelectionEvent): void 0%   (0/1)0%   (0/7)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/7)0%   (0/2)

1/*
2 * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.seff.part;
5 
6import java.io.IOException;
7import java.util.Collections;
8import java.util.LinkedList;
9import java.util.List;
10import java.util.Vector;
11 
12import org.eclipse.core.commands.ExecutionException;
13import org.eclipse.core.commands.operations.OperationHistoryFactory;
14import org.eclipse.core.resources.IFile;
15import org.eclipse.core.runtime.CoreException;
16import org.eclipse.core.runtime.IAdaptable;
17import org.eclipse.core.runtime.IPath;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.core.runtime.NullProgressMonitor;
20import org.eclipse.core.runtime.Path;
21import org.eclipse.emf.common.util.TreeIterator;
22import org.eclipse.emf.common.util.URI;
23import org.eclipse.emf.ecore.EObject;
24import org.eclipse.emf.ecore.resource.Resource;
25import org.eclipse.emf.ecore.resource.ResourceSet;
26import org.eclipse.emf.transaction.TransactionalEditingDomain;
27import org.eclipse.gmf.runtime.common.core.command.CommandResult;
28import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
29import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
30import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
31import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32import org.eclipse.gmf.runtime.notation.Diagram;
33import org.eclipse.jface.viewers.StructuredSelection;
34import org.eclipse.jface.wizard.Wizard;
35import org.eclipse.jface.wizard.WizardPage;
36import org.eclipse.osgi.util.NLS;
37import org.eclipse.swt.SWT;
38import org.eclipse.swt.events.SelectionEvent;
39import org.eclipse.swt.events.SelectionListener;
40import org.eclipse.swt.layout.GridData;
41import org.eclipse.swt.layout.GridLayout;
42import org.eclipse.swt.widgets.Combo;
43import org.eclipse.swt.widgets.Composite;
44import org.eclipse.swt.widgets.Label;
45import org.eclipse.ui.PartInitException;
46import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
47 
48import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.ResourceDemandingSEFFEditPart;
49import de.uka.ipd.sdq.pcm.repository.BasicComponent;
50import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF;
51 
52/**
53 * @generated
54 */
55public class PalladioComponentModelNewDiagramFileWizard extends Wizard {
56 
57        /**
58         * @generated
59         */
60        private WizardNewFileCreationPage myFileCreationPage;
61 
62        /**
63         * @generated
64         */
65        private ModelElementSelectionPage diagramRootElementSelectionPage;
66 
67        /**
68         * @generated
69         */
70        private TransactionalEditingDomain myEditingDomain;
71 
72        /**
73         * @generated not
74         */
75        private WizardNewFileCreationPage myDiagramFilenameSelectionPage;
76 
77        /**
78         * @generated not
79         */
80        private DiagramRootElementSelectionPage myDiagramRootElementSelectionPage;
81 
82        /**
83         * @generated not
84         */
85        public PalladioComponentModelNewDiagramFileWizard(URI domainModelURI,
86                        EObject diagramRoot, TransactionalEditingDomain editingDomain) {
87                assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
88                assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$
89                assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$
90 
91                myDiagramFilenameSelectionPage = new WizardNewFileCreationPage(
92                                Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageName,
93                                StructuredSelection.EMPTY);
94                myDiagramFilenameSelectionPage
95                                .setTitle(Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageTitle);
96                myDiagramFilenameSelectionPage
97                                .setDescription(NLS
98                                                .bind(
99                                                                Messages.PalladioComponentModelNewDiagramFileWizard_CreationPageDescription,
100                                                                ResourceDemandingSEFFEditPart.MODEL_ID));
101                //force correct file extension
102                myDiagramFilenameSelectionPage.setFileExtension("seff_diagram");
103 
104                IPath filePath;
105                if (domainModelURI.isPlatformResource()) {
106                        filePath = new Path(domainModelURI.trimSegments(1)
107                                        .toPlatformString(true));
108                } else if (domainModelURI.isFile()) {
109                        filePath = new Path(domainModelURI.trimSegments(1).toFileString());
110                } else {
111                        // TODO : use some default path
112                        throw new IllegalArgumentException(
113                                        "Unsupported URI: " + domainModelURI); //$NON-NLS-1$
114                }
115                myDiagramFilenameSelectionPage.setContainerFullPath(filePath);
116 
117                myDiagramRootElementSelectionPage = new DiagramRootElementSelectionPage(
118                                Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageName,
119                                diagramRoot);
120                myDiagramRootElementSelectionPage
121                                .setTitle(Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageTitle);
122                myDiagramRootElementSelectionPage
123                                .setDescription(Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageDescription);
124 
125                myEditingDomain = editingDomain;
126        }
127 
128        /**
129         * @generated not
130         */
131        public void addPages() {
132                addPage(myDiagramRootElementSelectionPage);
133                addPage(myDiagramFilenameSelectionPage);
134        }
135 
136        /**
137         * @generated not
138         */
139        public boolean performFinish() {
140                List<IFile> affectedFiles = new LinkedList<IFile>();
141                IFile diagramFile = myDiagramFilenameSelectionPage.createNewFile();
142                try {
143                        diagramFile.setCharset("UTF-8", new NullProgressMonitor()); //$NON-NLS-1$
144                } catch (CoreException e) {
145                        PalladioComponentModelSeffDiagramEditorPlugin.getInstance()
146                                        .logError("Unable to set charset for diagram file", e); //$NON-NLS-1$
147                }
148                affectedFiles.add(diagramFile);
149                org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI
150                                .createPlatformResourceURI(
151                                                diagramFile.getFullPath().toString(), true);
152                ResourceSet resourceSet = myEditingDomain.getResourceSet();
153                final Resource diagramResource = resourceSet
154                                .createResource(diagramModelURI);
155                AbstractTransactionalCommand command = new AbstractTransactionalCommand(
156                                myEditingDomain, "Initializing diagram contents", affectedFiles) { //$NON-NLS-1$
157 
158                        protected CommandResult doExecuteWithResult(
159                                        IProgressMonitor monitor, IAdaptable info)
160                                        throws ExecutionException {
161                                int diagramVID = PalladioComponentModelVisualIDRegistry
162                                                .getDiagramVisualID(myDiagramRootElementSelectionPage
163                                                                .getSeff());
164                                if (diagramVID != ResourceDemandingSEFFEditPart.VISUAL_ID) {
165                                        return CommandResult
166                                                        .newErrorCommandResult("Incorrect model object stored as a root resource object"); //$NON-NLS-1$
167                                }
168                                Diagram diagram = ViewService
169                                                .createDiagram(
170                                                                myDiagramRootElementSelectionPage.getSeff(),
171                                                                ResourceDemandingSEFFEditPart.MODEL_ID,
172                                                                PalladioComponentModelSeffDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
173                                diagramResource.getContents().add(diagram);
174                                return CommandResult.newOKCommandResult();
175                        }
176                };
177                try {
178                        OperationHistoryFactory.getOperationHistory().execute(command,
179                                        new NullProgressMonitor(), null);
180                        diagramResource.save(Collections.EMPTY_MAP);
181                        PalladioComponentModelDiagramEditorUtil
182                                        .openDiagram(diagramResource);
183                } catch (ExecutionException e) {
184                        PalladioComponentModelSeffDiagramEditorPlugin.getInstance()
185                                        .logError("Unable to create model and diagram", e); //$NON-NLS-1$
186                } catch (IOException ex) {
187                        PalladioComponentModelSeffDiagramEditorPlugin
188                                        .getInstance()
189                                        .logError(
190                                                        "Save operation failed for: " + diagramModelURI, ex); //$NON-NLS-1$
191                } catch (PartInitException ex) {
192                        PalladioComponentModelSeffDiagramEditorPlugin.getInstance()
193                                        .logError("Unable to open editor", ex); //$NON-NLS-1$
194                }
195                return true;
196        }
197 
198        /**
199         * @generated not
200         */
201        private class DiagramRootElementSelectionPage extends WizardPage {
202 
203                /**
204                 * @generated
205                 */
206                protected DiagramRootElementSelectionPage(String pageName) {
207                        super(pageName);
208                }
209 
210                private Combo myCombo;
211                private List<ResourceDemandingSEFF> myFoundSeffs;
212                private EObject myDiagramRoot;
213                private ResourceDemandingSEFF mySeff;
214 
215                /**
216                 * @generated not
217                 */
218                protected DiagramRootElementSelectionPage(String pageName,
219                                EObject diagramRoot) {
220                        super(pageName);
221                        myCombo = null;
222                        myFoundSeffs = new Vector<ResourceDemandingSEFF>();
223                        myDiagramRoot = diagramRoot;
224                        mySeff = null;
225                }
226 
227                public void createControl(Composite parent) {
228                        initializeDialogUnits(parent);
229                        Composite topLevel = new Composite(parent, SWT.NONE);
230                        topLevel.setLayout(new GridLayout());
231                        topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
232                                        | GridData.HORIZONTAL_ALIGN_FILL));
233                        topLevel.setFont(parent.getFont());
234                        setControl(topLevel);
235                        createPageContent(topLevel);
236                        setPageComplete(validatePage());
237                }
238 
239                private void createPageContent(Composite parent) {
240                        Composite panel = new Composite(parent, SWT.NONE);
241                        panel.setLayoutData(new GridData(GridData.FILL_BOTH));
242                        GridLayout layout = new GridLayout();
243                        panel.setLayout(layout);
244 
245                        Label label = new Label(panel, SWT.NONE);
246                        label.setText("Select Resource Demanding SEFF:");
247                        label.setLayoutData(new GridData(
248                                        GridData.HORIZONTAL_ALIGN_BEGINNING));
249 
250                        myCombo = new Combo(panel, SWT.DROP_DOWN | SWT.READ_ONLY);
251                        findSeffs();
252                        populateComboBox();
253                        myCombo.addSelectionListener(new ComboSelectionListener());
254                }
255 
256                private void populateComboBox() {
257                        if (myCombo == null) {
258                                return;
259                        }
260 
261                        myCombo.removeAll();
262                        for (ResourceDemandingSEFF seff : myFoundSeffs) {
263                                myCombo.add("Container: " + getComponentNameFromSEFF(seff)
264                                                + " - SEFF " + getServiceNameFromSEFF(seff) + " id: "
265                                                + seff.getId());
266                        }
267                }
268 
269                /**
270                 * helper function to determine the name of the component of a seff.
271                 * Assumes the seff can only be contained in a BasicComponent.
272                 * 
273                 * @param seff any seff
274                 * @return the name of the component the seff belongs to
275                 * or "" if the seff is not contained in a BasicComponent
276                 */
277                protected String getComponentNameFromSEFF(ResourceDemandingSEFF seff) {
278                        EObject container = seff.eContainer();
279                        if (container instanceof BasicComponent) {
280                                BasicComponent component = (BasicComponent) container;
281                                return component.getEntityName();
282                        } else {
283                                return "";
284                        }
285                }
286 
287                /**
288                 * helper function to determine the name of the service of a seff
289                 * 
290                 * @param seff any seff
291                 * @return the name of the service the seff belongs to
292                 * or "" if the seff belongs to no service
293                 * 
294                 * @generated not
295                 */
296                protected String getServiceNameFromSEFF(ResourceDemandingSEFF seff) {
297                        return (seff.getDescribedService__SEFF() == null ? "" : seff
298                                        .getDescribedService__SEFF().getEntityName());
299                }
300 
301                private void findSeffs() {
302 
303                        myFoundSeffs.clear();
304                        TreeIterator<EObject> it = myDiagramRoot.eAllContents();
305 
306                        while (it.hasNext()) {
307                                EObject possibleSeff = it.next();
308                                if (possibleSeff instanceof ResourceDemandingSEFF) {
309                                        myFoundSeffs.add((ResourceDemandingSEFF) possibleSeff);
310                                }
311                        }
312                }
313 
314                /**
315                 * @generated
316                 */
317                protected String getSelectionTitle() {
318                        return Messages.PalladioComponentModelNewDiagramFileWizard_RootSelectionPageSelectionTitle;
319                }
320 
321                protected ResourceDemandingSEFF getSeff() {
322                        return mySeff;
323                }
324 
325                /**
326                 * @generated not
327                 */
328                protected boolean validatePage() {
329                        mySeff = null;
330                        if (myCombo.getSelectionIndex() == -1) {
331                                return false;
332                        }
333 
334                        try {
335                                mySeff = myFoundSeffs.get(myCombo.getSelectionIndex());
336                        } catch (ArrayIndexOutOfBoundsException e) {
337                                return false;
338                        }
339 
340                        //propose a name in the diagram filename selection page
341                        String filename = getComponentNameFromSEFF(mySeff) + "."
342                                        + getServiceNameFromSEFF(mySeff) + ".seff_diagram";
343                        myDiagramFilenameSelectionPage.setFileName(filename);
344 
345                        return true;
346                }
347 
348                private class ComboSelectionListener implements SelectionListener {
349 
350                        public void widgetDefaultSelected(SelectionEvent e) {
351                                setPageComplete(validatePage());
352                        }
353 
354                        public void widgetSelected(SelectionEvent e) {
355                                setPageComplete(validatePage());
356                        }
357 
358                }
359        }
360}

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