david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
nitind | 3bc5b95 | 2007-12-03 18:35:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001, 2007 IBM Corporation and others. |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 7 | * |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
pavery | 0f11a86 | 2005-03-29 21:14:36 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.sse.ui.internal; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 14 | |
| 15 | import org.eclipse.core.resources.IMarker; |
| 16 | import org.eclipse.core.resources.IResource; |
| 17 | import org.eclipse.core.runtime.CoreException; |
| 18 | import org.eclipse.jface.text.Position; |
| 19 | import org.eclipse.ui.texteditor.MarkerAnnotation; |
pavery | 328c4a1 | 2005-10-06 14:55:56 +0000 | [diff] [blame] | 20 | import org.eclipse.ui.texteditor.MarkerUtilities; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 21 | import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 22 | import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointConstants; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /** |
| 26 | * Source editor resource marker annotation model implementation |
| 27 | */ |
| 28 | public class StructuredResourceMarkerAnnotationModel extends ResourceMarkerAnnotationModel { |
nitind | 3bc5b95 | 2007-12-03 18:35:16 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Loading of markers when working with non-IResources is accomplished by |
| 31 | * adding the markers to the workspace root with an additional key, whose |
| 32 | * value uses '/' for segment separators when representing paths, |
| 33 | * determining whether they're added into the annotation model. |
| 34 | * |
| 35 | * Setters of this attribute should use '/'for segment separators when |
| 36 | * representing paths. |
| 37 | */ |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 38 | public final static String SECONDARY_ID_KEY = IBreakpointConstants.RESOURCE_PATH; |
nitind | 3bc5b95 | 2007-12-03 18:35:16 +0000 | [diff] [blame] | 39 | |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 40 | protected IResource fMarkerResource; |
| 41 | protected String fSecondaryMarkerAttributeValue; |
| 42 | |
| 43 | /** |
| 44 | * Constructor |
| 45 | * |
| 46 | * @param resource |
| 47 | */ |
| 48 | public StructuredResourceMarkerAnnotationModel(IResource resource) { |
| 49 | super(resource); |
| 50 | fMarkerResource = resource; |
| 51 | } |
| 52 | |
| 53 | public StructuredResourceMarkerAnnotationModel(IResource resource, String secondaryID) { |
| 54 | super(resource); |
| 55 | fMarkerResource = resource; |
| 56 | fSecondaryMarkerAttributeValue = secondaryID; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * (non-Javadoc) |
| 61 | * |
| 62 | * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#createMarkerAnnotation(org.eclipse.core.resources.IMarker) |
| 63 | */ |
| 64 | protected MarkerAnnotation createMarkerAnnotation(IMarker marker) { |
pavery | 328c4a1 | 2005-10-06 14:55:56 +0000 | [diff] [blame] | 65 | /* |
| 66 | * We need to do some special processing if marker is a validation |
| 67 | * (aka problem) marker or if marker is a breakpoint marker so create |
| 68 | * a special marker annotation for those markers. Otherwise, use |
| 69 | * default. |
| 70 | */ |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 71 | if (MarkerUtilities.isMarkerType(marker, IMarker.PROBLEM)) { |
pavery | 328c4a1 | 2005-10-06 14:55:56 +0000 | [diff] [blame] | 72 | return new StructuredMarkerAnnotation(marker); |
| 73 | } |
| 74 | return super.createMarkerAnnotation(marker); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * (non-Javadoc) |
| 79 | * |
| 80 | * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#getMarkerPosition(org.eclipse.core.resources.IMarker) |
| 81 | */ |
| 82 | public Position getMarkerPosition(IMarker marker) { |
| 83 | Position pos = super.getMarkerPosition(marker); |
| 84 | |
pavery | 328c4a1 | 2005-10-06 14:55:56 +0000 | [diff] [blame] | 85 | // if ((pos == null || pos.getLength() == 0) && marker.getType() == |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 86 | // IInternalDebugUIConstants.ANN_INSTR_POINTER_CURRENT) { |
| 87 | if (pos == null || pos.getLength() == 0) { |
| 88 | // We probably should create position from marker if marker |
| 89 | // attributes specify a valid position |
| 90 | pos = createPositionFromMarker(marker); |
| 91 | } |
| 92 | |
| 93 | return pos; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * (non-Javadoc) |
| 98 | * |
| 99 | * @see org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel#isAcceptable(org.eclipse.core.resources.IMarker) |
| 100 | */ |
| 101 | protected boolean isAcceptable(IMarker marker) { |
| 102 | try { |
| 103 | Object attr = marker.getAttribute(IBreakpointConstants.ATTR_HIDDEN); |
nitind | 3bc5b95 | 2007-12-03 18:35:16 +0000 | [diff] [blame] | 104 | if (attr != null && Boolean.TRUE.equals(attr)) |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 105 | return false; |
pavery | 328c4a1 | 2005-10-06 14:55:56 +0000 | [diff] [blame] | 106 | } |
| 107 | catch (CoreException e) { |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 108 | // ignore |
| 109 | } |
| 110 | |
| 111 | if (fSecondaryMarkerAttributeValue == null) |
| 112 | return super.isAcceptable(marker); |
| 113 | String markerSecondaryMarkerAttributeValue = marker.getAttribute(SECONDARY_ID_KEY, ""); //$NON-NLS-1$ |
| 114 | boolean isSameFile = fSecondaryMarkerAttributeValue.equalsIgnoreCase(markerSecondaryMarkerAttributeValue); |
| 115 | return super.isAcceptable(marker) && isSameFile; |
| 116 | } |
| 117 | |
| 118 | } |