Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 69f9c23bd2de8d4675d02b544928b6a43641042c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
 * Copyright (c) 2002, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Rational Software - Initial Contribution
 *     Norbert Ploett (Siemens AG)
 *     Anton Leherbauer (Wind River Systems)
 *******************************************************************************/

package org.eclipse.cdt.internal.ui.editor;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;

import org.eclipse.cdt.core.model.ICModelMarker;

public class ExternalSearchAnnotationModel extends ResourceMarkerAnnotationModel {

	private final IStorage fStorage;
	private final int fDepth;
	private final String fLocationAttribute;
	
	/**
	 * @param markerResource
	 * @param storage
	 */
	public ExternalSearchAnnotationModel(IResource markerResource, IStorage storage) {
		this(markerResource, storage, IResource.DEPTH_ZERO, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
	}

	/**
	 * @param markerResource
	 * @param storage
	 * @param depth
	 */
	ExternalSearchAnnotationModel(IResource markerResource, IStorage storage, int depth) {
		this(markerResource, storage, depth, ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
	}

	/**
	 * @param markerResource
	 * @param storage
	 * @param depth
	 * @param locationAttribute
	 */
	ExternalSearchAnnotationModel(IResource markerResource,
			IStorage storage, int depth, String locationAttribute) {
		super(markerResource);
		fStorage= storage;
		fDepth= depth;
		fLocationAttribute= locationAttribute;
	}

	@Override
	protected IMarker[] retrieveMarkers() throws CoreException {
		IMarker[] markers = null;
		if (getResource() != null) {
			markers = getResource().findMarkers(IMarker.MARKER, true, fDepth);
		}
		return markers;
	}

	@Override
	protected boolean isAcceptable(IMarker marker) {
		boolean acceptable = false;
		String externalFileName = marker.getAttribute(fLocationAttribute, null);
		if (externalFileName != null) { // Only accept markers with external
										// paths set
			IPath externalPath = new Path(externalFileName);
			IPath storagePath = fStorage.getFullPath();
			acceptable = externalPath.equals(storagePath); // Only accept
															// markers for this
															// annotation
															// model's external
															// editor
		}
		return acceptable;
	}

}

Back to the top