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

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