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

COVERAGE SUMMARY FOR SOURCE FILE [PalladioComponentModelDiagramEditorUtil.java]

nameclass, %method, %block, %line, %
PalladioComponentModelDiagramEditorUtil.java0%   (0/3)0%   (0/19)0%   (0/671)0%   (0/205)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelDiagramEditorUtil0%   (0/1)0%   (0/14)0%   (0/450)0%   (0/140)
PalladioComponentModelDiagramEditorUtil (): void 0%   (0/1)0%   (0/3)0%   (0/1)
access$0 (): ComposedProvidingRequiringEntity 0%   (0/1)0%   (0/2)0%   (0/1)
access$1 (ComposedProvidingRequiringEntity, Resource): void 0%   (0/1)0%   (0/4)0%   (0/1)
attachModelToResource (ComposedProvidingRequiringEntity, Resource): void 0%   (0/1)0%   (0/6)0%   (0/2)
createDiagram (URI, URI, IProgressMonitor): Resource 0%   (0/1)0%   (0/54)0%   (0/23)
createInitialModel (): ComposedProvidingRequiringEntity 0%   (0/1)0%   (0/8)0%   (0/3)
findElementsInDiagramByID (DiagramEditPart, EObject, List): int 0%   (0/1)0%   (0/90)0%   (0/27)
findView (DiagramEditPart, EObject, PalladioComponentModelDiagramEditorUtil$L... 0%   (0/1)0%   (0/63)0%   (0/17)
getSaveOptions (): Map 0%   (0/1)0%   (0/16)0%   (0/5)
getUniqueFileName (IPath, String, String): String 0%   (0/1)0%   (0/66)0%   (0/16)
openDiagram (Resource): boolean 0%   (0/1)0%   (0/35)0%   (0/10)
runWizard (Shell, Wizard, String): void 0%   (0/1)0%   (0/38)0%   (0/14)
selectElementsInDiagram (IDiagramWorkbenchPart, List): void 0%   (0/1)0%   (0/42)0%   (0/12)
setCharset (IFile): void 0%   (0/1)0%   (0/23)0%   (0/8)
     
class PalladioComponentModelDiagramEditorUtil$10%   (0/1)0%   (0/2)0%   (0/57)0%   (0/24)
PalladioComponentModelDiagramEditorUtil$1 (TransactionalEditingDomain, String... 0%   (0/1)0%   (0/15)0%   (0/2)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/42)0%   (0/22)
     
class PalladioComponentModelDiagramEditorUtil$LazyElement2ViewMap0%   (0/1)0%   (0/3)0%   (0/164)0%   (0/42)
PalladioComponentModelDiagramEditorUtil$LazyElement2ViewMap (View, Set): void 0%   (0/1)0%   (0/14)0%   (0/5)
buildElement2ViewMap (View, Map, Set): Map 0%   (0/1)0%   (0/101)0%   (0/27)
getElement2ViewMap (): Map 0%   (0/1)0%   (0/49)0%   (0/10)

1/*
2 * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.composite.part;
5 
6import java.io.IOException;
7import java.util.ArrayList;
8import java.util.Collections;
9import java.util.HashMap;
10import java.util.Iterator;
11import java.util.List;
12import java.util.Map;
13import java.util.Set;
14 
15import org.eclipse.core.commands.ExecutionException;
16import org.eclipse.core.commands.operations.OperationHistoryFactory;
17import org.eclipse.core.resources.IFile;
18import org.eclipse.core.resources.IResource;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.core.runtime.IAdaptable;
22import org.eclipse.core.runtime.IPath;
23import org.eclipse.core.runtime.IProgressMonitor;
24import org.eclipse.core.runtime.NullProgressMonitor;
25import org.eclipse.core.runtime.Path;
26import org.eclipse.core.runtime.SubProgressMonitor;
27import org.eclipse.emf.common.util.URI;
28import org.eclipse.emf.ecore.EObject;
29import org.eclipse.emf.ecore.resource.Resource;
30import org.eclipse.emf.ecore.xmi.XMLResource;
31import org.eclipse.emf.transaction.TransactionalEditingDomain;
32import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
33import org.eclipse.gef.EditPart;
34import org.eclipse.gmf.runtime.common.core.command.CommandResult;
35import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
36import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
37import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
38import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
39import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
40import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
41import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
42import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
43import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
44import org.eclipse.gmf.runtime.notation.Diagram;
45import org.eclipse.gmf.runtime.notation.View;
46import org.eclipse.jface.dialogs.IDialogSettings;
47import org.eclipse.jface.wizard.Wizard;
48import org.eclipse.jface.wizard.WizardDialog;
49import org.eclipse.swt.widgets.Shell;
50import org.eclipse.ui.IWorkbenchPage;
51import org.eclipse.ui.PartInitException;
52import org.eclipse.ui.PlatformUI;
53import org.eclipse.ui.part.FileEditorInput;
54 
55import de.uka.ipd.sdq.pcm.core.entity.ComposedProvidingRequiringEntity;
56import de.uka.ipd.sdq.pcm.core.entity.EntityFactory;
57import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ComposedProvidingRequiringEntityEditPart;
58import de.uka.ipd.sdq.pcm.system.System;
59import de.uka.ipd.sdq.pcm.system.SystemFactory;
60 
61/**
62 * @generated
63 */
64public class PalladioComponentModelDiagramEditorUtil {
65        /**
66         * @generated
67         */
68        public static Map getSaveOptions() {
69                Map saveOptions = new HashMap();
70                saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
71                saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,
72                                Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
73                return saveOptions;
74        }
75 
76        /**
77         * @generated
78         */
79        public static boolean openDiagram(Resource diagram)
80                        throws PartInitException {
81                String path = diagram.getURI().toPlatformString(true);
82                IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot()
83                                .findMember(new Path(path));
84                if (workspaceResource instanceof IFile) {
85                        IWorkbenchPage page = PlatformUI.getWorkbench()
86                                        .getActiveWorkbenchWindow().getActivePage();
87                        return null != page.openEditor(new FileEditorInput(
88                                        (IFile) workspaceResource),
89                                        PalladioComponentModelDiagramEditor.ID);
90                }
91                return false;
92        }
93 
94        /**
95         * @generated
96         */
97        public static void setCharset(IFile file) {
98                if (file == null) {
99                        return;
100                }
101                try {
102                        file.setCharset("UTF-8", new NullProgressMonitor()); //$NON-NLS-1$
103                } catch (CoreException e) {
104                        PalladioComponentModelComposedStructureDiagramEditorPlugin
105                                        .getInstance()
106                                        .logError(
107                                                        "Unable to set charset for file " + file.getFullPath(), e); //$NON-NLS-1$
108                }
109        }
110 
111        /**
112         * @generated
113         */
114        public static String getUniqueFileName(IPath containerFullPath,
115                        String fileName, String extension) {
116                if (containerFullPath == null) {
117                        containerFullPath = new Path(""); //$NON-NLS-1$
118                }
119                if (fileName == null || fileName.trim().length() == 0) {
120                        fileName = "default"; //$NON-NLS-1$
121                }
122                IPath filePath = containerFullPath.append(fileName);
123                if (extension != null && !extension.equals(filePath.getFileExtension())) {
124                        filePath = filePath.addFileExtension(extension);
125                }
126                extension = filePath.getFileExtension();
127                fileName = filePath.removeFileExtension().lastSegment();
128                int i = 1;
129                while (ResourcesPlugin.getWorkspace().getRoot().exists(filePath)) {
130                        i++;
131                        filePath = containerFullPath.append(fileName + i);
132                        if (extension != null) {
133                                filePath = filePath.addFileExtension(extension);
134                        }
135                }
136                return filePath.lastSegment();
137        }
138 
139        /**
140         * Runs the wizard in a dialog.
141         * 
142         * @generated
143         */
144        public static void runWizard(Shell shell, Wizard wizard, String settingsKey) {
145                IDialogSettings pluginDialogSettings = PalladioComponentModelComposedStructureDiagramEditorPlugin
146                                .getInstance().getDialogSettings();
147                IDialogSettings wizardDialogSettings = pluginDialogSettings
148                                .getSection(settingsKey);
149                if (wizardDialogSettings == null) {
150                        wizardDialogSettings = pluginDialogSettings
151                                        .addNewSection(settingsKey);
152                }
153                wizard.setDialogSettings(wizardDialogSettings);
154                WizardDialog dialog = new WizardDialog(shell, wizard);
155                dialog.create();
156                dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x),
157                                500);
158                dialog.open();
159        }
160 
161        /**
162         * This method should be called within a workspace modify operation since it creates resources.
163         * @generated
164         */
165        public static Resource createDiagram(URI diagramURI, URI modelURI,
166                        IProgressMonitor progressMonitor) {
167                TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
168                                .createEditingDomain();
169                progressMonitor
170                                .beginTask(
171                                                Messages.PalladioComponentModelDiagramEditorUtil_CreateDiagramProgressTask,
172                                                3);
173                final Resource diagramResource = editingDomain.getResourceSet()
174                                .createResource(diagramURI);
175                final Resource modelResource = editingDomain.getResourceSet()
176                                .createResource(modelURI);
177                final String diagramName = diagramURI.lastSegment();
178                AbstractTransactionalCommand command = new AbstractTransactionalCommand(
179                                editingDomain,
180                                Messages.PalladioComponentModelDiagramEditorUtil_CreateDiagramCommandLabel,
181                                Collections.EMPTY_LIST) {
182                        protected CommandResult doExecuteWithResult(
183                                        IProgressMonitor monitor, IAdaptable info)
184                                        throws ExecutionException {
185                                ComposedProvidingRequiringEntity model = createInitialModel();
186                                attachModelToResource(model, modelResource);
187 
188                                Diagram diagram = ViewService
189                                                .createDiagram(
190                                                                model,
191                                                                ComposedProvidingRequiringEntityEditPart.MODEL_ID,
192                                                                PalladioComponentModelComposedStructureDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
193                                if (diagram != null) {
194                                        diagramResource.getContents().add(diagram);
195                                        diagram.setName(diagramName);
196                                        diagram.setElement(model);
197                                }
198 
199                                try {
200                                        modelResource
201                                                        .save(de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelDiagramEditorUtil
202                                                                        .getSaveOptions());
203                                        diagramResource
204                                                        .save(de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelDiagramEditorUtil
205                                                                        .getSaveOptions());
206                                } catch (IOException e) {
207 
208                                        PalladioComponentModelComposedStructureDiagramEditorPlugin
209                                                        .getInstance()
210                                                        .logError(
211                                                                        "Unable to store model and diagram resources", e); //$NON-NLS-1$
212                                }
213                                return CommandResult.newOKCommandResult();
214                        }
215                };
216                try {
217                        OperationHistoryFactory.getOperationHistory().execute(command,
218                                        new SubProgressMonitor(progressMonitor, 1), null);
219                } catch (ExecutionException e) {
220                        PalladioComponentModelComposedStructureDiagramEditorPlugin
221                                        .getInstance().logError(
222                                                        "Unable to create model and diagram", e); //$NON-NLS-1$
223                }
224                setCharset(WorkspaceSynchronizer.getFile(modelResource));
225                setCharset(WorkspaceSynchronizer.getFile(diagramResource));
226                return diagramResource;
227        }
228 
229        /**
230         * Create a new instance of domain element associated with canvas.
231         * <!-- begin-user-doc -->
232         * <!-- end-user-doc -->
233         * @generated not
234         */
235        private static ComposedProvidingRequiringEntity createInitialModel() {
236                System system = SystemFactory.eINSTANCE.createSystem();
237 
238                //set default entity name
239                system.setEntityName("defaultSystem"); //$NON-NLS-1$
240 
241                return system;
242        }
243 
244        /**
245         * Store model element in the resource.
246         * <!-- begin-user-doc -->
247         * <!-- end-user-doc -->
248         * @generated
249         */
250        private static void attachModelToResource(
251                        ComposedProvidingRequiringEntity model, Resource resource) {
252                resource.getContents().add(model);
253        }
254 
255        /**
256         * @generated
257         */
258        public static void selectElementsInDiagram(
259                        IDiagramWorkbenchPart diagramPart, List/*EditPart*/editParts) {
260                diagramPart.getDiagramGraphicalViewer().deselectAll();
261 
262                EditPart firstPrimary = null;
263                for (Iterator it = editParts.iterator(); it.hasNext();) {
264                        EditPart nextPart = (EditPart) it.next();
265                        diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
266                        if (firstPrimary == null && nextPart instanceof IPrimaryEditPart) {
267                                firstPrimary = nextPart;
268                        }
269                }
270 
271                if (!editParts.isEmpty()) {
272                        diagramPart.getDiagramGraphicalViewer().reveal(
273                                        firstPrimary != null ? firstPrimary : (EditPart) editParts
274                                                        .get(0));
275                }
276        }
277 
278        /**
279         * @generated
280         */
281        private static int findElementsInDiagramByID(DiagramEditPart diagramPart,
282                        EObject element, List editPartCollector) {
283                IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer) diagramPart
284                                .getViewer();
285                final int intialNumOfEditParts = editPartCollector.size();
286 
287                if (element instanceof View) { // support notation element lookup
288                        EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(
289                                        element);
290                        if (editPart != null) {
291                                editPartCollector.add(editPart);
292                                return 1;
293                        }
294                }
295 
296                String elementID = EMFCoreUtil.getProxyID(element);
297                List associatedParts = viewer.findEditPartsForElement(elementID,
298                                IGraphicalEditPart.class);
299                // perform the possible hierarchy disjoint -> take the top-most parts only
300                for (Iterator editPartIt = associatedParts.iterator(); editPartIt
301                                .hasNext();) {
302                        EditPart nextPart = (EditPart) editPartIt.next();
303                        EditPart parentPart = nextPart.getParent();
304                        while (parentPart != null && !associatedParts.contains(parentPart)) {
305                                parentPart = parentPart.getParent();
306                        }
307                        if (parentPart == null) {
308                                editPartCollector.add(nextPart);
309                        }
310                }
311 
312                if (intialNumOfEditParts == editPartCollector.size()) {
313                        if (!associatedParts.isEmpty()) {
314                                editPartCollector.add(associatedParts.iterator().next());
315                        } else {
316                                if (element.eContainer() != null) {
317                                        return findElementsInDiagramByID(diagramPart, element
318                                                        .eContainer(), editPartCollector);
319                                }
320                        }
321                }
322                return editPartCollector.size() - intialNumOfEditParts;
323        }
324 
325        /**
326         * @generated
327         */
328        public static View findView(DiagramEditPart diagramEditPart,
329                        EObject targetElement, LazyElement2ViewMap lazyElement2ViewMap) {
330                boolean hasStructuralURI = false;
331                if (targetElement.eResource() instanceof XMLResource) {
332                        hasStructuralURI = ((XMLResource) targetElement.eResource())
333                                        .getID(targetElement) == null;
334                }
335 
336                View view = null;
337                if (hasStructuralURI
338                                && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) {
339                        view = (View) lazyElement2ViewMap.getElement2ViewMap().get(
340                                        targetElement);
341                } else if (findElementsInDiagramByID(diagramEditPart, targetElement,
342                                lazyElement2ViewMap.editPartTmpHolder) > 0) {
343                        EditPart editPart = (EditPart) lazyElement2ViewMap.editPartTmpHolder
344                                        .get(0);
345                        lazyElement2ViewMap.editPartTmpHolder.clear();
346                        view = editPart.getModel() instanceof View ? (View) editPart
347                                        .getModel() : null;
348                }
349 
350                return (view == null) ? diagramEditPart.getDiagramView() : view;
351        }
352 
353        /**
354         * @generated
355         */
356        public static class LazyElement2ViewMap {
357                /**
358                 * @generated
359                 */
360                private Map element2ViewMap;
361 
362                /**
363                 * @generated
364                 */
365                private View scope;
366 
367                /**
368                 * @generated
369                 */
370                private Set elementSet;
371 
372                /**
373                 * @generated
374                 */
375                public final List editPartTmpHolder = new ArrayList();
376 
377                /**
378                 * @generated
379                 */
380                public LazyElement2ViewMap(View scope, Set elements) {
381                        this.scope = scope;
382                        this.elementSet = elements;
383                }
384 
385                /**
386                 * @generated
387                 */
388                public final Map getElement2ViewMap() {
389                        if (element2ViewMap == null) {
390                                element2ViewMap = new HashMap();
391                                // map possible notation elements to itself as these can't be found by view.getElement()
392                                for (Iterator it = elementSet.iterator(); it.hasNext();) {
393                                        EObject element = (EObject) it.next();
394                                        if (element instanceof View) {
395                                                View view = (View) element;
396                                                if (view.getDiagram() == scope.getDiagram()) {
397                                                        element2ViewMap.put(element, element); // take only those that part of our diagram
398                                                }
399                                        }
400                                }
401 
402                                buildElement2ViewMap(scope, element2ViewMap, elementSet);
403                        }
404                        return element2ViewMap;
405                }
406 
407                /**
408                 * @generated
409                 */
410                static Map buildElement2ViewMap(View parentView, Map element2ViewMap,
411                                Set elements) {
412                        if (elements.size() == element2ViewMap.size())
413                                return element2ViewMap;
414 
415                        if (parentView.isSetElement()
416                                        && !element2ViewMap.containsKey(parentView.getElement())
417                                        && elements.contains(parentView.getElement())) {
418                                element2ViewMap.put(parentView.getElement(), parentView);
419                                if (elements.size() == element2ViewMap.size())
420                                        return element2ViewMap;
421                        }
422 
423                        for (Iterator it = parentView.getChildren().iterator(); it
424                                        .hasNext();) {
425                                buildElement2ViewMap((View) it.next(), element2ViewMap,
426                                                elements);
427                                if (elements.size() == element2ViewMap.size())
428                                        return element2ViewMap;
429                        }
430                        for (Iterator it = parentView.getSourceEdges().iterator(); it
431                                        .hasNext();) {
432                                buildElement2ViewMap((View) it.next(), element2ViewMap,
433                                                elements);
434                                if (elements.size() == element2ViewMap.size())
435                                        return element2ViewMap;
436                        }
437                        for (Iterator it = parentView.getSourceEdges().iterator(); it
438                                        .hasNext();) {
439                                buildElement2ViewMap((View) it.next(), element2ViewMap,
440                                                elements);
441                                if (elements.size() == element2ViewMap.size())
442                                        return element2ViewMap;
443                        }
444                        return element2ViewMap;
445                }
446        } //LazyElement2ViewMap        
447 
448}

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