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