blob: 73d6babd46e105a91c23dd2ca128ecec4cec537d [file] [log] [blame]
david_williamscfdb2cd2004-11-11 08:37:49 +00001/*******************************************************************************
nitind3bc5b952007-12-03 18:35:16 +00002 * Copyright (c) 2001, 2007 IBM Corporation and others.
david_williamscfdb2cd2004-11-11 08:37:49 +00003 * 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
amywuecebb042007-04-10 20:07:35 +00007 *
david_williamscfdb2cd2004-11-11 08:37:49 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
pavery0f11a862005-03-29 21:14:36 +000013package org.eclipse.wst.sse.ui.internal;
david_williamscfdb2cd2004-11-11 08:37:49 +000014
15import org.eclipse.core.resources.IMarker;
16import org.eclipse.core.resources.IResource;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.jface.text.Position;
19import org.eclipse.ui.texteditor.MarkerAnnotation;
pavery328c4a12005-10-06 14:55:56 +000020import org.eclipse.ui.texteditor.MarkerUtilities;
david_williamscfdb2cd2004-11-11 08:37:49 +000021import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
david_williams4ad020f2005-04-18 08:00:30 +000022import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointConstants;
david_williamscfdb2cd2004-11-11 08:37:49 +000023
24
25/**
26 * Source editor resource marker annotation model implementation
27 */
28public class StructuredResourceMarkerAnnotationModel extends ResourceMarkerAnnotationModel {
nitind3bc5b952007-12-03 18:35:16 +000029 /**
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_williamscfdb2cd2004-11-11 08:37:49 +000038 public final static String SECONDARY_ID_KEY = IBreakpointConstants.RESOURCE_PATH;
nitind3bc5b952007-12-03 18:35:16 +000039
david_williamscfdb2cd2004-11-11 08:37:49 +000040 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) {
pavery328c4a12005-10-06 14:55:56 +000065 /*
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 */
nitind09d2cb82006-05-18 18:42:43 +000071 if (MarkerUtilities.isMarkerType(marker, IMarker.PROBLEM)) {
pavery328c4a12005-10-06 14:55:56 +000072 return new StructuredMarkerAnnotation(marker);
73 }
74 return super.createMarkerAnnotation(marker);
david_williamscfdb2cd2004-11-11 08:37:49 +000075 }
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
pavery328c4a12005-10-06 14:55:56 +000085 // if ((pos == null || pos.getLength() == 0) && marker.getType() ==
david_williamscfdb2cd2004-11-11 08:37:49 +000086 // 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);
nitind3bc5b952007-12-03 18:35:16 +0000104 if (attr != null && Boolean.TRUE.equals(attr))
david_williamscfdb2cd2004-11-11 08:37:49 +0000105 return false;
pavery328c4a12005-10-06 14:55:56 +0000106 }
107 catch (CoreException e) {
david_williamscfdb2cd2004-11-11 08:37:49 +0000108 // 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}