1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.providers; |
5 | |
6 | import java.util.Arrays; |
7 | import java.util.Map; |
8 | |
9 | import org.eclipse.core.resources.IFile; |
10 | import org.eclipse.core.resources.IMarker; |
11 | import org.eclipse.core.resources.IResource; |
12 | import org.eclipse.core.runtime.CoreException; |
13 | import org.eclipse.core.runtime.IStatus; |
14 | import org.eclipse.emf.ecore.EObject; |
15 | import org.eclipse.gef.EditPart; |
16 | import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; |
17 | import org.eclipse.gmf.runtime.emf.ui.providers.marker.AbstractModelMarkerNavigationProvider; |
18 | |
19 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelDiagramEditorUtil; |
20 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelUsageDiagramEditorPlugin; |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public class PalladioComponentModelMarkerNavigationProvider extends |
26 | AbstractModelMarkerNavigationProvider { |
27 | |
28 | /** |
29 | * @generated |
30 | */ |
31 | public static final String MARKER_TYPE = PalladioComponentModelUsageDiagramEditorPlugin.ID |
32 | + ".diagnostic"; //$NON-NLS-1$ |
33 | |
34 | /** |
35 | * @generated |
36 | */ |
37 | protected void doGotoMarker(IMarker marker) { |
38 | String elementId = marker |
39 | .getAttribute( |
40 | org.eclipse.gmf.runtime.common.core.resources.IMarker.ELEMENT_ID, |
41 | null); |
42 | if (elementId == null || !(getEditor() instanceof DiagramEditor)) { |
43 | return; |
44 | } |
45 | DiagramEditor editor = (DiagramEditor) getEditor(); |
46 | Map editPartRegistry = editor.getDiagramGraphicalViewer() |
47 | .getEditPartRegistry(); |
48 | EObject targetView = editor.getDiagram().eResource().getEObject( |
49 | elementId); |
50 | if (targetView == null) { |
51 | return; |
52 | } |
53 | EditPart targetEditPart = (EditPart) editPartRegistry.get(targetView); |
54 | if (targetEditPart != null) { |
55 | PalladioComponentModelDiagramEditorUtil.selectElementsInDiagram( |
56 | editor, Arrays.asList(new EditPart[] { targetEditPart })); |
57 | } |
58 | } |
59 | |
60 | /** |
61 | * @generated |
62 | */ |
63 | public static void deleteMarkers(IResource resource) { |
64 | try { |
65 | resource.deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO); |
66 | } catch (CoreException e) { |
67 | PalladioComponentModelUsageDiagramEditorPlugin.getInstance() |
68 | .logError("Failed to delete validation markers", e); //$NON-NLS-1$ |
69 | } |
70 | } |
71 | |
72 | /** |
73 | * @generated |
74 | */ |
75 | public static IMarker addMarker(IFile file, String elementId, |
76 | String location, String message, int statusSeverity) { |
77 | IMarker marker = null; |
78 | try { |
79 | marker = file.createMarker(MARKER_TYPE); |
80 | marker.setAttribute(IMarker.MESSAGE, message); |
81 | marker.setAttribute(IMarker.LOCATION, location); |
82 | marker |
83 | .setAttribute( |
84 | org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, |
85 | elementId); |
86 | int markerSeverity = IMarker.SEVERITY_INFO; |
87 | if (statusSeverity == IStatus.WARNING) { |
88 | markerSeverity = IMarker.SEVERITY_WARNING; |
89 | } else if (statusSeverity == IStatus.ERROR |
90 | || statusSeverity == IStatus.CANCEL) { |
91 | markerSeverity = IMarker.SEVERITY_ERROR; |
92 | } |
93 | marker.setAttribute(IMarker.SEVERITY, markerSeverity); |
94 | } catch (CoreException e) { |
95 | PalladioComponentModelUsageDiagramEditorPlugin.getInstance() |
96 | .logError("Failed to create validation marker", e); //$NON-NLS-1$ |
97 | } |
98 | return marker; |
99 | } |
100 | } |