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

nameclass, %method, %block, %line, %
PalladioComponentModelRepositoryDiagramEditor.java0%   (0/4)0%   (0/25)0%   (0/585)0%   (0/186)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelRepositoryDiagramEditor0%   (0/1)0%   (0/17)0%   (0/356)0%   (0/121)
PalladioComponentModelRepositoryDiagramEditor (): void 0%   (0/1)0%   (0/4)0%   (0/2)
configureGraphicalViewer (): void 0%   (0/1)0%   (0/21)0%   (0/7)
createPaletteRoot (PaletteRoot): PaletteRoot 0%   (0/1)0%   (0/11)0%   (0/3)
doSaveAs (): void 0%   (0/1)0%   (0/6)0%   (0/2)
getAdapter (Class): Object 0%   (0/1)0%   (0/12)0%   (0/3)
getContextID (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getContributorId (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getDocumentProvider (IEditorInput): IDocumentProvider 0%   (0/1)0%   (0/13)0%   (0/5)
getEditingDomain (): TransactionalEditingDomain 0%   (0/1)0%   (0/21)0%   (0/5)
getNavigatorSelection (): ISelection 0%   (0/1)0%   (0/30)0%   (0/10)
getPreferencesHint (): PreferencesHint 0%   (0/1)0%   (0/2)0%   (0/1)
getShowInContext (): ShowInContext 0%   (0/1)0%   (0/8)0%   (0/1)
gotoMarker (IMarker): void 0%   (0/1)0%   (0/5)0%   (0/2)
initializeGraphicalViewer (): void 0%   (0/1)0%   (0/13)0%   (0/6)
isSaveAsAllowed (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
performSaveAs (IProgressMonitor): void 0%   (0/1)0%   (0/189)0%   (0/65)
setDocumentProvider (IEditorInput): void 0%   (0/1)0%   (0/15)0%   (0/6)
     
class PalladioComponentModelRepositoryDiagramEditor$10%   (0/1)0%   (0/2)0%   (0/13)0%   (0/3)
PalladioComponentModelRepositoryDiagramEditor$1 (PalladioComponentModelReposi... 0%   (0/1)0%   (0/6)0%   (0/2)
getShowInTargetIds (): String [] 0%   (0/1)0%   (0/7)0%   (0/1)
     
class PalladioComponentModelRepositoryDiagramEditor$20%   (0/1)0%   (0/4)0%   (0/112)0%   (0/33)
PalladioComponentModelRepositoryDiagramEditor$2 (PalladioComponentModelReposi... 0%   (0/1)0%   (0/8)0%   (0/2)
adaptAllObjects (List): List 0%   (0/1)0%   (0/42)0%   (0/12)
getObjectsBeingDropped (): List 0%   (0/1)0%   (0/38)0%   (0/9)
isEnabled (DropTargetEvent): boolean 0%   (0/1)0%   (0/24)0%   (0/10)
     
class PalladioComponentModelRepositoryDiagramEditor$DropTargetListener0%   (0/1)0%   (0/2)0%   (0/104)0%   (0/32)
PalladioComponentModelRepositoryDiagramEditor$DropTargetListener (PalladioCom... 0%   (0/1)0%   (0/8)0%   (0/3)
getObjectsBeingDropped (): List 0%   (0/1)0%   (0/96)0%   (0/29)

1/*
2 *Copyright 2007, IPD, SDQ, University of Karlsruhe
3 */
4package de.uka.ipd.sdq.pcm.gmf.repository.part;
5 
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.HashSet;
9import java.util.Iterator;
10import java.util.List;
11 
12import org.eclipse.core.resources.IFile;
13import org.eclipse.core.resources.IMarker;
14import org.eclipse.core.resources.IWorkspaceRoot;
15import org.eclipse.core.resources.ResourcesPlugin;
16import org.eclipse.core.runtime.CoreException;
17import org.eclipse.core.runtime.IAdaptable;
18import org.eclipse.core.runtime.IPath;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.NullProgressMonitor;
22import org.eclipse.emf.common.ui.URIEditorInput;
23import org.eclipse.emf.common.util.URI;
24import org.eclipse.emf.ecore.EObject;
25import org.eclipse.emf.ecore.resource.Resource;
26import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
27import org.eclipse.emf.transaction.TransactionalEditingDomain;
28import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
29import org.eclipse.gef.EditPartViewer;
30import org.eclipse.gef.palette.PaletteRoot;
31import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
32import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
33import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
34import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetListener;
35import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
36import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
37import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider;
38import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
39import org.eclipse.gmf.runtime.notation.Diagram;
40import org.eclipse.gmf.runtime.notation.View;
41import org.eclipse.jface.dialogs.ErrorDialog;
42import org.eclipse.jface.dialogs.IMessageProvider;
43import org.eclipse.jface.dialogs.MessageDialog;
44import org.eclipse.jface.util.LocalSelectionTransfer;
45import org.eclipse.jface.util.TransferDropTargetListener;
46import org.eclipse.jface.viewers.ISelection;
47import org.eclipse.jface.viewers.IStructuredSelection;
48import org.eclipse.jface.viewers.StructuredSelection;
49import org.eclipse.jface.window.Window;
50import org.eclipse.osgi.util.NLS;
51import org.eclipse.swt.dnd.DropTargetEvent;
52import org.eclipse.swt.dnd.Transfer;
53import org.eclipse.swt.dnd.TransferData;
54import org.eclipse.swt.widgets.Shell;
55import org.eclipse.ui.IEditorInput;
56import org.eclipse.ui.IEditorMatchingStrategy;
57import org.eclipse.ui.IEditorReference;
58import org.eclipse.ui.IFileEditorInput;
59import org.eclipse.ui.PlatformUI;
60import org.eclipse.ui.dialogs.SaveAsDialog;
61import org.eclipse.ui.ide.IGotoMarker;
62import org.eclipse.ui.navigator.resources.ProjectExplorer;
63import org.eclipse.ui.part.FileEditorInput;
64import org.eclipse.ui.part.IShowInTargetList;
65import org.eclipse.ui.part.ShowInContext;
66 
67import de.uka.ipd.sdq.pcm.gmf.repository.navigator.PalladioComponentModelNavigatorItem;
68 
69/**
70 * @generated
71 */
72public class PalladioComponentModelRepositoryDiagramEditor extends
73                DiagramDocumentEditor implements IGotoMarker {
74 
75        /**
76         * @generated
77         */
78        public static final String ID = "de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelRepositoryDiagramEditorID"; //$NON-NLS-1$
79 
80        /**
81         * @generated
82         */
83        public static final String CONTEXT_ID = "de.uka.ipd.sdq.pcm.gmf.repository.ui.diagramContext"; //$NON-NLS-1$
84 
85        /**
86         * @generated
87         */
88        public PalladioComponentModelRepositoryDiagramEditor() {
89                super(true);
90        }
91 
92        /**
93         * @generated
94         */
95        protected String getContextID() {
96                return CONTEXT_ID;
97        }
98 
99        /**
100         * @generated
101         */
102        protected PaletteRoot createPaletteRoot(PaletteRoot existingPaletteRoot) {
103                PaletteRoot root = super.createPaletteRoot(existingPaletteRoot);
104                new PalladioComponentModelPaletteFactory().fillPalette(root);
105                return root;
106        }
107 
108        /**
109         * @generated
110         */
111        protected PreferencesHint getPreferencesHint() {
112                return PalladioComponentModelRepositoryDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
113        }
114 
115        /**
116         * @generated
117         */
118        public String getContributorId() {
119                return PalladioComponentModelRepositoryDiagramEditorPlugin.ID;
120        }
121 
122        /**
123         * @generated
124         */
125        public Object getAdapter(Class type) {
126                if (type == IShowInTargetList.class) {
127                        return new IShowInTargetList() {
128                                public String[] getShowInTargetIds() {
129                                        return new String[] { ProjectExplorer.VIEW_ID };
130                                }
131                        };
132                }
133                return super.getAdapter(type);
134        }
135 
136        /**
137         * @generated
138         */
139        protected IDocumentProvider getDocumentProvider(IEditorInput input) {
140                if (input instanceof IFileEditorInput
141                                || input instanceof URIEditorInput) {
142                        return PalladioComponentModelRepositoryDiagramEditorPlugin
143                                        .getInstance().getDocumentProvider();
144                }
145                return super.getDocumentProvider(input);
146        }
147 
148        /**
149         * @generated
150         */
151        public TransactionalEditingDomain getEditingDomain() {
152                IDocument document = getEditorInput() != null ? getDocumentProvider()
153                                .getDocument(getEditorInput()) : null;
154                if (document instanceof IDiagramDocument) {
155                        return ((IDiagramDocument) document).getEditingDomain();
156                }
157                return super.getEditingDomain();
158        }
159 
160        /**
161         * @generated
162         */
163        protected void setDocumentProvider(IEditorInput input) {
164                if (input instanceof IFileEditorInput
165                                || input instanceof URIEditorInput) {
166                        setDocumentProvider(PalladioComponentModelRepositoryDiagramEditorPlugin
167                                        .getInstance().getDocumentProvider());
168                } else {
169                        super.setDocumentProvider(input);
170                }
171        }
172 
173        /**
174         * @generated
175         */
176        public void gotoMarker(IMarker marker) {
177                MarkerNavigationService.getInstance().gotoMarker(this, marker);
178        }
179 
180        /**
181         * @generated
182         */
183        public boolean isSaveAsAllowed() {
184                return true;
185        }
186 
187        /**
188         * @generated
189         */
190        public void doSaveAs() {
191                performSaveAs(new NullProgressMonitor());
192        }
193 
194        /**
195         * @generated
196         */
197        protected void performSaveAs(IProgressMonitor progressMonitor) {
198                Shell shell = getSite().getShell();
199                IEditorInput input = getEditorInput();
200                SaveAsDialog dialog = new SaveAsDialog(shell);
201                IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input)
202                                .getFile()
203                                : null;
204                if (original != null) {
205                        dialog.setOriginalFile(original);
206                }
207                dialog.create();
208                IDocumentProvider provider = getDocumentProvider();
209                if (provider == null) {
210                        // editor has been programmatically closed while the dialog was open
211                        return;
212                }
213                if (provider.isDeleted(input) && original != null) {
214                        String message = NLS
215                                        .bind(
216                                                        Messages.PalladioComponentModelRepositoryDiagramEditor_SavingDeletedFile,
217                                                        original.getName());
218                        dialog.setErrorMessage(null);
219                        dialog.setMessage(message, IMessageProvider.WARNING);
220                }
221                if (dialog.open() == Window.CANCEL) {
222                        if (progressMonitor != null) {
223                                progressMonitor.setCanceled(true);
224                        }
225                        return;
226                }
227                IPath filePath = dialog.getResult();
228                if (filePath == null) {
229                        if (progressMonitor != null) {
230                                progressMonitor.setCanceled(true);
231                        }
232                        return;
233                }
234                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
235                IFile file = workspaceRoot.getFile(filePath);
236                final IEditorInput newInput = new FileEditorInput(file);
237                // Check if the editor is already open
238                IEditorMatchingStrategy matchingStrategy = getEditorDescriptor()
239                                .getEditorMatchingStrategy();
240                IEditorReference[] editorRefs = PlatformUI.getWorkbench()
241                                .getActiveWorkbenchWindow().getActivePage()
242                                .getEditorReferences();
243                for (int i = 0; i < editorRefs.length; i++) {
244                        if (matchingStrategy.matches(editorRefs[i], newInput)) {
245                                MessageDialog
246                                                .openWarning(
247                                                                shell,
248                                                                Messages.PalladioComponentModelRepositoryDiagramEditor_SaveAsErrorTitle,
249                                                                Messages.PalladioComponentModelRepositoryDiagramEditor_SaveAsErrorMessage);
250                                return;
251                        }
252                }
253                boolean success = false;
254                try {
255                        provider.aboutToChange(newInput);
256                        getDocumentProvider(newInput).saveDocument(progressMonitor,
257                                        newInput,
258                                        getDocumentProvider().getDocument(getEditorInput()), true);
259                        success = true;
260                } catch (CoreException x) {
261                        IStatus status = x.getStatus();
262                        if (status == null || status.getSeverity() != IStatus.CANCEL) {
263                                ErrorDialog
264                                                .openError(
265                                                                shell,
266                                                                Messages.PalladioComponentModelRepositoryDiagramEditor_SaveErrorTitle,
267                                                                Messages.PalladioComponentModelRepositoryDiagramEditor_SaveErrorMessage,
268                                                                x.getStatus());
269                        }
270                } finally {
271                        provider.changed(newInput);
272                        if (success) {
273                                setInput(newInput);
274                        }
275                }
276                if (progressMonitor != null) {
277                        progressMonitor.setCanceled(!success);
278                }
279        }
280 
281        /**
282         * @generated
283         */
284        public ShowInContext getShowInContext() {
285                return new ShowInContext(getEditorInput(), getNavigatorSelection());
286        }
287 
288        /**
289         * @generated
290         */
291        private ISelection getNavigatorSelection() {
292                IDiagramDocument document = getDiagramDocument();
293                if (document == null) {
294                        return StructuredSelection.EMPTY;
295                }
296                Diagram diagram = document.getDiagram();
297                IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
298                if (file != null) {
299                        PalladioComponentModelNavigatorItem item = new PalladioComponentModelNavigatorItem(
300                                        diagram, file, false);
301                        return new StructuredSelection(item);
302                }
303                return StructuredSelection.EMPTY;
304        }
305 
306        /**
307         * @generated
308         */
309        protected void configureGraphicalViewer() {
310                super.configureGraphicalViewer();
311                DiagramEditorContextMenuProvider provider = new DiagramEditorContextMenuProvider(
312                                this, getDiagramGraphicalViewer());
313                getDiagramGraphicalViewer().setContextMenu(provider);
314                getSite().registerContextMenu(ActionIds.DIAGRAM_EDITOR_CONTEXT_MENU,
315                                provider, getDiagramGraphicalViewer());
316        }
317 
318        /* Manual code to enable drag and drop */
319        @Override
320        protected void initializeGraphicalViewer() {
321                // TODO Auto-generated method stub
322                super.initializeGraphicalViewer();
323 
324                getDiagramGraphicalViewer().addDropTargetListener(
325                                (TransferDropTargetListener) new DiagramDropTargetListener(
326                                                getDiagramGraphicalViewer(), LocalSelectionTransfer
327                                                                .getTransfer()) {
328                                        protected List getObjectsBeingDropped() {
329                                                TransferData[] data = getCurrentEvent().dataTypes;
330                                                List eObjects = new ArrayList();
331 
332                                                for (int i = 0; i < data.length; i++) {
333                                                        if (LocalSelectionTransfer.getTransfer()
334                                                                        .isSupportedType(data[i])) {
335                                                                IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer
336                                                                                .getTransfer().nativeToJava(data[i]);
337                                                                eObjects.addAll(selection.toList());
338                                                        }
339                                                }
340                                                return adaptAllObjects(eObjects);
341                                        }
342 
343                                        private List adaptAllObjects(List objects) {
344                                                ArrayList result = new ArrayList();
345                                                for (Object o : objects) {
346                                                        Object resultingAdaptedObject = null;
347                                                        if (o instanceof EObject) {
348                                                                resultingAdaptedObject = o;
349                                                        } else if (o instanceof IAdaptable) {
350                                                                IAdaptable adaptable = (IAdaptable) o;
351                                                                resultingAdaptedObject = adaptable
352                                                                                .getAdapter(EObject.class);
353                                                        }
354                                                        if (!result.contains(resultingAdaptedObject)) {
355                                                                result.add(resultingAdaptedObject);
356                                                        }
357                                                }
358                                                return result;
359                                        }
360 
361                                        public boolean isEnabled(DropTargetEvent event) {
362                                                if (super.isEnabled(event)) {
363                                                        Object modelObj = getViewer().getContents()
364                                                                        .getModel();
365                                                        if (modelObj instanceof EObject) {
366                                                                List eObjects = getDropObjectsRequest()
367                                                                                .getObjects();
368 
369                                                                if (eObjects == null)
370                                                                        return false;
371 
372                                                                return true;
373                                                        }
374                                                }
375 
376                                                return false;
377                                        }
378                                });
379        }
380 
381        /**
382         * @generated
383         */
384        private abstract class DropTargetListener extends DiagramDropTargetListener {
385 
386                /**
387                 * @generated
388                 */
389                public DropTargetListener(EditPartViewer viewer, Transfer xfer) {
390                        super(viewer, xfer);
391                }
392 
393                /**
394                 * @generated
395                 */
396                protected List getObjectsBeingDropped() {
397                        TransferData data = getCurrentEvent().currentDataType;
398                        Collection uris = new HashSet();
399 
400                        Object transferedObject = getJavaObject(data);
401                        if (transferedObject instanceof IStructuredSelection) {
402                                IStructuredSelection selection = (IStructuredSelection) transferedObject;
403                                for (Iterator it = selection.iterator(); it.hasNext();) {
404                                        Object nextSelectedObject = it.next();
405                                        if (nextSelectedObject instanceof PalladioComponentModelNavigatorItem) {
406                                                View view = ((PalladioComponentModelNavigatorItem) nextSelectedObject)
407                                                                .getView();
408                                                nextSelectedObject = view.getElement();
409                                        } else if (nextSelectedObject instanceof IAdaptable) {
410                                                IAdaptable adaptable = (IAdaptable) nextSelectedObject;
411                                                nextSelectedObject = adaptable
412                                                                .getAdapter(EObject.class);
413                                        }
414 
415                                        if (nextSelectedObject instanceof EObject) {
416                                                EObject modelElement = (EObject) nextSelectedObject;
417                                                Resource modelElementResource = modelElement
418                                                                .eResource();
419                                                uris.add(modelElementResource.getURI().appendFragment(
420                                                                modelElementResource
421                                                                                .getURIFragment(modelElement)));
422                                        }
423                                }
424                        }
425 
426                        List result = new ArrayList();
427                        for (Iterator it = uris.iterator(); it.hasNext();) {
428                                URI nextURI = (URI) it.next();
429                                EObject modelObject = getEditingDomain().getResourceSet()
430                                                .getEObject(nextURI, true);
431                                result.add(modelObject);
432                        }
433                        return result;
434                }
435 
436                /**
437                 * @generated
438                 */
439                protected abstract Object getJavaObject(TransferData data);
440 
441        }
442 
443}

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