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 [PalladioComponentModelDiagramEditorUtil.java]

nameclass, %method, %block, %line, %
PalladioComponentModelDiagramEditorUtil.java0%   (0/3)0%   (0/19)0%   (0/696)0%   (0/201)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelDiagramEditorUtil0%   (0/1)0%   (0/14)0%   (0/452)0%   (0/136)
PalladioComponentModelDiagramEditorUtil (): void 0%   (0/1)0%   (0/3)0%   (0/1)
access$0 (): Allocation 0%   (0/1)0%   (0/2)0%   (0/1)
access$1 (Allocation, Resource): void 0%   (0/1)0%   (0/4)0%   (0/1)
attachModelToResource (Allocation, Resource): void 0%   (0/1)0%   (0/6)0%   (0/2)
createDiagram (URI, URI, System, ResourceEnvironment, IProgressMonitor): Reso... 0%   (0/1)0%   (0/56)0%   (0/19)
createInitialModel (): Allocation 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/80)0%   (0/24)
PalladioComponentModelDiagramEditorUtil$1 (TransactionalEditingDomain, String... 0%   (0/1)0%   (0/21)0%   (0/2)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/59)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, U KA
3 */
4package de.uka.ipd.sdq.pcm.gmf.allocation.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.XMIResource;
31import org.eclipse.emf.ecore.xmi.XMLResource;
32import org.eclipse.emf.edit.ui.util.EditUIUtil;
33import org.eclipse.emf.transaction.TransactionalEditingDomain;
34import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
35import org.eclipse.gef.EditPart;
36import org.eclipse.gmf.runtime.common.core.command.CommandResult;
37import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
38import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
39import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
40import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
41import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
42import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
43import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
44import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
45import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
46import org.eclipse.gmf.runtime.notation.Diagram;
47import org.eclipse.gmf.runtime.notation.View;
48import org.eclipse.jface.dialogs.IDialogSettings;
49import org.eclipse.jface.wizard.Wizard;
50import org.eclipse.jface.wizard.WizardDialog;
51import org.eclipse.swt.widgets.Shell;
52import org.eclipse.ui.IWorkbenchPage;
53import org.eclipse.ui.PartInitException;
54 
55import org.eclipse.ui.PlatformUI;
56import org.eclipse.ui.part.FileEditorInput;
57import de.uka.ipd.sdq.pcm.allocation.Allocation;
58import de.uka.ipd.sdq.pcm.allocation.AllocationFactory;
59import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationEditPart;
60import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment;
61 
62/**
63 * @generated
64 */
65public class PalladioComponentModelDiagramEditorUtil {
66        /**
67         * @generated
68         */
69        public static Map getSaveOptions() {
70                Map saveOptions = new HashMap();
71                saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
72                saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,
73                                Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
74                return saveOptions;
75        }
76 
77        /**
78         * @generated
79         */
80        public static boolean openDiagram(Resource diagram)
81                        throws PartInitException {
82                String path = diagram.getURI().toPlatformString(true);
83                IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot()
84                                .findMember(new Path(path));
85                if (workspaceResource instanceof IFile) {
86                        IWorkbenchPage page = PlatformUI.getWorkbench()
87                                        .getActiveWorkbenchWindow().getActivePage();
88                        return null != page.openEditor(new FileEditorInput(
89                                        (IFile) workspaceResource),
90                                        PalladioComponentModelAllocationDiagramEditor.ID);
91                }
92                return false;
93        }
94 
95        /**
96         * @generated
97         */
98        public static void setCharset(IFile file) {
99                if (file == null) {
100                        return;
101                }
102                try {
103                        file.setCharset("UTF-8", new NullProgressMonitor()); //$NON-NLS-1$
104                } catch (CoreException e) {
105                        PalladioComponentModelAllocationDiagramEditorPlugin
106                                        .getInstance()
107                                        .logError(
108                                                        "Unable to set charset for file " + file.getFullPath(), e); //$NON-NLS-1$
109                }
110        }
111 
112        /**
113         * @generated
114         */
115        public static String getUniqueFileName(IPath containerFullPath,
116                        String fileName, String extension) {
117                if (containerFullPath == null) {
118                        containerFullPath = new Path(""); //$NON-NLS-1$
119                }
120                if (fileName == null || fileName.trim().length() == 0) {
121                        fileName = "default"; //$NON-NLS-1$
122                }
123                IPath filePath = containerFullPath.append(fileName);
124                if (extension != null && !extension.equals(filePath.getFileExtension())) {
125                        filePath = filePath.addFileExtension(extension);
126                }
127                extension = filePath.getFileExtension();
128                fileName = filePath.removeFileExtension().lastSegment();
129                int i = 1;
130                while (ResourcesPlugin.getWorkspace().getRoot().exists(filePath)) {
131                        i++;
132                        filePath = containerFullPath.append(fileName + i);
133                        if (extension != null) {
134                                filePath = filePath.addFileExtension(extension);
135                        }
136                }
137                return filePath.lastSegment();
138        }
139 
140        /**
141         * Runs the wizard in a dialog.
142         * 
143         * @generated
144         */
145        public static void runWizard(Shell shell, Wizard wizard, String settingsKey) {
146                IDialogSettings pluginDialogSettings = PalladioComponentModelAllocationDiagramEditorPlugin
147                                .getInstance().getDialogSettings();
148                IDialogSettings wizardDialogSettings = pluginDialogSettings
149                                .getSection(settingsKey);
150                if (wizardDialogSettings == null) {
151                        wizardDialogSettings = pluginDialogSettings
152                                        .addNewSection(settingsKey);
153                }
154                wizard.setDialogSettings(wizardDialogSettings);
155                WizardDialog dialog = new WizardDialog(shell, wizard);
156                dialog.create();
157                dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x),
158                                500);
159                dialog.open();
160        }
161 
162        /**
163         * This method should be called within a workspace modify operation since it creates resources.
164         * @generated not
165         */
166        public static Resource createDiagram(
167                        org.eclipse.emf.common.util.URI diagramURI,
168                        org.eclipse.emf.common.util.URI modelURI,
169                        final de.uka.ipd.sdq.pcm.system.System mySystem,
170                        final ResourceEnvironment myResourceEnv,
171                        IProgressMonitor progressMonitor) {
172                TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
173                                .createEditingDomain();
174                progressMonitor.beginTask("Creating diagram and model files", 3);
175                final Resource diagramResource = editingDomain.getResourceSet()
176                                .createResource(diagramURI);
177                final Resource modelResource = editingDomain.getResourceSet()
178                                .createResource(modelURI);
179                final String diagramName = diagramURI.lastSegment();
180                AbstractTransactionalCommand command = new AbstractTransactionalCommand(
181                                editingDomain,
182                                "Creating diagram and model", Collections.EMPTY_LIST) { //$NON-NLS-1$
183                        protected CommandResult doExecuteWithResult(
184                                        IProgressMonitor monitor, IAdaptable info)
185                                        throws ExecutionException {
186                                Allocation model = createInitialModel();
187                                model.setSystem_Allocation(mySystem);
188                                model.setTargetResourceEnvironment_Allocation(myResourceEnv);
189                                attachModelToResource(model, modelResource);
190 
191                                Diagram diagram = ViewService
192                                                .createDiagram(
193                                                                model,
194                                                                AllocationEditPart.MODEL_ID,
195                                                                PalladioComponentModelAllocationDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
196                                if (diagram != null) {
197                                        diagramResource.getContents().add(diagram);
198                                        diagram.setName(diagramName);
199                                        diagram.setElement(model);
200                                }
201 
202                                try {
203                                        Map options = new HashMap();
204                                        options.put(XMIResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
205                                        modelResource.save(options);
206                                        diagramResource.save(options);
207                                } catch (IOException e) {
208 
209                                        PalladioComponentModelAllocationDiagramEditorPlugin
210                                                        .getInstance()
211                                                        .logError(
212                                                                        "Unable to store model and diagram resources", e); //$NON-NLS-1$
213                                }
214                                return CommandResult.newOKCommandResult();
215                        }
216                };
217                try {
218                        OperationHistoryFactory.getOperationHistory().execute(command,
219                                        new SubProgressMonitor(progressMonitor, 1), null);
220                } catch (ExecutionException e) {
221                        PalladioComponentModelAllocationDiagramEditorPlugin.getInstance()
222                                        .logError("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 Allocation createInitialModel() {
236                Allocation alloc = AllocationFactory.eINSTANCE.createAllocation();
237 
238                //set default entity name
239                alloc.setEntityName("defaultAllocation"); //$NON-NLS-1$
240 
241                return alloc;
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(Allocation model,
251                        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.allocation.part]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov