View | Details | Raw Unified | Return to bug 60117 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/views/markers/internal/ActionDeleteCompleted.java (-4 / +4 lines)
Lines 99-109 Link Here
99
99
100
        for (int i = 0; i < markers.length; i++) {
100
        for (int i = 0; i < markers.length; i++) {
101
            ConcreteMarker marker = markers[i];
101
            ConcreteMarker marker = markers[i];
102
            if (marker instanceof TaskMarker) {
102
            if (marker instanceof ConcreteMarker) {
103
                TaskMarker taskMarker = (TaskMarker) marker;
103
                ConcreteMarker ConcreteMarker = (ConcreteMarker) marker;
104
104
105
                if (taskMarker.getDone() == 1) {
105
                if (ConcreteMarker.getDone() == 1) {
106
                    completed.add(taskMarker.getMarker());
106
                    completed.add(ConcreteMarker.getMarker());
107
                }
107
                }
108
            }
108
            }
109
        }
109
        }
(-)src/org/eclipse/ui/views/markers/internal/BookmarkFilter.java (-18 / +12 lines)
Lines 14-20 Link Here
14
import org.eclipse.core.resources.IMarker;
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.jface.dialogs.IDialogSettings;
15
import org.eclipse.jface.dialogs.IDialogSettings;
16
16
17
public class BookmarkFilter extends MarkerFilter {
17
public class BookmarkFilter extends MarkerFilterCriteria {
18
18
19
    private final static String TAG_CONTAINS = "contains"; //$NON-NLS-1$
19
    private final static String TAG_CONTAINS = "contains"; //$NON-NLS-1$
20
20
Lines 34-56 Link Here
34
        super(new String[] { IMarker.BOOKMARK });
34
        super(new String[] { IMarker.BOOKMARK });
35
    }
35
    }
36
36
37
    /**
38
     * Returns true iff the given marker is accepted by this filter
39
     */
40
    public boolean selectMarker(ConcreteMarker marker) {
41
        return !isEnabled()
42
                || (super.selectMarker(marker) && selectByDescription(marker));
43
    }
44
45
    private boolean selectByDescription(ConcreteMarker marker) {
46
        if (description == null || description.equals("")) //$NON-NLS-1$
47
            return true;
48
49
        String markerDescription = marker.getDescription();
50
        int index = markerDescription.indexOf(description);
51
        return contains ? (index >= 0) : (index < 0);
52
    }
53
54
    boolean getContains() {
37
    boolean getContains() {
55
        return contains;
38
        return contains;
56
    }
39
    }
Lines 73-78 Link Here
73
        description = DEFAULT_DESCRIPTION;
56
        description = DEFAULT_DESCRIPTION;
74
    }
57
    }
75
58
59
    /* (non-Javadoc)
60
	 * @see org.eclipse.ui.views.markers.internal.MarkerFilterCriteria#getMarkerFilter()
61
	 */
62
	protected MarkerFilter getMarkerFilter() {
63
		MarkerFilter result = super.getMarkerFilter();
64
		
65
		result.setDescription(description, contains);
66
		
67
		return result;
68
	}
69
    
76
    public void restoreState(IDialogSettings dialogSettings) {
70
    public void restoreState(IDialogSettings dialogSettings) {
77
        super.restoreState(dialogSettings);
71
        super.restoreState(dialogSettings);
78
        IDialogSettings settings = dialogSettings
72
        IDialogSettings settings = dialogSettings
(-)src/org/eclipse/ui/views/markers/internal/BookmarkMarker.java (-30 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.views.markers.internal;
12
13
import org.eclipse.core.resources.IMarker;
14
15
/**
16
 * Represents a marker visible in the Bookmarks view. Currently, this adds no additional
17
 * fields to the ConcreteMarker class. However, if additional fields were added to the
18
 * bookmark view that are not general to all views, these fields would be added to this
19
 * class.
20
 */
21
public class BookmarkMarker extends ConcreteMarker {
22
23
    /**
24
     * @param toCopy
25
     */
26
    public BookmarkMarker(IMarker toCopy) {
27
        super(toCopy);
28
    }
29
30
}
(-)src/org/eclipse/ui/views/markers/internal/BookmarkView.java (-8 / +5 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.core.resources.IMarker;
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.jface.dialogs.ErrorDialog;
18
import org.eclipse.jface.dialogs.ErrorDialog;
Lines 75-83 Link Here
75
                Object data = item.getData();
74
                Object data = item.getData();
76
75
77
                if (data instanceof ConcreteMarker) {
76
                if (data instanceof ConcreteMarker) {
78
                    IMarker marker = ((ConcreteMarker) data).getMarker();
79
77
80
                    try {
78
                    try {
79
                        IMarker marker = ((ConcreteMarker) data).getMarker();
81
                        if (!marker.getAttribute(property).equals(value)) {
80
                        if (!marker.getAttribute(property).equals(value)) {
82
                            if (IMarker.MESSAGE.equals(property))
81
                            if (IMarker.MESSAGE.equals(property))
83
                                marker.setAttribute(IMarker.MESSAGE, value);
82
                                marker.setAttribute(IMarker.MESSAGE, value);
Lines 168-177 Link Here
168
        return ROOT_TYPES;
167
        return ROOT_TYPES;
169
    }
168
    }
170
169
171
    protected Object getViewerInput() {
172
        return ResourcesPlugin.getWorkspace().getRoot();
173
    }
174
175
    protected IField[] getVisibleFields() {
170
    protected IField[] getVisibleFields() {
176
        return VISIBLE_FIELDS;
171
        return VISIBLE_FIELDS;
177
    }
172
    }
Lines 199-212 Link Here
199
        if (dialog.open() == Window.OK) {
194
        if (dialog.open() == Window.OK) {
200
            bookmarkFilter = (BookmarkFilter) dialog.getFilter();
195
            bookmarkFilter = (BookmarkFilter) dialog.getFilter();
201
            bookmarkFilter.saveState(getDialogSettings());
196
            bookmarkFilter.saveState(getDialogSettings());
202
            refresh();
197
            setFilter(dialog.getFilter().getFilter());
198
            setLimit(getFilterCriteria().getMarkerLimit());
199
//            refresh();
203
        }
200
        }
204
    }
201
    }
205
202
206
    /* (non-Javadoc)
203
    /* (non-Javadoc)
207
     * @see org.eclipse.ui.views.markers.internal.MarkerView#getFilter()
204
     * @see org.eclipse.ui.views.markers.internal.MarkerView#getFilter()
208
     */
205
     */
209
    protected MarkerFilter getFilter() {
206
    protected MarkerFilterCriteria getFilterCriteria() {
210
        return bookmarkFilter;
207
        return bookmarkFilter;
211
    }
208
    }
212
209
(-)src/org/eclipse/ui/views/markers/internal/ConcreteMarker.java (-14 / +77 lines)
Lines 42-56 Link Here
42
42
43
    private long creationTime;
43
    private long creationTime;
44
44
45
    private int severity;
46
    
45
    private String type;
47
    private String type;
46
48
47
    private IMarker marker;
49
    private boolean isBookmark;
48
50
51
    private int priority;
52
53
    private int done;
54
55
	private boolean isTask;
56
57
	private boolean isProblem;
58
	
59
	private IResource resource;
60
	
61
	private long id;
62
    
49
    public ConcreteMarker(IMarker toCopy) {
63
    public ConcreteMarker(IMarker toCopy) {
50
        marker = toCopy;
64
    	this.id = toCopy.getId();
65
    	this.resource = toCopy.getResource();
66
    	this.type = ""; //$NON-NLS-1$
51
        refresh();
67
        refresh();
52
    }
68
    }
53
69
70
    public int getPriority() {
71
        return priority;
72
    }
73
74
    public int getDone() {
75
        return done;
76
    }
77
    
54
    /**
78
    /**
55
     * Clears any cached information. This frees up some memory, but will slow down
79
     * Clears any cached information. This frees up some memory, but will slow down
56
     * the next comparison operation. It is a good idea to call this on a set of markers
80
     * the next comparison operation. It is a good idea to call this on a set of markers
Lines 62-81 Link Here
62
        inFolderKey = null;
86
        inFolderKey = null;
63
    }
87
    }
64
88
89
    public int getSeverity() {
90
        return severity;
91
    }
92
    
93
    public String getType() {
94
    	return type;
95
    }
96
    
65
    /**
97
    /**
66
     * Refresh the properties of this marker from the underlying IMarker instance
98
     * Refresh the properties of this marker from the underlying IMarker instance
67
     */
99
     */
68
    public void refresh() {
100
    public void refresh() {
69
        clearCache();
101
        clearCache();
70
102
103
        creationTime = 0;
104
    	isBookmark = false;
105
    	isTask = false;
106
    	isProblem = false;
107
        
108
        IMarker marker;
109
		try {
110
			marker = getMarker();
111
		} catch (CoreException e2) {
112
			return;
113
		}
114
        
71
        description = Util.getProperty(IMarker.MESSAGE, marker);
115
        description = Util.getProperty(IMarker.MESSAGE, marker);
72
        resourceName = marker.getResource().getName();
116
        resourceName = marker.getResource().getName();
73
        inFolder = Util.getContainerName(marker);
117
        inFolder = Util.getContainerName(marker);
74
        line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
118
        line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
119
    	
75
        try {
120
        try {
76
            creationTime = marker.getCreationTime();
121
        	isBookmark = marker.isSubtypeOf(IMarker.BOOKMARK);
122
            isTask = marker.isSubtypeOf(IMarker.TASK);
123
            isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
124
        	creationTime = marker.getCreationTime();
77
        } catch (CoreException e) {
125
        } catch (CoreException e) {
78
            creationTime = 0;
79
        }
126
        }
80
127
81
        try {
128
        try {
Lines 83-96 Link Here
83
        } catch (CoreException e1) {
130
        } catch (CoreException e1) {
84
            type = ""; //$NON-NLS-1$
131
            type = ""; //$NON-NLS-1$
85
        }
132
        }
133
        
134
        priority = marker.getAttribute(IMarker.PRIORITY,
135
                IMarker.PRIORITY_NORMAL);
136
        done = -1;
137
        if (marker.getAttribute(IMarker.USER_EDITABLE, true)) {
138
            done = 0;
139
            if (marker.getAttribute(IMarker.DONE, false)) {
140
                done = 1;
141
            }
142
        }
143
        
144
        severity = marker.getAttribute(IMarker.SEVERITY, -1);
86
    }
145
    }
87
146
88
    public IResource getResource() {
147
    public IResource getResource() {
89
        return marker.getResource();
148
        return resource;
90
    }
91
92
    public String getType() {
93
        return type;
94
    }
149
    }
95
150
96
    public String getDescription() {
151
    public String getDescription() {
Lines 137-146 Link Here
137
        return creationTime;
192
        return creationTime;
138
    }
193
    }
139
194
140
    public IMarker getMarker() {
195
    public String toString() {
141
        return marker;
196
        return description;
142
    }
197
    }
143
198
    
199
    public long getId() {
200
    	return id;
201
    }
202
    
203
    public IMarker getMarker() throws CoreException {
204
    	return resource.getMarker(getId());
205
    }
206
    
144
    public boolean equals(Object object) {
207
    public boolean equals(Object object) {
145
        if (!(object instanceof ConcreteMarker)) {
208
        if (!(object instanceof ConcreteMarker)) {
146
            return false;
209
            return false;
Lines 148-157 Link Here
148
211
149
        ConcreteMarker other = (ConcreteMarker) object;
212
        ConcreteMarker other = (ConcreteMarker) object;
150
213
151
        return other.getMarker().equals(getMarker());
214
        return other.getId() == getId() && other.getResource().equals(getResource());
152
    }
215
    }
153
216
154
    public int hashCode() {
217
    public int hashCode() {
155
        return getMarker().hashCode();
218
        return ((int)getId()) + getResource().hashCode();
156
    }
219
    }
157
}
220
}
(-)src/org/eclipse/ui/views/markers/internal/DialogMarkerFilter.java (-24 / +24 lines)
Lines 225-231 Link Here
225
        }
225
        }
226
    }
226
    }
227
227
228
    private MarkerFilter filter;
228
    private MarkerFilterCriteria filter;
229
229
230
    private CheckboxTableViewer typesViewer;
230
    private CheckboxTableViewer typesViewer;
231
231
Lines 266-272 Link Here
266
    /**
266
    /**
267
     * Creates a new filters dialog.
267
     * Creates a new filters dialog.
268
     */
268
     */
269
    DialogMarkerFilter(Shell parentShell, MarkerFilter filter) {
269
    DialogMarkerFilter(Shell parentShell, MarkerFilterCriteria filter) {
270
        super(parentShell);
270
        super(parentShell);
271
        this.filter = filter;
271
        this.filter = filter;
272
    }
272
    }
Lines 642-662 Link Here
642
     */
642
     */
643
    protected void resetPressed() {
643
    protected void resetPressed() {
644
        filterEnabledButton
644
        filterEnabledButton
645
                .setSelection(MarkerFilter.DEFAULT_ACTIVATION_STATUS);
645
                .setSelection(MarkerFilterCriteria.DEFAULT_ACTIVATION_STATUS);
646
        filterOnMarkerLimit
646
        filterOnMarkerLimit
647
                .setSelection(MarkerFilter.DEFAULT_FILTER_ON_MARKER_LIMIT);
647
                .setSelection(MarkerFilterCriteria.DEFAULT_FILTER_ON_MARKER_LIMIT);
648
        markerLimit.setText(String.valueOf(MarkerFilter.DEFAULT_MARKER_LIMIT));
648
        markerLimit.setText(String.valueOf(MarkerFilterCriteria.DEFAULT_MARKER_LIMIT));
649
        typesViewer.setAllChecked(true);
649
        typesViewer.setAllChecked(true);
650
        int onResource = MarkerFilter.DEFAULT_ON_RESOURCE;
650
        int onResource = MarkerFilterCriteria.DEFAULT_ON_RESOURCE;
651
        anyResourceButton
651
        anyResourceButton
652
                .setSelection(onResource == MarkerFilter.ON_ANY_RESOURCE);
652
                .setSelection(onResource == MarkerFilterCriteria.ON_ANY_RESOURCE);
653
        anyResourceInSameProjectButton
653
        anyResourceInSameProjectButton
654
                .setSelection(onResource == MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT);
654
                .setSelection(onResource == MarkerFilterCriteria.ON_ANY_RESOURCE_OF_SAME_PROJECT);
655
        selectedResourceButton
655
        selectedResourceButton
656
                .setSelection(onResource == MarkerFilter.ON_SELECTED_RESOURCE_ONLY);
656
                .setSelection(onResource == MarkerFilterCriteria.ON_SELECTED_RESOURCE_ONLY);
657
        selectedResourceAndChildrenButton
657
        selectedResourceAndChildrenButton
658
                .setSelection(onResource == MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN);
658
                .setSelection(onResource == MarkerFilterCriteria.ON_SELECTED_RESOURCE_AND_CHILDREN);
659
        workingSetGroup.setSelection(onResource == MarkerFilter.ON_WORKING_SET);
659
        workingSetGroup.setSelection(onResource == MarkerFilterCriteria.ON_WORKING_SET);
660
        updateEnabledState();
660
        updateEnabledState();
661
    }
661
    }
662
662
Lines 705-724 Link Here
705
        filter.setSelectedTypes(getSelectedTypes());
705
        filter.setSelectedTypes(getSelectedTypes());
706
706
707
        if (selectedResourceButton.getSelection())
707
        if (selectedResourceButton.getSelection())
708
            filter.setOnResource(MarkerFilter.ON_SELECTED_RESOURCE_ONLY);
708
            filter.setOnResource(MarkerFilterCriteria.ON_SELECTED_RESOURCE_ONLY);
709
        else if (selectedResourceAndChildrenButton.getSelection())
709
        else if (selectedResourceAndChildrenButton.getSelection())
710
            filter
710
            filter
711
                    .setOnResource(MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN);
711
                    .setOnResource(MarkerFilterCriteria.ON_SELECTED_RESOURCE_AND_CHILDREN);
712
        else if (anyResourceInSameProjectButton.getSelection())
712
        else if (anyResourceInSameProjectButton.getSelection())
713
            filter.setOnResource(MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT);
713
            filter.setOnResource(MarkerFilterCriteria.ON_ANY_RESOURCE_OF_SAME_PROJECT);
714
        else if (workingSetGroup.getSelection())
714
        else if (workingSetGroup.getSelection())
715
            filter.setOnResource(MarkerFilter.ON_WORKING_SET);
715
            filter.setOnResource(MarkerFilterCriteria.ON_WORKING_SET);
716
        else
716
        else
717
            filter.setOnResource(MarkerFilter.ON_ANY_RESOURCE);
717
            filter.setOnResource(MarkerFilterCriteria.ON_ANY_RESOURCE);
718
718
719
        filter.setWorkingSet(workingSetGroup.getWorkingSet());
719
        filter.setWorkingSet(workingSetGroup.getWorkingSet());
720
720
721
        int markerLimit = MarkerFilter.DEFAULT_MARKER_LIMIT;
721
        int markerLimit = MarkerFilterCriteria.DEFAULT_MARKER_LIMIT;
722
722
723
        try {
723
        try {
724
            markerLimit = Integer.parseInt(this.markerLimit.getText());
724
            markerLimit = Integer.parseInt(this.markerLimit.getText());
Lines 738-751 Link Here
738
        setSelectedTypes(filter.getSelectedTypes());
738
        setSelectedTypes(filter.getSelectedTypes());
739
739
740
        int on = filter.getOnResource();
740
        int on = filter.getOnResource();
741
        anyResourceButton.setSelection(on == MarkerFilter.ON_ANY_RESOURCE);
741
        anyResourceButton.setSelection(on == MarkerFilterCriteria.ON_ANY_RESOURCE);
742
        anyResourceInSameProjectButton
742
        anyResourceInSameProjectButton
743
                .setSelection(on == MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT);
743
                .setSelection(on == MarkerFilterCriteria.ON_ANY_RESOURCE_OF_SAME_PROJECT);
744
        selectedResourceButton
744
        selectedResourceButton
745
                .setSelection(on == MarkerFilter.ON_SELECTED_RESOURCE_ONLY);
745
                .setSelection(on == MarkerFilterCriteria.ON_SELECTED_RESOURCE_ONLY);
746
        selectedResourceAndChildrenButton
746
        selectedResourceAndChildrenButton
747
                .setSelection(on == MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN);
747
                .setSelection(on == MarkerFilterCriteria.ON_SELECTED_RESOURCE_AND_CHILDREN);
748
        workingSetGroup.setSelection(on == MarkerFilter.ON_WORKING_SET);
748
        workingSetGroup.setSelection(on == MarkerFilterCriteria.ON_WORKING_SET);
749
        workingSetGroup.setWorkingSet(filter.getWorkingSet());
749
        workingSetGroup.setWorkingSet(filter.getWorkingSet());
750
750
751
        markerLimit.setText("" + filter.getMarkerLimit()); //$NON-NLS-1$
751
        markerLimit.setText("" + filter.getMarkerLimit()); //$NON-NLS-1$
Lines 777-783 Link Here
777
        dirty = true;
777
        dirty = true;
778
    }
778
    }
779
779
780
    public void setFilter(MarkerFilter newFilter) {
780
    public void setFilter(MarkerFilterCriteria newFilter) {
781
        filter = newFilter;
781
        filter = newFilter;
782
        updateUIFromFilter();
782
        updateUIFromFilter();
783
    }
783
    }
Lines 785-791 Link Here
785
    /**
785
    /**
786
     * @return the MarkerFilter associated with the dialog.
786
     * @return the MarkerFilter associated with the dialog.
787
     */
787
     */
788
    public MarkerFilter getFilter() {
788
    public MarkerFilterCriteria getFilter() {
789
        return filter;
789
        return filter;
790
    }
790
    }
791
791
(-)src/org/eclipse/ui/views/markers/internal/FieldDone.java (-6 / +6 lines)
Lines 75-84 Link Here
75
     * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
75
     * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
76
     */
76
     */
77
    public Image getImage(Object obj) {
77
    public Image getImage(Object obj) {
78
        if (obj == null || !(obj instanceof TaskMarker)) {
78
        if (obj == null || !(obj instanceof ConcreteMarker)) {
79
            return null;
79
            return null;
80
        }
80
        }
81
        TaskMarker marker = (TaskMarker) obj;
81
        ConcreteMarker marker = (ConcreteMarker) obj;
82
        int done = marker.getDone();
82
        int done = marker.getDone();
83
        if (done == -1) {
83
        if (done == -1) {
84
            return null;
84
            return null;
Lines 94-105 Link Here
94
     * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
94
     * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
95
     */
95
     */
96
    public int compare(Object obj1, Object obj2) {
96
    public int compare(Object obj1, Object obj2) {
97
        if (obj1 == null || obj2 == null || !(obj1 instanceof TaskMarker)
97
        if (obj1 == null || obj2 == null || !(obj1 instanceof ConcreteMarker)
98
                || !(obj2 instanceof TaskMarker)) {
98
                || !(obj2 instanceof ConcreteMarker)) {
99
            return 0;
99
            return 0;
100
        }
100
        }
101
        TaskMarker marker1 = (TaskMarker) obj1;
101
        ConcreteMarker marker1 = (ConcreteMarker) obj1;
102
        TaskMarker marker2 = (TaskMarker) obj2;
102
        ConcreteMarker marker2 = (ConcreteMarker) obj2;
103
        int value1 = marker1.getDone();
103
        int value1 = marker1.getDone();
104
        int value2 = marker2.getDone();
104
        int value2 = marker2.getDone();
105
        return value1 - value2;
105
        return value1 - value2;
(-)src/org/eclipse/ui/views/markers/internal/FieldPriority.java (-6 / +6 lines)
Lines 76-86 Link Here
76
     * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
76
     * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
77
     */
77
     */
78
    public Image getImage(Object obj) {
78
    public Image getImage(Object obj) {
79
        if (obj == null || !(obj instanceof TaskMarker)) {
79
        if (obj == null || !(obj instanceof ConcreteMarker)) {
80
            return null;
80
            return null;
81
        }
81
        }
82
        try {
82
        try {
83
            int priority = ((TaskMarker) obj).getPriority();
83
            int priority = ((ConcreteMarker) obj).getPriority();
84
            if (priority == IMarker.PRIORITY_HIGH) {
84
            if (priority == IMarker.PRIORITY_HIGH) {
85
                return ImageFactory.getImage(HIGH_PRIORITY_IMAGE_PATH);
85
                return ImageFactory.getImage(HIGH_PRIORITY_IMAGE_PATH);
86
            }
86
            }
Lines 98-109 Link Here
98
     * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
98
     * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
99
     */
99
     */
100
    public int compare(Object obj1, Object obj2) {
100
    public int compare(Object obj1, Object obj2) {
101
        if (obj1 == null || obj2 == null || !(obj1 instanceof TaskMarker)
101
        if (obj1 == null || obj2 == null || !(obj1 instanceof ConcreteMarker)
102
                || !(obj2 instanceof TaskMarker)) {
102
                || !(obj2 instanceof ConcreteMarker)) {
103
            return 0;
103
            return 0;
104
        }
104
        }
105
        int priority1 = ((TaskMarker) obj1).getPriority();
105
        int priority1 = ((ConcreteMarker) obj1).getPriority();
106
        int priority2 = ((TaskMarker) obj2).getPriority();
106
        int priority2 = ((ConcreteMarker) obj2).getPriority();
107
        return priority1 - priority2;
107
        return priority1 - priority2;
108
    }
108
    }
109
109
(-)src/org/eclipse/ui/views/markers/internal/FieldSeverity.java (-7 / +7 lines)
Lines 68-74 Link Here
68
     * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
68
     * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
69
     */
69
     */
70
    public String getValue(Object obj) {
70
    public String getValue(Object obj) {
71
        return "" + ((ProblemMarker) obj).getSeverity(); //$NON-NLS-1$
71
        return "" + ((ConcreteMarker) obj).getSeverity(); //$NON-NLS-1$
72
    }
72
    }
73
73
74
    /*
74
    /*
Lines 76-86 Link Here
76
     * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
76
     * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
77
     */
77
     */
78
    public Image getImage(Object obj) {
78
    public Image getImage(Object obj) {
79
        if (obj == null || !(obj instanceof ProblemMarker)) {
79
        if (obj == null || !(obj instanceof ConcreteMarker)) {
80
            return null;
80
            return null;
81
        }
81
        }
82
82
83
        int severity = ((ProblemMarker) obj).getSeverity();
83
        int severity = ((ConcreteMarker) obj).getSeverity();
84
        if (severity == IMarker.SEVERITY_ERROR) {
84
        if (severity == IMarker.SEVERITY_ERROR) {
85
            return ImageFactory.getImage(IMAGE_ERROR_PATH);
85
            return ImageFactory.getImage(IMAGE_ERROR_PATH);
86
        }
86
        }
Lines 98-110 Link Here
98
     * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
98
     * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
99
     */
99
     */
100
    public int compare(Object obj1, Object obj2) {
100
    public int compare(Object obj1, Object obj2) {
101
        if (obj1 == null || obj2 == null || !(obj1 instanceof ProblemMarker)
101
        if (obj1 == null || obj2 == null || !(obj1 instanceof ConcreteMarker)
102
                || !(obj2 instanceof ProblemMarker)) {
102
                || !(obj2 instanceof ConcreteMarker)) {
103
            return 0;
103
            return 0;
104
        }
104
        }
105
105
106
        int severity1 = ((ProblemMarker) obj1).getSeverity();
106
        int severity1 = ((ConcreteMarker) obj1).getSeverity();
107
        int severity2 = ((ProblemMarker) obj2).getSeverity();
107
        int severity2 = ((ConcreteMarker) obj2).getSeverity();
108
        return severity1 - severity2;
108
        return severity1 - severity2;
109
    }
109
    }
110
110
(-)src/org/eclipse/ui/views/markers/internal/IFilter.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.views.markers.internal;
13
14
/**
15
 * Generic filtering interface.
16
 */
17
public interface IFilter {
18
19
    /**
20
     * Filters the list of elements. Removes the elements that need to filtered out from the list.
21
     * 
22
     * @param elements
23
     */
24
    public Object[] filter(Object[] elements);
25
26
    /**
27
     * @param item
28
     * @return
29
     * <ul>
30
     * <li><code>true</code> if the item will make it through the filter.</li>
31
     * <li><code>false</code> if the item will not make it through the filter.</li>
32
     * </ul>
33
     */
34
    public boolean select(Object item);
35
36
}
(-)src/org/eclipse/ui/views/markers/internal/ITableViewContentProvider.java (-26 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.views.markers.internal;
13
14
public interface ITableViewContentProvider {
15
16
    public Object[] getElements();
17
18
    public IFilter getFilter();
19
20
    public void setFilter(IFilter filter);
21
22
    public void addItemsChangedListener(IItemsChangedListener listener);
23
24
    public void removeItemsChangedListener(IItemsChangedListener listener);
25
26
}
(-)src/org/eclipse/ui/views/markers/internal/MarkerFilter.java (-687 / +211 lines)
Lines 11-734 Link Here
11
11
12
package org.eclipse.ui.views.markers.internal;
12
package org.eclipse.ui.views.markers.internal;
13
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Collection;
17
import java.util.Collections;
18
import java.util.HashSet;
14
import java.util.HashSet;
19
import java.util.Iterator;
15
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Set;
16
import java.util.Set;
22
import java.util.StringTokenizer;
23
17
24
import org.eclipse.core.resources.IContainer;
25
import org.eclipse.core.resources.IMarker;
18
import org.eclipse.core.resources.IMarker;
26
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.resources.IResource;
20
import org.eclipse.jface.viewers.deferred.IFilter;
28
import org.eclipse.core.resources.ResourcesPlugin;
29
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IAdaptable;
31
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.jface.dialogs.IDialogSettings;
33
import org.eclipse.ui.IWorkingSet;
34
import org.eclipse.ui.internal.WorkbenchPlugin;
35
21
36
public class MarkerFilter {
22
public class MarkerFilter implements IFilter {
37
23
38
    private static final String TAG_DIALOG_SECTION = "filter"; //$NON-NLS-1$
24
    final static int DEFAULT_SEVERITY = 0;
39
25
    final static int SEVERITY_ERROR = 1 << 2;
40
    private static final String TAG_ENABLED = "enabled"; //$NON-NLS-1$
26
    final static int SEVERITY_WARNING = 1 << 1;
41
27
    final static int SEVERITY_INFO = 1 << 0;
42
    private static final String TAG_FILTER_ON_MARKER_LIMIT = "filterOnMarkerLimit"; //$NON-NLS-1$
28
    
43
29
    final static int PRIORITY_HIGH = 1 << 2;
44
    private static final String TAG_MARKER_LIMIT = "markerLimit"; //$NON-NLS-1$
30
    final static int PRIORITY_NORMAL = 1 << 1;
45
31
    final static int PRIORITY_LOW = 1 << 0;
46
    private static final String TAG_ON_RESOURCE = "onResource"; //$NON-NLS-1$
32
	
47
33
    protected String[] requiredTypes;
48
    private static final String TAG_SELECTED_TYPES = "selectedType"; //$NON-NLS-1$
34
49
35
    private String description = ""; //$NON-NLS-1$
50
    private static final String TAG_WORKING_SET = "workingSet"; //$NON-NLS-1$
36
    private boolean contains;
51
37
    
52
    private static final String TAG_TYPES_DELIMITER = ":"; //$NON-NLS-1$
38
    private boolean selectBySeverity;
53
39
    private int severity;
54
    static final int ON_ANY_RESOURCE = 0;
40
    
55
41
    private boolean done;
56
    static final int ON_SELECTED_RESOURCE_ONLY = 1;
42
    private int priority;
57
43
    private boolean selectByPriority;
58
    static final int ON_SELECTED_RESOURCE_AND_CHILDREN = 2;
44
    private boolean selectByDone;
59
45
    
60
    static final int ON_ANY_RESOURCE_OF_SAME_PROJECT = 3;
46
    /**
61
47
     * Set of IPath containing workspace-relative paths to resources accepted
62
    static final int ON_WORKING_SET = 4;
48
     * by this filter. null if the filter accepts any resource. 
63
49
     */
64
    static final int DEFAULT_MARKER_LIMIT = 100;
50
    private Set resourcePaths;
65
51
    private boolean includeChildResources = false;
66
    static final boolean DEFAULT_FILTER_ON_MARKER_LIMIT = true;
52
    private Set requiredTypeSet;
67
53
    
68
    static final int DEFAULT_ON_RESOURCE = ON_ANY_RESOURCE;
54
    MarkerFilter(String[] requiredTypes) {
69
55
    	this.requiredTypes = requiredTypes;
70
    static final boolean DEFAULT_ACTIVATION_STATUS = true;
56
    	this.resourcePaths = null;    	
71
57
    }
72
    protected List rootTypes = new ArrayList();
58
    
73
59
//    MarkerFilter(String[] requiredTypes, IResource[] exactResources) {
74
    protected List selectedTypes = new ArrayList();
60
//    	this.requiredTypes = requiredTypes;
75
61
//    	this.requiredResources = exactResources;
76
    protected IWorkingSet workingSet;
62
//    }
77
63
    
78
    protected int onResource;
64
    /**
79
65
     * @param resourcePathSet Set of IPath
80
    protected boolean filterOnMarkerLimit;
66
     */
81
67
    MarkerFilter(String[] requiredTypes, Set resourcePathSet, boolean includeChildResources) {
82
    protected boolean enabled;
68
    	this.requiredTypes = requiredTypes;
83
69
    	resourcePaths = resourcePathSet;
84
    protected int markerLimit;
70
    	this.includeChildResources = includeChildResources;
85
71
    }
86
    private MarkerTypesModel typesModel;
72
    
87
73
    /* (non-Javadoc)
88
    private IResource[] focusResource;
74
	 * @see java.lang.Object#equals(java.lang.Object)
89
75
	 */
90
    private Set cachedWorkingSet;
76
	public boolean equals(Object arg0) {
91
77
		if (!(arg0 instanceof MarkerFilter)) {
92
    MarkerFilter(String[] rootTypes) {
78
			return false;
93
        typesModel = new MarkerTypesModel();
79
		}
94
80
95
        for (int i = 0; i < rootTypes.length; i++) {
81
		MarkerFilter other = (MarkerFilter)arg0;
96
            MarkerType type = typesModel.getType(rootTypes[i]);
82
				
83
		if (!(other.contains == contains
84
				&& other.description.equals(description)
85
				&& other.selectBySeverity == selectBySeverity
86
				&& other.severity == severity
87
				&& other.done == done
88
				&& other.priority == priority
89
				&& other.includeChildResources == includeChildResources
90
				&& other.selectByPriority == selectByPriority
91
				&& other.selectBySeverity == selectBySeverity
92
				&& other.requiredTypes.length == requiredTypes.length)) return false;
93
		
94
		for (int i = 0; i < other.requiredTypes.length; i++) {
95
			String type = other.requiredTypes[i];
96
			
97
			if (!selectByType(type)) {
98
				return false;
99
			}
100
		}
101
		
102
		if (resourcePaths == null || other.resourcePaths == null) {
103
			// Unless they're both null, the filters aren't equal
104
			if (resourcePaths != other.resourcePaths) {
105
				return false;
106
			}
107
		} else {
108
			if (!includeChildResources) {
109
				if (!resourcePaths.equals(other.resourcePaths)) return false;
110
			} else {
111
				// Check for "resources + children" style matches
112
				for (Iterator iter = resourcePaths.iterator(); iter.hasNext();) {
113
					IPath next = (IPath) iter.next();
114
					
115
					if (!other.selectByResource(next)) {
116
						return false;
117
					}
118
				}
119
				for (Iterator iter = other.resourcePaths.iterator(); iter.hasNext();) {
120
					IPath next = (IPath) iter.next();
121
					
122
					if (!selectByResource(next)) {
123
						return false;
124
					}
125
				}
126
			}
127
		}
128
		
129
		return true;
130
	}
131
    
132
    /* (non-Javadoc)
133
	 * @see org.eclipse.jface.viewers.deferred.IFilter#select(java.lang.Object)
134
	 */
135
	public boolean select(Object toTest) {
136
		if (!(toTest instanceof ConcreteMarker)) {
137
			return false;
138
		}
139
		ConcreteMarker m = (ConcreteMarker)toTest;
140
		
141
		if (selectByType(m.getType()) && selectByResource(m.getResource().getFullPath()) && selectByDescription(m) && selectBySeverity(m) 
142
				&& selectByDone(m) && selectByPriority(m)) {
143
			return true;
144
		}
145
		
146
		return false;
147
	}
148
	
149
	private boolean selectByResource(IPath resource) {
150
		
151
		if (resourcePaths == null) {
152
			return true;
153
		}
154
		
155
		if (includeChildResources) {
156
			if (resourcePaths.contains(resource)) {
157
				return true;
158
			}
159
			
160
			if (resource.segmentCount() == 0) {
161
				return false;
162
			}
163
			
164
			return selectByResource(resource.removeLastSegments(1));
165
		} else {
166
			return resourcePaths.contains(resource);
167
		}
168
	}
169
	
170
	private boolean selectByType(String type) {
171
		if (requiredTypeSet == null) {
172
			requiredTypeSet = new HashSet();
173
			for (int i = 0; i < requiredTypes.length; i++) {
174
				String next = requiredTypes[i];
175
				
176
				requiredTypeSet.add(next);
177
			}
178
		}
179
		
180
		return requiredTypeSet.contains(type);
181
	}
182
	
183
	public void setDescription(String description, boolean contains) {
184
		this.description = description;
185
		this.contains = contains;
186
	}
187
	
188
    private boolean selectByDescription(ConcreteMarker marker) {
189
        if (description == null || description.equals("")) //$NON-NLS-1$
190
            return true;
97
191
98
            if (!this.rootTypes.contains(type))
192
        String markerDescription = marker.getDescription();
99
                this.rootTypes.add(type);
193
        int index = markerDescription.indexOf(description);
100
        }
194
        return contains ? (index >= 0) : (index < 0);
101
    }
195
    }
102
196
	
103
    private void addAllSubTypes() {
197
    public void setSelectBySeverity(boolean selectBySeverity) {
104
        for (int i = 0; i < rootTypes.size(); i++) {
198
        this.selectBySeverity = selectBySeverity;
105
            MarkerType rootType = (MarkerType) rootTypes.get(i);
106
            addAllSubTypes(rootType);
107
        }
108
    }
199
    }
109
200
110
    private void addAllSubTypes(MarkerType type) {
201
    public void setSeverity(int severity) {
111
        if (type == null)
202
        this.severity = severity;
112
            return;
113
114
        if (!selectedTypes.contains(type))
115
            selectedTypes.add(type);
116
117
        MarkerType[] subTypes = type.getSubtypes();
118
119
        for (int i = 0; i < subTypes.length; i++)
120
            addAllSubTypes(subTypes[i]);
121
    }
203
    }
122
204
123
    /**
205
    private boolean selectBySeverity(ConcreteMarker item) {
124
     * Adds all markers in the given set of resources to the given list
206
        if (selectBySeverity) {
125
     * 
207
            int markerSeverity = item.getSeverity();
126
     * @param resultList
127
     * @param resources
128
     * @param markerTypeId
129
     * @param depth
130
     * @throws CoreException
131
     */
132
    private List findMarkers(IResource[] resources, int depth, int limit,
133
            IProgressMonitor mon, boolean ignoreExceptions)
134
            throws CoreException {
135
        if (resources == null) {
136
            return Collections.EMPTY_LIST;
137
        }
138
139
        List resultList = new ArrayList(resources.length * 2);
140
141
        // Optimization: if a type appears in the selectedTypes list along with all of its
142
        // subtypes, then combine these in a single search.
143
144
        // List of types that haven't been replaced by one of their supertypes
145
        HashSet typesToSearch = new HashSet(selectedTypes.size());
146
147
        // List of types that appeared in selectedTypes along with all of their subtypes
148
        HashSet includeAllSubtypes = new HashSet(selectedTypes.size());
149
150
        typesToSearch.addAll(selectedTypes);
151
152
        Iterator iter = selectedTypes.iterator();
153
154
        while (iter.hasNext()) {
155
            MarkerType type = (MarkerType) iter.next();
156
157
            Collection subtypes = Arrays.asList(type.getAllSubTypes());
158
159
            if (selectedTypes.containsAll(subtypes)) {
160
                typesToSearch.removeAll(subtypes);
161
162
                includeAllSubtypes.add(type);
163
            }
164
        }
165
166
        mon
167
                .beginTask(
168
                        Messages.getString("MarkerFilter.searching"), typesToSearch.size() * resources.length); //$NON-NLS-1$
169
170
        // Use this hash set to determine if there are any resources in the
171
        // list that appear along with their parent.
172
        HashSet resourcesToSearch = new HashSet();
173
174
        // Insert all the resources into the hashset
175
        for (int idx = 0; idx < resources.length; idx++) {
176
            IResource next = resources[idx];
177
178
            if (!next.exists()) {
179
                continue;
180
            }
181
182
            if (resourcesToSearch.contains(next)) {
183
                mon.worked(typesToSearch.size());
184
            } else {
185
                resourcesToSearch.add(next);
186
            }
187
        }
188
208
189
        // Iterate through all the selected resources
209
            if (markerSeverity == IMarker.SEVERITY_ERROR)
190
        for (int resourceIdx = 0; resourceIdx < resources.length; resourceIdx++) {
210
                return (severity & SEVERITY_ERROR) > 0;
191
            iter = typesToSearch.iterator();
211
            else if (markerSeverity == IMarker.SEVERITY_WARNING)
192
212
                return (severity & SEVERITY_WARNING) > 0;
193
            IResource resource = resources[resourceIdx];
213
            else if (markerSeverity == IMarker.SEVERITY_INFO)
194
214
                return (severity & SEVERITY_INFO) > 0;
195
            // Skip resources that don't exist
196
            if (!resource.isAccessible()) {
197
                continue;
198
            }
199
200
            if (depth == IResource.DEPTH_INFINITE) {
201
                // Determine if any parent of this resource is also in our filter 
202
                IResource parent = resource.getParent();
203
                boolean found = false;
204
                while (parent != null) {
205
                    if (resourcesToSearch.contains(parent)) {
206
                        found = true;
207
                    }
208
209
                    parent = parent.getParent();
210
                }
211
212
                // If a parent of this resource is also in the filter, we can skip it
213
                // because we'll pick up its markers when we search the parent.
214
                if (found) {
215
                    continue;
216
                }
217
            }
218
219
            // Iterate through all the marker types
220
            while (iter.hasNext()) {
221
                MarkerType markerType = (MarkerType) iter.next();
222
223
                // Only search for subtypes of the marker if we found all of its
224
                // subtypes in the filter criteria.
225
                IMarker[] markers = resource.findMarkers(markerType.getId(),
226
                        includeAllSubtypes.contains(markerType), depth);
227
228
                mon.worked(1);
229
230
                for (int idx = 0; idx < markers.length; idx++) {
231
                    ConcreteMarker marker;
232
                    try {
233
                        marker = MarkerList.createMarker(markers[idx]);
234
                    } catch (CoreException e) {
235
                        if (ignoreExceptions) {
236
                            continue;
237
                        } else {
238
                            throw e;
239
                        }
240
                    }
241
242
                    if (limit != -1 && resultList.size() >= limit) {
243
                        return resultList;
244
                    }
245
246
                    if (selectMarker(marker)) {
247
                        resultList.add(marker);
248
                    }
249
                }
250
            }
251
        }
215
        }
252
216
253
        mon.done();
254
255
        return resultList;
256
    }
257
258
    /**
259
     * Subclasses should override to determine if the given marker passes the filter.
260
     * 
261
     * @param marker
262
     * @return <code>true</code> if the marker passes the filter and <code>false</code> otherwise
263
     */
264
    protected boolean selectMarker(ConcreteMarker marker) {
265
        return true;
217
        return true;
266
    }
218
    }
267
219
    
268
    /**
220
    public void setDone(boolean done) {
269
     * Searches the workspace for markers that pass this filter.
221
        this.done = done;
270
     * 
271
     * @return
272
     */
273
    ConcreteMarker[] findMarkers(IProgressMonitor mon, boolean ignoreExceptions)
274
            throws CoreException {
275
276
        List unfiltered = Collections.EMPTY_LIST;
277
278
        if (!isEnabled()) {
279
            unfiltered = findMarkers(new IResource[] { ResourcesPlugin
280
                    .getWorkspace().getRoot() }, IResource.DEPTH_INFINITE, -1,
281
                    mon, ignoreExceptions);
282
        } else {
283
            //int limit = getFilterOnMarkerLimit() ? getMarkerLimit() + 1 : -1;
284
            int limit = -1;
285
286
            switch (getOnResource()) {
287
            case ON_ANY_RESOURCE: {
288
                unfiltered = findMarkers(new IResource[] { ResourcesPlugin
289
                        .getWorkspace().getRoot() }, IResource.DEPTH_INFINITE,
290
                        limit, mon, ignoreExceptions);
291
                break;
292
            }
293
            case ON_SELECTED_RESOURCE_ONLY: {
294
                unfiltered = findMarkers(focusResource, IResource.DEPTH_ZERO,
295
                        limit, mon, ignoreExceptions);
296
                break;
297
            }
298
            case ON_SELECTED_RESOURCE_AND_CHILDREN: {
299
                unfiltered = findMarkers(focusResource,
300
                        IResource.DEPTH_INFINITE, limit, mon, ignoreExceptions);
301
                break;
302
            }
303
            case ON_ANY_RESOURCE_OF_SAME_PROJECT: {
304
                unfiltered = findMarkers(getProjects(focusResource),
305
                        IResource.DEPTH_INFINITE, limit, mon, ignoreExceptions);
306
                break;
307
            }
308
            case ON_WORKING_SET: {
309
                unfiltered = findMarkers(getResourcesInWorkingSet(),
310
                        IResource.DEPTH_INFINITE, limit, mon, ignoreExceptions);
311
            }
312
            }
313
        }
314
315
        if (unfiltered == null) {
316
            unfiltered = Collections.EMPTY_LIST;
317
        }
318
319
        return (ConcreteMarker[]) unfiltered
320
                .toArray(new ConcreteMarker[unfiltered.size()]);
321
    }
322
323
    IResource[] getResourcesInWorkingSet() {
324
        if (workingSet == null) {
325
            return new IResource[0];
326
        }
327
328
        IAdaptable[] elements = workingSet.getElements();
329
        List result = new ArrayList(elements.length);
330
331
        for (int idx = 0; idx < elements.length; idx++) {
332
            IResource next = (IResource) elements[idx]
333
                    .getAdapter(IResource.class);
334
335
            if (next != null) {
336
                result.add(next);
337
            }
338
        }
339
340
        return (IResource[]) result.toArray(new IResource[result.size()]);
341
    }
222
    }
342
223
343
    /**
224
    public void setPriority(int priority) {
344
     * Returns a set of strings representing the full pathnames to every resource directly
225
        this.priority = priority;
345
     * or indirectly contained in the working set. A resource is in the working set iff its
346
     * path name can be found in this set.
347
     * 
348
     * @return
349
     */
350
    private Set getWorkingSetAsSetOfPaths() {
351
        if (cachedWorkingSet == null) {
352
            HashSet result = new HashSet();
353
354
            addResourcesAndChildren(result, getResourcesInWorkingSet());
355
356
            cachedWorkingSet = result;
357
        }
358
359
        return cachedWorkingSet;
360
    }
361
362
    /***
363
     * Adds the paths of all resources in the given array to the given set. 
364
     */
365
    private void addResourcesAndChildren(HashSet result, IResource[] resources) {
366
        for (int idx = 0; idx < resources.length; idx++) {
367
368
            IResource currentResource = resources[idx];
369
370
            result.add(currentResource.getFullPath().toString());
371
372
            if (currentResource instanceof IContainer) {
373
                IContainer cont = (IContainer) currentResource;
374
375
                try {
376
                    addResourcesAndChildren(result, cont.members());
377
                } catch (CoreException e) {
378
                    // Ignore errors
379
                }
380
            }
381
382
        }
383
    }
384
385
    /**
386
     * Returns the set of projects that contain the given set of resources.
387
     * 
388
     * @param resources
389
     * @return
390
     */
391
    static IProject[] getProjects(IResource[] resources) {
392
        if (resources == null) {
393
            return new IProject[0];
394
        }
395
396
        Collection projects = getProjectsAsCollection(resources);
397
398
        return (IProject[]) projects.toArray(new IProject[projects.size()]);
399
    }
400
401
    static Collection getProjectsAsCollection(IResource[] resources) {
402
        HashSet projects = new HashSet();
403
404
        for (int idx = 0; idx < resources.length; idx++) {
405
            projects.add(resources[idx].getProject());
406
        }
407
408
        return projects;
409
    }
226
    }
410
227
411
    public boolean select(ConcreteMarker marker) {
228
    public void setSelectByDone(boolean selectByDone) {
412
        if (!isEnabled()) {
229
        this.selectByDone = selectByDone;
413
            return true;
414
        }
415
416
        return selectByType(marker) && selectBySelection(marker)
417
                && selectMarker(marker);
418
    }
230
    }
419
231
420
    private boolean selectByType(ConcreteMarker marker) {
232
    public void setSelectByPriority(boolean selectByPriority) {
421
        return selectedTypes.contains(typesModel.getType(marker.getType()));
233
        this.selectByPriority = selectByPriority;
422
    }
234
    }
423
235
424
    /**
236
    private boolean selectByDone(ConcreteMarker item) {
425
     * Returns whether the specified marker should be filter out or not.
237
        if (selectByDone)
426
     * 
238
            return done == (item.getDone() == 1);
427
     * @param marker the marker to test
428
     * @return 
429
     * 	true=the marker should not be filtered out
430
     * 	false=the marker should be filtered out
431
     */
432
    private boolean selectBySelection(ConcreteMarker marker) {
433
        if (onResource == ON_ANY_RESOURCE || marker == null)
434
            return true;
435
239
436
        if (focusResource == null)
240
        return true;
437
            return true;
438
439
        IResource resource = marker.getResource();
440
441
        if (onResource == ON_WORKING_SET) {
442
            if (workingSet == null)
443
                return true;
444
445
            if (resource != null)
446
                return isEnclosed(resource);
447
448
        } else if (onResource == ON_ANY_RESOURCE_OF_SAME_PROJECT) {
449
            IProject project = resource.getProject();
450
451
            if (project == null) {
452
                return false;
453
            }
454
455
            for (int i = 0; i < focusResource.length; i++) {
456
                IProject selectedProject = focusResource[i].getProject();
457
458
                if (selectedProject == null) {
459
                    continue;
460
                }
461
462
                if (project.equals(selectedProject))
463
                    return true;
464
            }
465
        } else if (onResource == ON_SELECTED_RESOURCE_ONLY) {
466
            for (int i = 0; i < focusResource.length; i++) {
467
                if (resource.equals(focusResource[i]))
468
                    return true;
469
            }
470
        } else if (onResource == ON_SELECTED_RESOURCE_AND_CHILDREN) {
471
            for (int i = 0; i < focusResource.length; i++) {
472
                IResource parentResource = resource;
473
474
                while (parentResource != null) {
475
                    if (parentResource.equals(focusResource[i]))
476
                        return true;
477
478
                    parentResource = parentResource.getParent();
479
                }
480
            }
481
        }
482
483
        return false;
484
    }
241
    }
485
242
486
    /**
243
    private boolean selectByPriority(ConcreteMarker marker) {
487
     * Returns if the given resource is enclosed by a working set element.
244
        if (priority != 0 && selectByPriority) {
488
     * Previous versions of this method used IContainmentAdapter for 
245
            int markerPriority = marker.getPriority();
489
     * containment tests. For performance reasons, this is no longer possible.
246
490
     * Code that relies on this behavior should be updated appropriately.
247
            if (markerPriority == IMarker.PRIORITY_HIGH)
491
     * 
248
                return (priority & PRIORITY_HIGH) > 0;
492
     * @param element resource to test for enclosure by a working set
249
            else if (markerPriority == IMarker.PRIORITY_NORMAL)
493
     * 	element 
250
                return (priority & PRIORITY_NORMAL) > 0;
494
     * @return true if element is enclosed by a working set element and 
251
            else if (markerPriority == IMarker.PRIORITY_LOW)
495
     * 	false otherwise. 
252
                return (priority & PRIORITY_LOW) > 0;
496
     */
497
    private boolean isEnclosed(IResource element) {
498
        if (workingSet == null) {
499
            return false;
500
        }
253
        }
501
        Set workingSetPaths = getWorkingSetAsSetOfPaths();
502
503
        return workingSetPaths.contains(element.getFullPath().toString());
504
    }
505
506
    /**
507
     * @return the defined limit on the number of markers to be displayed.
508
     */
509
    int getMarkerLimit() {
510
        return markerLimit;
511
    }
512
513
    /**
514
     * Sets the limit on the number of markers to be displayed.
515
     * 
516
     * @param the new limit
517
     */
518
    void setMarkerLimit(int markerLimit) {
519
        this.markerLimit = markerLimit;
520
    }
521
522
    /**
523
     * @return <ul>
524
     * <li><code>MarkerFilter.ON_ANY_RESOURCE</code> if showing items associated with any resource.</li>
525
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_ONLY</code> if showing items associated with
526
     * the selected resource within the workbench.</li>
527
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN</code> if showing items associated with
528
     * the selected resource within the workbench and its children.</li>
529
     * <li><code>MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT</code> if showing items in the same project
530
     * as the selected resource within the workbench.</li>
531
     * <li><code>MarkerFilter.ON_WORKING_SET</code> if showing items in some working set.</li>
532
     * </ul>
533
     */
534
    int getOnResource() {
535
        return onResource;
536
    }
537
538
    /**
539
     * Sets the type of filtering by selection.
540
     * 
541
     * @param onResource must be one of:
542
     * <ul>
543
     * <li><code>MarkerFilter.ON_ANY_RESOURCE</code></li>
544
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_ONLY</code></li>
545
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN</code></li>
546
     * <li><code>MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT</code></li>
547
     * <li><code>MarkerFilter.ON_WORKING_SET</code></li>
548
     * </ul>
549
     */
550
    void setOnResource(int onResource) {
551
        if (onResource >= ON_ANY_RESOURCE && onResource <= ON_WORKING_SET)
552
            this.onResource = onResource;
553
    }
554
555
    /**
556
     * @return the selected resource(s) withing the workbench.
557
     */
558
    IResource[] getFocusResource() {
559
        return focusResource;
560
    }
561
562
    /**
563
     * Sets the focused resources.
564
     */
565
    public void setFocusResource(IResource[] resources) {
566
        focusResource = resources;
567
    }
568
569
    /**
570
     * @return
571
     * <ul>
572
     * <li><code>true</code> if the filter is enabled.</li>
573
     * <li><code>false</code> if the filter is not enabled.</li>
574
     * </ul>
575
     */
576
    boolean isEnabled() {
577
        return enabled;
578
    }
579
580
    /**
581
     * @return
582
     * <ul>
583
     * <li><code>true</code> if filtering by marker limit is enabled.</li>
584
     * <li><code>false</code> if filtering by marker limit is not enabled.</li>
585
     * </ul>
586
     */
587
    boolean getFilterOnMarkerLimit() {
588
        return filterOnMarkerLimit;
589
    }
590
591
    /**
592
     * @return the root marker types.
593
     */
594
    List getRootTypes() {
595
        return rootTypes;
596
    }
597
598
    /**
599
     * @return the selected marker types to be displayed.
600
     */
601
    List getSelectedTypes() {
602
        return selectedTypes;
603
    }
604
254
605
    /**
255
        return true;
606
     * @return the current working set or <code>null</code> if no working set is defined.
607
     */
608
    IWorkingSet getWorkingSet() {
609
        return workingSet;
610
    }
611
612
    /**
613
     * Sets the enablement state of the filter.
614
     */
615
    void setEnabled(boolean enabled) {
616
        this.enabled = enabled;
617
    }
618
619
    /**
620
     * Sets the enablement state of filtering by marker limit.
621
     */
622
    void setFilterOnMarkerLimit(boolean filterOnMarkerLimit) {
623
        this.filterOnMarkerLimit = filterOnMarkerLimit;
624
    }
625
626
    /**
627
     * Sets the selected marker types to be displayed. The List <b>MUST ONLY</b> contain 
628
     * <code>MarkerType</code> objects.
629
     */
630
    void setSelectedTypes(List selectedTypes) {
631
        this.selectedTypes = selectedTypes;
632
    }
633
634
    /**
635
     * Sets the current working set.
636
     */
637
    void setWorkingSet(IWorkingSet workingSet) {
638
        this.workingSet = workingSet;
639
        cachedWorkingSet = null;
640
    }
641
642
    void resetState() {
643
        enabled = DEFAULT_ACTIVATION_STATUS;
644
        filterOnMarkerLimit = DEFAULT_FILTER_ON_MARKER_LIMIT;
645
        markerLimit = DEFAULT_MARKER_LIMIT;
646
        onResource = DEFAULT_ON_RESOURCE;
647
        selectedTypes.clear();
648
        addAllSubTypes();
649
        setWorkingSet(null);
650
    }
651
652
    public void restoreState(IDialogSettings dialogSettings) {
653
        resetState();
654
        IDialogSettings settings = dialogSettings
655
                .getSection(TAG_DIALOG_SECTION);
656
657
        if (settings != null) {
658
            String setting = settings.get(TAG_ENABLED);
659
660
            if (setting != null)
661
                enabled = Boolean.valueOf(setting).booleanValue();
662
663
            setting = settings.get(TAG_FILTER_ON_MARKER_LIMIT);
664
665
            if (setting != null)
666
                filterOnMarkerLimit = Boolean.valueOf(setting).booleanValue();
667
668
            setting = settings.get(TAG_MARKER_LIMIT);
669
670
            if (setting != null)
671
                try {
672
                    markerLimit = Integer.parseInt(setting);
673
                } catch (NumberFormatException eNumberFormat) {
674
                }
675
676
            setting = settings.get(TAG_ON_RESOURCE);
677
678
            if (setting != null)
679
                try {
680
                    onResource = Integer.parseInt(setting);
681
                } catch (NumberFormatException eNumberFormat) {
682
                }
683
684
            setting = settings.get(TAG_SELECTED_TYPES);
685
686
            if (setting != null) {
687
                selectedTypes.clear();
688
                StringTokenizer stringTokenizer = new StringTokenizer(setting);
689
690
                while (stringTokenizer.hasMoreTokens()) {
691
                    MarkerType markerType = typesModel.getType(stringTokenizer
692
                            .nextToken(TAG_TYPES_DELIMITER));
693
694
                    if (markerType != null
695
                            && !selectedTypes.contains(markerType))
696
                        selectedTypes.add(markerType);
697
                }
698
            }
699
700
            setting = settings.get(TAG_WORKING_SET);
701
702
            if (setting != null)
703
                setWorkingSet(WorkbenchPlugin.getDefault()
704
                        .getWorkingSetManager().getWorkingSet(setting));
705
        }
706
    }
256
    }
707
257
708
    public void saveState(IDialogSettings dialogSettings) {
709
        if (dialogSettings != null) {
710
            IDialogSettings settings = dialogSettings
711
                    .getSection(TAG_DIALOG_SECTION);
712
713
            if (settings == null)
714
                settings = dialogSettings.addNewSection(TAG_DIALOG_SECTION);
715
716
            settings.put(TAG_ENABLED, enabled);
717
            settings.put(TAG_FILTER_ON_MARKER_LIMIT, filterOnMarkerLimit);
718
            settings.put(TAG_MARKER_LIMIT, markerLimit);
719
            settings.put(TAG_ON_RESOURCE, onResource);
720
721
            String markerTypeIds = ""; //$NON-NLS-1$
722
723
            for (int i = 0; i < selectedTypes.size(); i++) {
724
                MarkerType markerType = (MarkerType) selectedTypes.get(i);
725
                markerTypeIds += markerType.getId() + TAG_TYPES_DELIMITER;
726
            }
727
728
            settings.put(TAG_SELECTED_TYPES, markerTypeIds);
729
730
            if (workingSet != null)
731
                settings.put(TAG_WORKING_SET, workingSet.getName());
732
        }
733
    }
734
}
258
}
(-)src/org/eclipse/ui/views/markers/internal/MarkerList.java (-73 / +4 lines)
Lines 13-20 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Arrays;
14
import java.util.Arrays;
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
16
import java.util.List;
19
import java.util.Map;
17
import java.util.Map;
20
18
Lines 22-28 Link Here
22
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
23
27
/**
24
/**
28
 * Represents a list of ConcreteMarkers.
25
 * Represents a list of ConcreteMarkers.
Lines 75-119 Link Here
75
        markerTable = null;
72
        markerTable = null;
76
    }
73
    }
77
74
78
    /**
75
    public static ConcreteMarker createMarker(IMarker marker) {
79
     * Returns the marker table or lazily creates it if it doesn't exist yet
76
        return new ConcreteMarker(marker);
80
     * 
81
     * @return a map of IMarker onto ConcreteMarker, containing all the ConcreteMarkers in the list
82
     */
83
    private Map getMarkerMap() {
84
        if (markerTable == null) {
85
            markerTable = new HashMap();
86
87
            for (int idx = 0; idx < markers.length; idx++) {
88
                ConcreteMarker marker = markers[idx];
89
                markerTable.put(marker.getMarker(), marker);
90
            }
91
        }
92
93
        return markerTable;
94
    }
95
96
    /**
97
     * Returns an existing marker from the list that is associated with
98
     * the given IMarker
99
     *  
100
     * @param toFind the IMarker to lookup in the list
101
     * @return the ConcreteMarker that corresponds to the given IMarker
102
     */
103
    public ConcreteMarker getMarker(IMarker toFind) {
104
        return (ConcreteMarker) getMarkerMap().get(toFind);
105
    }
106
107
    public static ConcreteMarker createMarker(IMarker marker)
108
            throws CoreException {
109
        if (marker.isSubtypeOf(IMarker.TASK)) {
110
            return new TaskMarker(marker);
111
        } else if (marker.isSubtypeOf(IMarker.BOOKMARK)) {
112
            return new BookmarkMarker(marker);
113
        } else if (marker.isSubtypeOf(IMarker.PROBLEM)) {
114
            return new ProblemMarker(marker);
115
        } else
116
            return new ConcreteMarker(marker);
117
    }
77
    }
118
78
119
    public void refresh() {
79
    public void refresh() {
Lines 127-148 Link Here
127
        return Arrays.asList(markers);
87
        return Arrays.asList(markers);
128
    }
88
    }
129
89
130
    public MarkerList findMarkers(Collection ofIMarker) {
131
        List result = new ArrayList(ofIMarker.size());
132
133
        Iterator iter = ofIMarker.iterator();
134
        while (iter.hasNext()) {
135
            IMarker next = (IMarker) iter.next();
136
137
            ConcreteMarker marker = getMarker(next);
138
            if (marker != null) {
139
                result.add(marker);
140
            }
141
        }
142
143
        return new MarkerList(result);
144
    }
145
146
    public static ConcreteMarker[] createMarkers(IMarker[] source)
90
    public static ConcreteMarker[] createMarkers(IMarker[] source)
147
            throws CoreException {
91
            throws CoreException {
148
        ConcreteMarker[] result = new ConcreteMarker[source.length];
92
        ConcreteMarker[] result = new ConcreteMarker[source.length];
Lines 155-173 Link Here
155
    }
99
    }
156
100
157
    /**
101
    /**
158
     * Computes the set of markers that match the given filter
159
     * @param filter the filter to apply
160
     * @param mon the monitor to update
161
     * @param ignoreExceptions whether or not exception will be shown
162
     * @return MarkerList
163
     * @throws CoreException
164
     */
165
    public static MarkerList compute(MarkerFilter filter, IProgressMonitor mon,
166
            boolean ignoreExceptions) throws CoreException {
167
        return new MarkerList(filter.findMarkers(mon, ignoreExceptions));
168
    }
169
170
    /**
171
     * Returns a new MarkerList containing all markers in the workspace of the specified types
102
     * Returns a new MarkerList containing all markers in the workspace of the specified types
172
     * @param types
103
     * @param types
173
     * @return  IMarker[]
104
     * @return  IMarker[]
Lines 253-260 Link Here
253
            for (int idx = 0; idx < markers.length; idx++) {
184
            for (int idx = 0; idx < markers.length; idx++) {
254
                ConcreteMarker marker = markers[idx];
185
                ConcreteMarker marker = markers[idx];
255
186
256
                if (marker instanceof ProblemMarker) {
187
                if (marker instanceof ConcreteMarker) {
257
                    int severity = ((ProblemMarker) markers[idx]).getSeverity();
188
                    int severity = ((ConcreteMarker) markers[idx]).getSeverity();
258
                    if (severity >= 0 && severity <= 2) {
189
                    if (severity >= 0 && severity <= 2) {
259
                        markerCounts[severity]++;
190
                        markerCounts[severity]++;
260
                    }
191
                    }
(-)src/org/eclipse/ui/views/markers/internal/MarkerRegistry.java (-279 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.views.markers.internal;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
18
import org.eclipse.core.resources.IMarker;
19
import org.eclipse.core.resources.IMarkerDelta;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResourceChangeEvent;
22
import org.eclipse.core.resources.IResourceChangeListener;
23
import org.eclipse.core.resources.IResourceDelta;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.jface.util.ListenerList;
26
27
/**
28
 * Registry that tracks resource markers and maintains a sorted, filtered list of the markers. 
29
 * Notifies listeners of changes in these markers.
30
 */
31
public class MarkerRegistry implements IResourceChangeListener,
32
        ITableViewContentProvider {
33
34
    private IFilter filter;
35
36
    private IResource input;
37
38
    private String[] types = new String[0];
39
40
    private ListenerList listeners = new ListenerList();
41
42
    public MarkerRegistry() {
43
    }
44
45
    /** 
46
     * Disposes the registry, releasing all listeners 
47
     * and any other allocated resources.
48
     */
49
    public void dispose() {
50
        listeners.clear();
51
        setInput(null);
52
    }
53
54
    /**
55
     * @return a filtered, sorted list of markers.
56
     */
57
    public Object[] getElements() {
58
        Object[] elements = getUnfilteredElements();
59
        if (filter != null) {
60
            Object[] filteredItems = filter.filter(elements);
61
            return filteredItems;
62
        }
63
        return elements;
64
    }
65
66
    /**
67
     * @return an unfiltered list of elements
68
     */
69
    public Object[] getUnfilteredElements() {
70
        if (input == null) {
71
            return new Object[0];
72
        }
73
        List elements = new ArrayList();
74
        for (int i = 0; i < types.length; i++) {
75
            try {
76
                IMarker[] newMarkers = input.findMarkers(types[i], true,
77
                        IResource.DEPTH_INFINITE);
78
                elements.addAll(Arrays.asList(newMarkers));
79
            } catch (CoreException e) {
80
            }
81
        }
82
        return elements.toArray();
83
    }
84
85
    /**
86
     * @return the registry's filter or <code>null</code> if no filter has been assigned 
87
     * to the registry.
88
     */
89
    public IFilter getFilter() {
90
        return filter;
91
    }
92
93
    /**
94
     * @return the registry's input resource
95
     */
96
    public IResource getInput() {
97
        return input;
98
    }
99
100
    /**
101
     * Sets the registry's filter
102
     * 
103
     * @param filter 
104
     */
105
    public void setFilter(IFilter filter) {
106
        if (this.filter == null || !this.filter.equals(filter)) {
107
            this.filter = filter;
108
        }
109
    }
110
111
    /**
112
     * Sets the registry's input resource
113
     * 
114
     * @param resource
115
     */
116
    public void setInput(IResource resource) {
117
        if (input != null) {
118
            if (input.equals(resource))
119
                return;
120
            input.getWorkspace().removeResourceChangeListener(this);
121
        }
122
        input = resource;
123
        if (input != null)
124
            resource.getWorkspace().addResourceChangeListener(this);
125
    }
126
127
    /**
128
     * @return the base marker types that the registry is tracking
129
     */
130
    public String[] getTypes() {
131
        return types;
132
    }
133
134
    /**
135
     * Sets the base marker types to track. By default the registry will search for
136
     * all markers of these types and their subtypes.
137
     * 
138
     * @param types
139
     */
140
    public void setTypes(String[] types) {
141
        if (types == null)
142
            this.types = new String[0];
143
        else
144
            this.types = types;
145
    }
146
147
    /**
148
     * Convenience method used if only interested in one base marker type.
149
     * 
150
     * @param type
151
     */
152
    public void setType(String type) {
153
        setTypes(new String[] { type });
154
    }
155
156
    /* (non-Javadoc)
157
     * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
158
     */
159
    public void resourceChanged(IResourceChangeEvent event) {
160
161
        // gather all marker changes from the delta.
162
        // be sure to do this in the calling thread, 
163
        // as the delta is destroyed when this method returns
164
        final List additions = new ArrayList();
165
        final List removals = new ArrayList();
166
        final List changes = new ArrayList();
167
168
        IResourceDelta delta = event.getDelta();
169
        if (delta == null)
170
            return;
171
        getMarkerDeltas(delta, additions, removals, changes);
172
        //filter additions and changes but not removals since they have already been deleted
173
        filterList(additions);
174
        filterList(changes);
175
        notifyListeners(additions, removals, changes);
176
    }
177
178
    /**
179
     * Recursively walks over the resource delta and gathers all marker deltas.  Marker
180
     * deltas are placed into one of the two given lists depending on the type of delta 
181
     * (add or remove).
182
     */
183
    private void getMarkerDeltas(IResourceDelta delta, List additions,
184
            List removals, List changes) {
185
        IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
186
        for (int i = 0; i < markerDeltas.length; i++) {
187
            IMarkerDelta markerDelta = markerDeltas[i];
188
            IMarker marker = markerDelta.getMarker();
189
            switch (markerDelta.getKind()) {
190
            case IResourceDelta.ADDED: {
191
                boolean added = false;
192
                for (int j = 0; j < types.length && !added; j++) {
193
                    if (markerDelta.isSubtypeOf(types[j])) {
194
                        additions.add(marker);
195
                        added = true;
196
                    }
197
                }
198
                break;
199
            }
200
            case IResourceDelta.REMOVED: {
201
                boolean added = false;
202
                for (int j = 0; j < types.length && !added; j++) {
203
                    if (markerDelta.isSubtypeOf(types[j])) {
204
                        removals.add(marker);
205
                        added = true;
206
                    }
207
                }
208
                break;
209
            }
210
            case IResourceDelta.CHANGED: {
211
                boolean added = false;
212
                for (int j = 0; j < types.length && !added; j++) {
213
                    if (markerDelta.isSubtypeOf(types[j])) {
214
                        changes.add(marker);
215
                        added = true;
216
                    }
217
                }
218
                break;
219
            }
220
            }
221
        }
222
223
        //recurse on child deltas
224
        IResourceDelta[] children = delta.getAffectedChildren();
225
        for (int i = 0; i < children.length; i++) {
226
            getMarkerDeltas(children[i], additions, removals, changes);
227
        }
228
    }
229
230
    private void notifyListeners(List additions, List removals, List changes) {
231
        Object[] listeners = this.listeners.getListeners();
232
        for (int i = 0; i < listeners.length; i++) {
233
            IItemsChangedListener listener = (IItemsChangedListener) listeners[i];
234
            listener.itemsChanged(additions, removals, changes);
235
        }
236
    }
237
238
    /* (non-Javadoc)
239
     * @see org.eclipse.ui.views.internal.tableview.ITableViewContentProvider#addItemsChangedListener(org.eclipse.ui.views.internal.tableview.IItemsChangedListener)
240
     */
241
    public void addItemsChangedListener(IItemsChangedListener listener) {
242
        listeners.add(listener);
243
    }
244
245
    /* (non-Javadoc)
246
     * @see org.eclipse.ui.views.internal.tableview.ITableViewContentProvider#removeItemsChangedListener(org.eclipse.ui.views.internal.tableview.IItemsChangedListener)
247
     */
248
    public void removeItemsChangedListener(IItemsChangedListener listener) {
249
        listeners.remove(listener);
250
    }
251
252
    /**
253
     * @return the number of items
254
     */
255
    public int getItemCount() {
256
        //TODO do this more efficiently
257
        return getElements().length;
258
    }
259
260
    public int getRawItemCount() {
261
        //TODO do this more efficiently
262
        return getUnfilteredElements().length;
263
    }
264
265
    private void filterList(List list) {
266
        if (filter == null || list == null) {
267
            return;
268
        }
269
        int i = 0;
270
        while (i < list.size()) {
271
            if (filter.select(list.get(i))) {
272
                i++;
273
            } else {
274
                list.remove(i);
275
            }
276
        }
277
    }
278
279
}
(-)src/org/eclipse/ui/views/markers/internal/MarkerView.java (-332 / +168 lines)
Lines 11-50 Link Here
11
11
12
package org.eclipse.ui.views.markers.internal;
12
package org.eclipse.ui.views.markers.internal;
13
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
14
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.Collection;
18
import java.util.Collections;
19
import java.util.Iterator;
15
import java.util.Iterator;
20
import java.util.List;
16
import java.util.List;
21
17
22
import org.eclipse.core.resources.IMarker;
18
import org.eclipse.core.resources.IMarker;
23
import org.eclipse.core.resources.IMarkerDelta;
19
import org.eclipse.core.resources.IMarkerDelta;
24
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IResourceChangeEvent;
26
import org.eclipse.core.resources.IResourceChangeListener;
27
import org.eclipse.core.resources.IResourceDelta;
21
import org.eclipse.core.resources.IResourceDelta;
28
import org.eclipse.core.resources.IWorkspaceRoot;
22
import org.eclipse.core.resources.IWorkspaceRoot;
29
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.IAdaptable;
32
import org.eclipse.core.runtime.IProgressMonitor;
33
import org.eclipse.core.runtime.IStatus;
34
import org.eclipse.core.runtime.Platform;
35
import org.eclipse.core.runtime.Status;
36
import org.eclipse.core.runtime.SubProgressMonitor;
37
import org.eclipse.core.runtime.jobs.IJobManager;
38
import org.eclipse.core.runtime.jobs.Job;
39
import org.eclipse.jface.action.IMenuManager;
26
import org.eclipse.jface.action.IMenuManager;
40
import org.eclipse.jface.action.IToolBarManager;
27
import org.eclipse.jface.action.IToolBarManager;
41
import org.eclipse.jface.action.Separator;
28
import org.eclipse.jface.action.Separator;
42
import org.eclipse.jface.operation.IRunnableWithProgress;
43
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.ISelection;
44
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.IStructuredSelection;
45
import org.eclipse.jface.viewers.OpenEvent;
31
import org.eclipse.jface.viewers.OpenEvent;
46
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.viewers.StructuredSelection;
47
import org.eclipse.jface.viewers.TableViewer;
33
import org.eclipse.jface.viewers.TableViewer;
34
import org.eclipse.jface.viewers.deferred.IConcurrentModel;
48
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.SWT;
49
import org.eclipse.swt.dnd.Clipboard;
36
import org.eclipse.swt.dnd.Clipboard;
50
import org.eclipse.swt.dnd.DND;
37
import org.eclipse.swt.dnd.DND;
Lines 73-99 Link Here
73
import org.eclipse.ui.part.FileEditorInput;
60
import org.eclipse.ui.part.FileEditorInput;
74
import org.eclipse.ui.part.MarkerTransfer;
61
import org.eclipse.ui.part.MarkerTransfer;
75
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
62
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
76
import org.eclipse.ui.progress.WorkbenchJob;
77
import org.eclipse.ui.views.navigator.ShowInNavigatorAction;
63
import org.eclipse.ui.views.navigator.ShowInNavigatorAction;
78
import org.eclipse.ui.views.tasklist.ITaskListResourceAdapter;
64
import org.eclipse.ui.views.tasklist.ITaskListResourceAdapter;
79
65
80
public abstract class MarkerView extends TableView {
66
public abstract class MarkerView extends TableView {
81
67
82
    private static final String WAITING_FOR_WORKSPACE_CHANGES_TO_FINISH = Messages
83
            .getString("MarkerView.waiting_on_changes"); //$NON-NLS-1$
84
85
    private static final String SEARCHING_FOR_MARKERS = Messages
86
            .getString("MarkerView.searching_for_markers"); //$NON-NLS-1$
87
88
    private static final String REFRESHING_MARKER_COUNTS = Messages
89
            .getString("MarkerView.refreshing_counts"); //$NON-NLS-1$
90
91
    private static final String QUEUEING_VIEWER_UPDATES = Messages
92
            .getString("MarkerView.queueing_updates"); //$NON-NLS-1$
93
94
    private static final String FILTERING_ON_MARKER_LIMIT = Messages
95
            .getString("MarkerView.18"); //$NON-NLS-1$
96
97
    private static final String TAG_SELECTION = "selection"; //$NON-NLS-1$
68
    private static final String TAG_SELECTION = "selection"; //$NON-NLS-1$
98
69
99
    private static final String TAG_MARKER = "marker"; //$NON-NLS-1$
70
    private static final String TAG_MARKER = "marker"; //$NON-NLS-1$
Lines 108-146 Link Here
108
79
109
    protected IResource[] focusResources;
80
    protected IResource[] focusResources;
110
81
82
    private IConcurrentModel model;
83
    
111
    private Clipboard clipboard;
84
    private Clipboard clipboard;
112
85
113
    IResourceChangeListener resourceListener = new IResourceChangeListener() {
114
        public void resourceChanged(IResourceChangeEvent event) {
115
            String[] markerTypes = getMarkerTypes();
116
117
            boolean refreshNeeded = false;
118
119
            for (int idx = 0; idx < markerTypes.length; idx++) {
120
                IMarkerDelta[] markerDeltas = event.findMarkerDeltas(
121
                        markerTypes[idx], true);
122
                List changes = new ArrayList(markerDeltas.length);
123
124
                examineDelta(markerDeltas, changes);
125
126
                if (markerDeltas.length != changes.size()) {
127
                    refreshNeeded = true;
128
                }
129
130
                MarkerList changed = currentMarkers.findMarkers(changes);
131
                changed.refresh();
132
133
                change(changed.asList());
134
            }
135
136
            // Refresh everything if markers were added or removed
137
            if (refreshNeeded) {
138
                markerCountDirty = true;
139
                refresh();
140
            }
141
        }
142
    };
143
144
    protected ActionCopyMarker copyAction;
86
    protected ActionCopyMarker copyAction;
145
87
146
    protected ActionPasteMarker pasteAction;
88
    protected ActionPasteMarker pasteAction;
Lines 163-291 Link Here
163
        }
105
        }
164
    };
106
    };
165
107
166
    private MarkerList currentMarkers = new MarkerList();
167
168
    private int totalMarkers = 0;
169
170
    private boolean markerCountDirty = true;
171
172
    WorkbenchJob uiJob;
173
174
    /**
175
     * This job is scheduled whenever a filter or resource change occurs. It computes the new
176
     * set of markers and schedules a UI Job to cause the changes to be reflected in the UI.
177
     */
178
179
    private RestartableJob refreshJob = null;
180
181
    private void internalRefresh(IProgressMonitor monitor)
182
            throws InvocationTargetException, InterruptedException {
183
        int markerLimit = getMarkerLimit();
184
        monitor
185
                .beginTask(
186
                        Messages.getString("MarkerView.19"), markerLimit == -1 ? 60 : 100); //$NON-NLS-1$
187
188
        haltTableUpdates();
189
        IJobManager jobMan = Platform.getJobManager();
190
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
191
192
        try {
193
            monitor.subTask(WAITING_FOR_WORKSPACE_CHANGES_TO_FINISH);
194
195
            jobMan.beginRule(root, monitor);
196
197
            if (monitor.isCanceled()) {
198
                return;
199
            }
200
201
            monitor.subTask(SEARCHING_FOR_MARKERS);
202
            SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
203
            MarkerList markerList = MarkerList.compute(getFilter(), subMonitor, true);
204
205
            if (monitor.isCanceled()) {
206
                return;
207
            }
208
            if (markerCountDirty) {
209
                monitor.subTask(REFRESHING_MARKER_COUNTS);
210
                totalMarkers = MarkerList.compute(getMarkerTypes()).length;
211
                markerCountDirty = false;
212
            }
213
            
214
            currentMarkers = markerList;
215
216
        } catch (CoreException e) {
217
            throw new InvocationTargetException(e);
218
        } finally {
219
            jobMan.endRule(root);
220
        }
221
222
        if (monitor.isCanceled()) {
223
            return;
224
        }
225
226
        // Exit immediately if the markers have changed in the meantime.
227
228
        Collection markers = Arrays.asList(currentMarkers.toArray());
229
230
        if (markerLimit != -1) {
231
232
            monitor.subTask(FILTERING_ON_MARKER_LIMIT);
233
            SubProgressMonitor mon = new SubProgressMonitor(monitor, 40);
234
235
            markers = SortUtil.getFirst(markers, getSorter(), markerLimit, mon);
236
            if (monitor.isCanceled())
237
                return;
238
            currentMarkers = new MarkerList(markers);
239
        }
240
241
        monitor.subTask(QUEUEING_VIEWER_UPDATES);
242
243
        SubProgressMonitor sub = new SubProgressMonitor(monitor, 50);
244
        setContents(markers, sub);
245
        if (monitor.isCanceled())
246
            return;
247
248
        uiJob.schedule();
249
        try {
250
            uiJob.join();
251
        } catch (InterruptedException e) {
252
            uiJob.cancel();
253
            monitor.done();
254
        } finally {
255
            if (monitor.isCanceled()) {
256
                uiJob.cancel();
257
            }
258
        }
259
260
        monitor.done();
261
    }
262
263
    /**
264
     * Causes the view to re-sync its contents with the workspace. Note that
265
     * changes will be scheduled in a background job, and may not take effect
266
     * immediately. 
267
     */
268
    protected void refresh() {
269
270
        if (uiJob == null)
271
            createUIJob();
272
273
        if (refreshJob == null) {
274
275
            refreshJob = new RestartableJob(Messages.format(
276
                    "MarkerView.refreshTitle", new Object[] { getTitle() }),//$NON-NLS-1$
277
                    new IRunnableWithProgress() {
278
                        public void run(IProgressMonitor monitor)
279
                                throws InvocationTargetException,
280
                                InterruptedException {
281
                            internalRefresh(monitor);
282
                        }
283
                    }, getProgressService());
284
        }
285
286
        refreshJob.restart();
287
    }
288
289
    /* (non-Javadoc)
108
    /* (non-Javadoc)
290
     * @see org.eclipse.ui.views.internal.tableview.TableView#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
109
     * @see org.eclipse.ui.views.internal.tableview.TableView#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
291
     */
110
     */
Lines 306-321 Link Here
306
    public void createPartControl(Composite parent) {
125
    public void createPartControl(Composite parent) {
307
        clipboard = new Clipboard(parent.getDisplay());
126
        clipboard = new Clipboard(parent.getDisplay());
308
127
128
        setFilter(getFilterCriteria().getFilter());
129
        setLimit(getFilterCriteria().getMarkerLimit());
130
        
309
        super.createPartControl(parent);
131
        super.createPartControl(parent);
310
132
133
        
311
        initDragAndDrop();
134
        initDragAndDrop();
312
135
313
        getSite().getPage().addSelectionListener(focusListener);
136
        getSite().getPage().addSelectionListener(focusListener);
314
        focusSelectionChanged(getSite().getPage().getActivePart(), getSite()
137
        focusSelectionChanged(getSite().getPage().getActivePart(), getSite()
315
                .getPage().getSelection());
138
                .getPage().getSelection());
316
        ResourcesPlugin.getWorkspace().addResourceChangeListener(
317
                resourceListener);
318
        refresh();
319
139
320
        // Set help on the view itself
140
        // Set help on the view itself
321
        getViewer().getControl().addHelpListener(new HelpListener() {
141
        getViewer().getControl().addHelpListener(new HelpListener() {
Lines 329-336 Link Here
329
                ConcreteMarker marker = (ConcreteMarker) ((IStructuredSelection) getViewer()
149
                ConcreteMarker marker = (ConcreteMarker) ((IStructuredSelection) getViewer()
330
                        .getSelection()).getFirstElement();
150
                        .getSelection()).getFirstElement();
331
                if (marker != null) {
151
                if (marker != null) {
332
                    contextId = IDE.getMarkerHelpRegistry().getHelp(
152
                    try {
333
                            marker.getMarker());
153
						contextId = IDE.getMarkerHelpRegistry().getHelp(
154
						        marker.getMarker());
155
					} catch (CoreException e1) {
156
						contextId = null;
157
					}
334
                }
158
                }
335
159
336
                if (contextId == null) {
160
                if (contextId == null) {
Lines 348-360 Link Here
348
172
349
        Object[] rawSelection = selection.toArray();
173
        Object[] rawSelection = selection.toArray();
350
174
351
        IMarker[] markers = new IMarker[rawSelection.length];
175
        ArrayList markers = new ArrayList(rawSelection.length);
352
176
        
353
        for (int idx = 0; idx < rawSelection.length; idx++) {
177
        for (int idx = 0; idx < rawSelection.length; idx++) {
354
            markers[idx] = ((ConcreteMarker) rawSelection[idx]).getMarker();
178
        	IMarker next;
179
			try {
180
				next = ((ConcreteMarker) rawSelection[idx]).getMarker();
181
				markers.add(next);
182
			} catch (CoreException e) {
183
			}
355
        }
184
        }
356
185
357
        setSelection(new StructuredSelection(markers));
186
        setSelection(new StructuredSelection(markers.toArray()));
358
187
359
        updateStatusMessage(selection);
188
        updateStatusMessage(selection);
360
    }
189
    }
Lines 364-371 Link Here
364
     */
193
     */
365
    public void dispose() {
194
    public void dispose() {
366
        super.dispose();
195
        super.dispose();
367
        ResourcesPlugin.getWorkspace().removeResourceChangeListener(
368
                resourceListener);
369
        getSite().getPage().removeSelectionListener(focusListener);
196
        getSite().getPage().removeSelectionListener(focusListener);
370
197
371
        //dispose of selection provider actions
198
        //dispose of selection provider actions
Lines 377-382 Link Here
377
        showInNavigatorAction.dispose();
204
        showInNavigatorAction.dispose();
378
        propertiesAction.dispose();
205
        propertiesAction.dispose();
379
        clipboard.dispose();
206
        clipboard.dispose();
207
        
208
        if (model != null) {
209
        	MarkerProvider.releaseRef(model);
210
        	model = null;
211
        }
380
    }
212
    }
381
213
382
    /* (non-Javadoc)
214
    /* (non-Javadoc)
Lines 497-503 Link Here
497
    /* (non-Javadoc)
329
    /* (non-Javadoc)
498
     * @see org.eclipse.ui.views.internal.tableview.TableView#getFilter()
330
     * @see org.eclipse.ui.views.internal.tableview.TableView#getFilter()
499
     */
331
     */
500
    protected abstract MarkerFilter getFilter();
332
    protected abstract MarkerFilterCriteria getFilterCriteria();
501
333
502
    /* (non-Javadoc)
334
    /* (non-Javadoc)
503
     * @see org.eclipse.ui.views.internal.tableview.TableView#handleKeyPressed(org.eclipse.swt.events.KeyEvent)
335
     * @see org.eclipse.ui.views.internal.tableview.TableView#handleKeyPressed(org.eclipse.swt.events.KeyEvent)
Lines 526-535 Link Here
526
        for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
358
        for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
527
            ConcreteMarker marker = (ConcreteMarker) iterator.next();
359
            ConcreteMarker marker = (ConcreteMarker) iterator.next();
528
            IMemento elementMem = selectionMem.createChild(TAG_MARKER);
360
            IMemento elementMem = selectionMem.createChild(TAG_MARKER);
529
            elementMem.putString(TAG_RESOURCE, marker.getMarker().getResource()
361
            elementMem.putString(TAG_RESOURCE, marker.getResource()
530
                    .getFullPath().toString());
362
                    .getFullPath().toString());
531
            elementMem.putString(TAG_ID, String.valueOf(marker.getMarker()
363
            elementMem.putString(TAG_ID, String.valueOf(marker.getId()));
532
                    .getId()));
533
        }
364
        }
534
    }
365
    }
535
366
Lines 545-550 Link Here
545
        if (selectionMemento == null) {
376
        if (selectionMemento == null) {
546
            return new StructuredSelection();
377
            return new StructuredSelection();
547
        }
378
        }
379
        
548
        ArrayList selectionList = new ArrayList();
380
        ArrayList selectionList = new ArrayList();
549
        IMemento[] markerMems = selectionMemento.getChildren(TAG_MARKER);
381
        IMemento[] markerMems = selectionMemento.getChildren(TAG_MARKER);
550
        for (int i = 0; i < markerMems.length; i++) {
382
        for (int i = 0; i < markerMems.length; i++) {
Lines 554-561 Link Here
554
                        .getString(TAG_RESOURCE));
386
                        .getString(TAG_RESOURCE));
555
                if (resource != null) {
387
                if (resource != null) {
556
                    IMarker marker = resource.findMarker(id);
388
                    IMarker marker = resource.findMarker(id);
557
                    if (marker != null)
389
                    if (marker != null) {
558
                        selectionList.add(currentMarkers.getMarker(marker));
390
                        selectionList.add(MarkerList.createMarker(marker));
391
                    }
559
                }
392
                }
560
            } catch (CoreException e) {
393
            } catch (CoreException e) {
561
            }
394
            }
Lines 605-610 Link Here
605
            }
438
            }
606
        }
439
        }
607
440
441
608
        IResource[] focus = new IResource[resources.size()];
442
        IResource[] focus = new IResource[resources.size()];
609
        resources.toArray(focus);
443
        resources.toArray(focus);
610
        updateFocusResource(focus);
444
        updateFocusResource(focus);
Lines 617-667 Link Here
617
    protected abstract void updateFilterSelection(IResource[] resources);
451
    protected abstract void updateFilterSelection(IResource[] resources);
618
452
619
    void updateFocusResource(IResource[] resources) {
453
    void updateFocusResource(IResource[] resources) {
620
        boolean updateNeeded = updateNeeded(focusResources, resources);
454
    	if (resources.length > 0) {
621
        if (updateNeeded) {
455
	        updateFilterSelection(resources);
622
            focusResources = resources;
456
	        setFilter(getFilterCriteria().getFilter());
623
            updateFilterSelection(resources);
457
    	}
624
            refresh();
458
        
625
        }
459
//        boolean updateNeeded = updateNeeded(focusResources, resources);
626
    }
460
//        if (updateNeeded) {
627
461
//            focusResources = resources;
628
    private boolean updateNeeded(IResource[] oldResources,
462
//            updateFilterSelection(resources);
629
            IResource[] newResources) {
463
//            setFilter(getFilterCriteria().getFilter());
630
        //determine if an update if refiltering is required
464
//        }
631
        MarkerFilter filter = getFilter();
465
    }
632
        if (!filter.isEnabled()) {
466
633
            return false;
467
//    private boolean updateNeeded(IResource[] oldResources,
634
        }
468
//            IResource[] newResources) {
635
469
//        //determine if an update if refiltering is required
636
        int onResource = filter.getOnResource();
470
//        MarkerFilterCriteria filter = getFilterCriteria();
637
        if (onResource == MarkerFilter.ON_ANY_RESOURCE
471
//        if (!filter.isEnabled()) {
638
                || onResource == MarkerFilter.ON_WORKING_SET) {
472
//            return false;
639
            return false;
473
//        }
640
        }
474
//
641
        if (newResources == null || newResources.length < 1) {
475
//        int onResource = filter.getOnResource();
642
            return false;
476
//        if (onResource == MarkerFilterCriteria.ON_ANY_RESOURCE
643
        }
477
//                || onResource == MarkerFilterCriteria.ON_WORKING_SET) {
644
        if (oldResources == null || oldResources.length < 1) {
478
//            return false;
645
            return true;
479
//        }
646
        }
480
//        if (newResources == null || newResources.length < 1) {
647
        if (Arrays.equals(oldResources, newResources)) {
481
//            return false;
648
            return false;
482
//        }
649
        }
483
//        if (oldResources == null || oldResources.length < 1) {
650
        if (onResource == MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT) {
484
//            return true;
651
            Collection oldProjects = MarkerFilter
485
//        }
652
                    .getProjectsAsCollection(oldResources);
486
//        if (Arrays.equals(oldResources, newResources)) {
653
            Collection newProjects = MarkerFilter
487
//            return false;
654
                    .getProjectsAsCollection(newResources);
488
//        }
655
489
//        if (onResource == MarkerFilterCriteria.ON_ANY_RESOURCE_OF_SAME_PROJECT) {
656
            if (oldProjects.size() == newProjects.size()) {
490
//            Collection oldProjects = MarkerFilterCriteria
657
                return !newProjects.containsAll(oldProjects);
491
//                    .getProjectsAsCollection(oldResources);
658
            } else {
492
//            Collection newProjects = MarkerFilterCriteria
659
                return true;
493
//                    .getProjectsAsCollection(newResources);
660
            }
494
//
661
        }
495
//            if (oldProjects.size() == newProjects.size()) {
662
496
//                return !newProjects.containsAll(oldProjects);
663
        return true;
497
//            } else {
664
    }
498
//                return true;
499
//            }
500
//        }
501
//
502
//        return true;
503
//    }
665
504
666
    /**
505
    /**
667
     * Returns the marker limit or -1 if unlimited
506
     * Returns the marker limit or -1 if unlimited
Lines 669-675 Link Here
669
     * @return
508
     * @return
670
     */
509
     */
671
    private int getMarkerLimit() {
510
    private int getMarkerLimit() {
672
        MarkerFilter filter = getFilter();
511
        MarkerFilterCriteria filter = getFilterCriteria();
673
512
674
        if (!filter.isEnabled() || !filter.getFilterOnMarkerLimit()) {
513
        if (!filter.isEnabled() || !filter.getFilterOnMarkerLimit()) {
675
            return -1;
514
            return -1;
Lines 684-705 Link Here
684
        return (limit == -1 || toTest <= limit);
523
        return (limit == -1 || toTest <= limit);
685
    }
524
    }
686
525
526
    // TODO: FIX ME
687
    void updateTitle() {
527
    void updateTitle() {
688
        String currentTitle = getTitle();
528
//        String currentTitle = getTitle();
689
        String viewName = getConfigurationElement().getAttribute("name"); //$NON-NLS-1$
529
//        String viewName = getConfigurationElement().getAttribute("name"); //$NON-NLS-1$
690
        String status = ""; //$NON-NLS-1$
530
//        String status = ""; //$NON-NLS-1$
691
        int filteredCount = currentMarkers.getItemCount();
531
//        int filteredCount = currentMarkers.getItemCount();
692
        int totalCount = getTotalMarkers();
532
//        int totalCount = getTotalMarkers();
693
        if (filteredCount == totalCount) {
533
//        if (filteredCount == totalCount) {
694
            status = Messages
534
//            status = Messages
695
                    .format(
535
//                    .format(
696
                            "filter.itemsMessage", new Object[] { new Integer(totalCount) }); //$NON-NLS-1$
536
//                            "filter.itemsMessage", new Object[] { new Integer(totalCount) }); //$NON-NLS-1$
697
        } else {
537
//        } else {
698
            status = Messages
538
//            status = Messages
699
                    .format(
539
//                    .format(
700
                            "filter.matchedMessage", new Object[] { new Integer(filteredCount), new Integer(totalCount) }); //$NON-NLS-1$
540
//                            "filter.matchedMessage", new Object[] { new Integer(filteredCount), new Integer(totalCount) }); //$NON-NLS-1$
701
        }
541
//        }
702
        setContentDescription(status);
542
//        setContentDescription(status);
703
    }
543
    }
704
544
705
    /**
545
    /**
Lines 796-803 Link Here
796
        for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
636
        for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
797
            Object next = i.next();
637
            Object next = i.next();
798
            if (next instanceof IMarker) {
638
            if (next instanceof IMarker) {
799
                ConcreteMarker marker = currentMarkers
639
                ConcreteMarker marker = MarkerList.createMarker((IMarker) next);
800
                        .getMarker((IMarker) next);
801
                if (marker != null) {
640
                if (marker != null) {
802
                    newSelection.add(marker);
641
                    newSelection.add(marker);
803
                }
642
                }
Lines 808-849 Link Here
808
            viewer.setSelection(new StructuredSelection(newSelection), reveal);
647
            viewer.setSelection(new StructuredSelection(newSelection), reveal);
809
    }
648
    }
810
649
811
    /* (non-Javadoc)
650
//    protected MarkerList getVisibleMarkers() {
812
     * @see org.eclipse.ui.views.markers.internal.TableView#setContents(java.util.Collection)
651
//        return currentMarkers;
813
     */
652
//    }
814
    void setContents(Collection contents, IProgressMonitor mon) {
653
//
815
        if (withinMarkerLimit(contents.size())) {
654
//    /**
816
            super.setContents(contents, mon);
655
//     * Returns the total number of markers. Should not be called while the marker
817
        } else {
656
//     * list is still updating.
818
            super.setContents(Collections.EMPTY_LIST, mon);
657
//     * 
819
        }
658
//     * @return the total number of markers in the workspace (including everything that doesn't pass the filters)
820
    }
659
//     */
821
660
//    int getTotalMarkers() {
822
    protected MarkerList getVisibleMarkers() {
661
//        // The number of visible markers should never exceed the total number of markers in
823
        return currentMarkers;
662
//        // the workspace. If this assertation fails, it probably indicates some sort of concurrency problem
824
    }
663
//        // (most likely, getTotalMarkers was called while we were still computing the marker lists)
825
664
//        //Assert.isTrue(totalMarkers >= currentMarkers.getItemCount());
826
    /**
665
//
827
     * Returns the total number of markers. Should not be called while the marker
666
//        return totalMarkers;
828
     * list is still updating.
667
//    }
829
     * 
668
830
     * @return the total number of markers in the workspace (including everything that doesn't pass the filters)
669
//    /* (non-Javadoc)
831
     */
670
//     * @see org.eclipse.ui.views.markers.internal.TableView#sorterChanged()
832
    int getTotalMarkers() {
671
//     */
833
        // The number of visible markers should never exceed the total number of markers in
672
//    protected void sorterChanged() {
834
        // the workspace. If this assertation fails, it probably indicates some sort of concurrency problem
673
//        refresh();
835
        // (most likely, getTotalMarkers was called while we were still computing the marker lists)
674
//    }
836
        //Assert.isTrue(totalMarkers >= currentMarkers.getItemCount());
837
838
        return totalMarkers;
839
    }
840
841
    /* (non-Javadoc)
842
     * @see org.eclipse.ui.views.markers.internal.TableView#sorterChanged()
843
     */
844
    protected void sorterChanged() {
845
        refresh();
846
    }
847
675
848
    private static void examineDelta(IMarkerDelta[] deltas, List changes) {
676
    private static void examineDelta(IMarkerDelta[] deltas, List changes) {
849
        for (int idx = 0; idx < deltas.length; idx++) {
677
        for (int idx = 0; idx < deltas.length; idx++) {
Lines 856-892 Link Here
856
        }
684
        }
857
    }
685
    }
858
686
859
    /* (non-Javadoc)
687
//    /* (non-Javadoc)
860
     * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
688
//     * @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean)
861
     */
689
//     */
862
    public void showBusy(boolean busy) {
690
//    public void showBusy(boolean busy) {
863
        super.showBusy(busy);
691
//        super.showBusy(busy);
864
692
//
865
        if (busy) {
693
//        if (busy) {
866
            preBusyMarkers = totalMarkers;
694
//            preBusyMarkers = totalMarkers;
867
        } else {//Only bold if there has been a change in count
695
//        } else {//Only bold if there has been a change in count
868
            if (totalMarkers != preBusyMarkers)
696
//            if (totalMarkers != preBusyMarkers)
869
                getProgressService().warnOfContentChange();
697
//                getProgressService().warnOfContentChange();
870
        }
698
//        }
871
699
//
872
    }
700
//    }
873
701
874
    /**
702
    protected IConcurrentModel getViewerInput() {
875
     * Create the UIJob used in the receiver for updates.
703
    	if (model == null) {
876
     *
704
    		model = MarkerProvider.getRef();
877
     */
705
    	}
878
    private void createUIJob() {
706
    	
879
        uiJob = new WorkbenchJob(Messages
707
    	return model;
880
                .getString("MarkerView.refreshProgress")) { //$NON-NLS-1$
708
    }
881
709
    
882
            public IStatus runInUIThread(IProgressMonitor monitor) {
710
//    /**
883
                updateStatusMessage();
711
//     * Create the UIJob used in the receiver for updates.
884
                updateTitle();
712
//     *
885
                return Status.OK_STATUS;
713
//     */
886
            }
714
//    private void createUIJob() {
887
        };
715
//        uiJob = new WorkbenchJob(Messages
888
        uiJob.setPriority(Job.INTERACTIVE);
716
//                .getString("MarkerView.refreshProgress")) { //$NON-NLS-1$
889
        uiJob.setSystem(true);
717
//
890
    }
718
//            public IStatus runInUIThread(IProgressMonitor monitor) {
719
//                updateStatusMessage();
720
//                updateTitle();
721
//                return Status.OK_STATUS;
722
//            }
723
//        };
724
//        uiJob.setPriority(Job.INTERACTIVE);
725
//        uiJob.setSystem(true);
726
//    }
891
727
892
}
728
}
(-)src/org/eclipse/ui/views/markers/internal/ProblemFilter.java (-36 / +13 lines)
Lines 14-20 Link Here
14
import org.eclipse.core.resources.IMarker;
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.jface.dialogs.IDialogSettings;
15
import org.eclipse.jface.dialogs.IDialogSettings;
16
16
17
public class ProblemFilter extends MarkerFilter {
17
public class ProblemFilter extends MarkerFilterCriteria {
18
18
19
    private static final String TAG_CONTAINS = "contains"; //$NON-NLS-1$
19
    private static final String TAG_CONTAINS = "contains"; //$NON-NLS-1$
20
20
Lines 52-92 Link Here
52
        super(new String[] { IMarker.PROBLEM });
52
        super(new String[] { IMarker.PROBLEM });
53
    }
53
    }
54
54
55
    public boolean selectMarker(ConcreteMarker marker) {
55
    /* (non-Javadoc)
56
        if (!(marker instanceof ProblemMarker)) {
56
	 * @see org.eclipse.ui.views.markers.internal.MarkerFilterCriteria#getMarkerFilter()
57
            return false;
57
	 */
58
        }
58
	protected MarkerFilter getMarkerFilter() {
59
59
		MarkerFilter result = super.getMarkerFilter();
60
        ProblemMarker problemMarker = (ProblemMarker) marker;
60
		
61
61
		result.setSeverity(severity);
62
        return !isEnabled()
62
		result.setSelectBySeverity(selectBySeverity);
63
                || (super.selectMarker(problemMarker)
63
		result.setDescription(description, contains);
64
                        && selectByDescription(problemMarker) && selectBySeverity(problemMarker));
64
		
65
    }
65
		return result;
66
66
	}
67
    private boolean selectByDescription(ConcreteMarker item) {
68
        if (description == null || description.equals("")) //$NON-NLS-1$
69
            return true;
70
71
        String markerDescription = item.getDescription();
72
        int index = markerDescription.indexOf(description);
73
        return contains ? (index >= 0) : (index < 0);
74
    }
75
76
    private boolean selectBySeverity(ProblemMarker item) {
77
        if (selectBySeverity) {
78
            int markerSeverity = item.getSeverity();
79
80
            if (markerSeverity == IMarker.SEVERITY_ERROR)
81
                return (severity & SEVERITY_ERROR) > 0;
82
            else if (markerSeverity == IMarker.SEVERITY_WARNING)
83
                return (severity & SEVERITY_WARNING) > 0;
84
            else if (markerSeverity == IMarker.SEVERITY_INFO)
85
                return (severity & SEVERITY_INFO) > 0;
86
        }
87
88
        return true;
89
    }
90
67
91
    public boolean getContains() {
68
    public boolean getContains() {
92
        return contains;
69
        return contains;
(-)src/org/eclipse/ui/views/markers/internal/ProblemMarker.java (-38 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.views.markers.internal;
12
13
import org.eclipse.core.resources.IMarker;
14
15
/**
16
 * 
17
 */
18
public class ProblemMarker extends ConcreteMarker {
19
20
    private int severity;
21
22
    public ProblemMarker(IMarker toCopy) {
23
        super(toCopy);
24
25
    }
26
27
    /* (non-Javadoc)
28
     * @see org.eclipse.ui.views.markers.internal.ConcreteMarker#refresh()
29
     */
30
    public void refresh() {
31
        super.refresh();
32
        severity = getMarker().getAttribute(IMarker.SEVERITY, -1);
33
    }
34
35
    public int getSeverity() {
36
        return severity;
37
    }
38
}
(-)src/org/eclipse/ui/views/markers/internal/ProblemView.java (-17 / +17 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.core.resources.IMarker;
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.Platform;
16
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.IMenuManager;
19
import org.eclipse.jface.action.Separator;
18
import org.eclipse.jface.action.Separator;
Lines 167-175 Link Here
167
        return sorter;
166
        return sorter;
168
    }
167
    }
169
168
170
    protected Object getViewerInput() {
169
//    protected Object getViewerInput() {
171
        return ResourcesPlugin.getWorkspace().getRoot();
170
//        return ResourcesPlugin.getWorkspace().getRoot();
172
    }
171
//    }
173
172
174
    protected IField[] getVisibleFields() {
173
    protected IField[] getVisibleFields() {
175
        return VISIBLE_FIELDS;
174
        return VISIBLE_FIELDS;
Lines 179-195 Link Here
179
        super.initMenu(menu);
178
        super.initMenu(menu);
180
    }
179
    }
181
180
182
    void updateTitle() {
181
//    void updateTitle() {
183
        MarkerList visibleMarkers = getVisibleMarkers();
182
//        MarkerList visibleMarkers = getVisibleMarkers();
184
        String breakdown = formatSummaryBreakDown(visibleMarkers);
183
//        String breakdown = formatSummaryBreakDown(visibleMarkers);
185
        int filteredCount = visibleMarkers.getItemCount();
184
//        int filteredCount = visibleMarkers.getItemCount();
186
        int totalCount = getTotalMarkers();
185
//        int totalCount = getTotalMarkers();
187
        if (filteredCount != totalCount)
186
//        if (filteredCount != totalCount)
188
            breakdown = Messages.format("problem.filter.matchedMessage", //$NON-NLS-1$
187
//            breakdown = Messages.format("problem.filter.matchedMessage", //$NON-NLS-1$
189
                    new Object[] { breakdown, new Integer(filteredCount),
188
//                    new Object[] { breakdown, new Integer(filteredCount),
190
                            new Integer(totalCount) });
189
//                            new Integer(totalCount) });
191
        setContentDescription(breakdown);
190
//        setContentDescription(breakdown);
192
    }
191
//    }
193
192
194
    private String formatSummaryBreakDown(MarkerList visibleMarkers) {
193
    private String formatSummaryBreakDown(MarkerList visibleMarkers) {
195
        return Messages.format("problem.statusSummaryBreakdown", //$NON-NLS-1$
194
        return Messages.format("problem.statusSummaryBreakdown", //$NON-NLS-1$
Lines 229-235 Link Here
229
    /* (non-Javadoc)
228
    /* (non-Javadoc)
230
     * @see org.eclipse.ui.views.markers.internal.MarkerView#getFilter()
229
     * @see org.eclipse.ui.views.markers.internal.MarkerView#getFilter()
231
     */
230
     */
232
    protected MarkerFilter getFilter() {
231
    protected MarkerFilterCriteria getFilterCriteria() {
233
        return problemFilter;
232
        return problemFilter;
234
    }
233
    }
235
234
Lines 243-249 Link Here
243
        if (dialog.open() == Window.OK) {
242
        if (dialog.open() == Window.OK) {
244
            problemFilter = (ProblemFilter) dialog.getFilter();
243
            problemFilter = (ProblemFilter) dialog.getFilter();
245
            problemFilter.saveState(getDialogSettings());
244
            problemFilter.saveState(getDialogSettings());
246
            refresh();
245
            setFilter(dialog.getFilter().getFilter());
246
            setLimit(getFilterCriteria().getMarkerLimit());
247
        }
247
        }
248
    }
248
    }
249
249
(-)src/org/eclipse/ui/views/markers/internal/TableView.java (-46 / +49 lines)
Lines 12-22 Link Here
12
package org.eclipse.ui.views.markers.internal;
12
package org.eclipse.ui.views.markers.internal;
13
13
14
import java.util.Arrays;
14
import java.util.Arrays;
15
import java.util.Collection;
16
import java.util.HashMap;
15
import java.util.HashMap;
17
import java.util.Map;
16
import java.util.Map;
18
17
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.IAction;
21
import org.eclipse.jface.action.IMenuListener;
19
import org.eclipse.jface.action.IMenuListener;
22
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.action.IMenuManager;
Lines 33-38 Link Here
33
import org.eclipse.jface.viewers.SelectionChangedEvent;
31
import org.eclipse.jface.viewers.SelectionChangedEvent;
34
import org.eclipse.jface.viewers.TableLayout;
32
import org.eclipse.jface.viewers.TableLayout;
35
import org.eclipse.jface.viewers.TableViewer;
33
import org.eclipse.jface.viewers.TableViewer;
34
import org.eclipse.jface.viewers.deferred.AcceptAllFilter;
35
import org.eclipse.jface.viewers.deferred.DeferredContentProvider;
36
import org.eclipse.jface.viewers.deferred.IConcurrentModel;
37
import org.eclipse.jface.viewers.deferred.IFilter;
36
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.events.KeyAdapter;
39
import org.eclipse.swt.events.KeyAdapter;
38
import org.eclipse.swt.events.KeyEvent;
40
import org.eclipse.swt.events.KeyEvent;
Lines 55-61 Link Here
55
57
56
public abstract class TableView extends ViewPart {
58
public abstract class TableView extends ViewPart {
57
59
58
    private TableContentProvider content;
60
    private DeferredContentProvider content;
59
61
60
    private static final String TAG_COLUMN_WIDTH = "columnWidth"; //$NON-NLS-1$
62
    private static final String TAG_COLUMN_WIDTH = "columnWidth"; //$NON-NLS-1$
61
63
Lines 78-84 Link Here
78
    private ISelectionProvider selectionProvider = new SelectionProviderAdapter();
80
    private ISelectionProvider selectionProvider = new SelectionProviderAdapter();
79
81
80
    private TableSorter sorter;
82
    private TableSorter sorter;
81
83
    private int limit = -1;
84
    
85
    private IFilter filter = AcceptAllFilter.getInstance();
86
    
82
    /* (non-Javadoc)
87
    /* (non-Javadoc)
83
     * Method declared on IViewPart.
88
     * Method declared on IViewPart.
84
     */
89
     */
Lines 87-114 Link Here
87
        this.memento = memento;
92
        this.memento = memento;
88
    }
93
    }
89
94
90
    /**
91
     * 
92
     */
93
    void haltTableUpdates() {
94
        content.cancelPendingChanges();
95
    }
96
97
    void change(Collection toRefresh) {
98
        content.change(toRefresh);
99
    }
100
101
    void setContents(Collection contents, IProgressMonitor mon) {
102
        content.set(contents, mon);
103
    }
104
105
    protected ISelectionProvider getSelectionProvider() {
95
    protected ISelectionProvider getSelectionProvider() {
106
        return selectionProvider;
96
        return selectionProvider;
107
    }
97
    }
108
98
109
    abstract protected void viewerSelectionChanged(
99
    abstract protected void viewerSelectionChanged(
110
            IStructuredSelection selection);
100
            IStructuredSelection selection);
111
101
    
102
    protected void setFilter(IFilter newFilter) {
103
    	if (filter.equals(newFilter)) {
104
    		return;
105
    	}
106
    	filter = newFilter;
107
    	if (content != null) {
108
    		content.setFilter(filter);
109
    	}
110
    }
111
    
112
    protected void setLimit(int newLimit) {
113
    	limit = newLimit;
114
    	if (content != null) {
115
    		content.setLimit(newLimit);
116
    	}
117
    }
118
    
112
    /* (non-Javadoc)
119
    /* (non-Javadoc)
113
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
120
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
114
     */
121
     */
Lines 118-127 Link Here
118
        viewer = new TableViewer(createTable(parent));
125
        viewer = new TableViewer(createTable(parent));
119
        restoreColumnWidths(memento);
126
        restoreColumnWidths(memento);
120
        createColumns(viewer.getTable());
127
        createColumns(viewer.getTable());
121
        content = new TableContentProvider(viewer, Messages.format(
128
        content = new DeferredContentProvider(getSorter());
122
                "TableView.populating", //$NON-NLS-1$
129
        content.setFilter(filter);
123
                new Object[] { getTitle() }), getProgressService());
130
        content.setLimit(limit);
124
125
        viewer.setContentProvider(content);
131
        viewer.setContentProvider(content);
126
132
127
        viewer.setLabelProvider(new TableViewLabelProvider(getVisibleFields()));
133
        viewer.setLabelProvider(new TableViewLabelProvider(getVisibleFields()));
Lines 190-198 Link Here
190
        TableSorter newSorter = new TableSorter(sorter2);
196
        TableSorter newSorter = new TableSorter(sorter2);
191
197
192
        sorter = newSorter;
198
        sorter = newSorter;
193
        content.setSorter(newSorter);
194
        newSorter.saveState(getDialogSettings());
199
        newSorter.saveState(getDialogSettings());
195
        sorterChanged();
200
        content.setSortOrder(newSorter);
196
    }
201
    }
197
202
198
    /* (non-Javadoc)
203
    /* (non-Javadoc)
Lines 205-213 Link Here
205
    /**
210
    /**
206
     * Creates the table control.
211
     * Creates the table control.
207
     */
212
     */
208
    protected Table createTable(Composite parent) {
213
    private Table createTable(Composite parent) {
209
        Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
214
        Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
210
                | SWT.FULL_SELECTION);
215
                | SWT.FULL_SELECTION | SWT.VIRTUAL);
211
        table.setLinesVisible(true);
216
        table.setLinesVisible(true);
212
        table.setFont(parent.getFont());
217
        table.setFont(parent.getFont());
213
        return table;
218
        return table;
Lines 322-328 Link Here
322
        return fields;
327
        return fields;
323
    }
328
    }
324
329
325
    protected abstract Object getViewerInput();
330
    protected abstract IConcurrentModel getViewerInput();
326
331
327
    protected abstract IField[] getVisibleFields();
332
    protected abstract IField[] getVisibleFields();
328
333
Lines 363-385 Link Here
363
        return null;
368
        return null;
364
    }
369
    }
365
370
366
    protected void sorterChanged() {
371
//    protected void sorterChanged() {
367
372
//
368
        viewer.setSorter(getSorter());
373
//        final TableViewer viewer = getViewer();
369
374
//        if (viewer == null) {
370
        final TableViewer viewer = getViewer();
375
//            return;
371
        if (viewer == null) {
376
//        }
372
            return;
377
//
373
        }
378
//        getSite().getShell().getDisplay().asyncExec(new Runnable() {
374
379
//            public void run() {
375
        getSite().getShell().getDisplay().asyncExec(new Runnable() {
380
//                viewer.getControl().setRedraw(false);
376
            public void run() {
381
//                viewer.refresh(false);
377
                viewer.getControl().setRedraw(false);
382
//                viewer.getControl().setRedraw(true);
378
                viewer.refresh(false);
383
//            }
379
                viewer.getControl().setRedraw(true);
384
//        });
380
            }
385
//    }
381
        });
382
    }
383
386
384
    protected abstract void handleKeyPressed(KeyEvent event);
387
    protected abstract void handleKeyPressed(KeyEvent event);
385
388
(-)src/org/eclipse/ui/views/markers/internal/TaskFilter.java (-44 / +16 lines)
Lines 14-20 Link Here
14
import org.eclipse.core.resources.IMarker;
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.jface.dialogs.IDialogSettings;
15
import org.eclipse.jface.dialogs.IDialogSettings;
16
16
17
public class TaskFilter extends MarkerFilter {
17
public class TaskFilter extends MarkerFilterCriteria {
18
18
19
    private static final String TAG_CONTAINS = "contains"; //$NON-NLS-1$
19
    private static final String TAG_CONTAINS = "contains"; //$NON-NLS-1$
20
20
Lines 64-112 Link Here
64
        super(new String[] { IMarker.TASK });
64
        super(new String[] { IMarker.TASK });
65
    }
65
    }
66
66
67
    public boolean selectMarker(ConcreteMarker marker) {
67
    /* (non-Javadoc)
68
        if (!(marker instanceof TaskMarker)) {
68
	 * @see org.eclipse.ui.views.markers.internal.MarkerFilterCriteria#getMarkerFilter()
69
            return false;
69
	 */
70
        }
70
	protected MarkerFilter getMarkerFilter() {
71
71
		MarkerFilter result = super.getMarkerFilter();
72
        TaskMarker taskMarker = (TaskMarker) marker;
72
		
73
73
		result.setPriority(priority);
74
        return !isEnabled()
74
		result.setSelectByPriority(selectByPriority);
75
                || (super.selectMarker(taskMarker)
75
		result.setDone(done);
76
                        && selectByDescription(taskMarker)
76
		result.setSelectByDone(selectByDone);
77
                        && selectByDone(taskMarker) && selectByPriority(taskMarker));
77
		result.setDescription(description, contains);
78
    }
78
		
79
79
		return result;
80
    private boolean selectByDescription(ConcreteMarker marker) {
80
	}
81
        if (description == null || description.equals("")) //$NON-NLS-1$
81
    
82
            return true;
83
84
        int index = marker.getDescription().indexOf(description);
85
        return contains ? (index >= 0) : (index < 0);
86
    }
87
88
    private boolean selectByDone(TaskMarker item) {
89
        if (selectByDone)
90
            return done == (item.getDone() == 1);
91
92
        return true;
93
    }
94
95
    private boolean selectByPriority(TaskMarker marker) {
96
        if (priority != 0 && selectByPriority) {
97
            int markerPriority = marker.getPriority();
98
99
            if (markerPriority == IMarker.PRIORITY_HIGH)
100
                return (priority & PRIORITY_HIGH) > 0;
101
            else if (markerPriority == IMarker.PRIORITY_NORMAL)
102
                return (priority & PRIORITY_NORMAL) > 0;
103
            else if (markerPriority == IMarker.PRIORITY_LOW)
104
                return (priority & PRIORITY_LOW) > 0;
105
        }
106
107
        return true;
108
    }
109
110
    public boolean getContains() {
82
    public boolean getContains() {
111
        return contains;
83
        return contains;
112
    }
84
    }
(-)src/org/eclipse/ui/views/markers/internal/TaskMarker.java (-55 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.views.markers.internal;
12
13
import org.eclipse.core.resources.IMarker;
14
15
/**
16
 * Represents a marker visible in the Tasks view. Additional members should be added
17
 * to this class if new fields are added to the Tasks view. Such members should be
18
 * initialized in the constructor, and accessed via get methods rather than accessing
19
 * the IMarker instance directly. This is necessary to support sorting in a reasonable
20
 * time bound.
21
 */
22
public class TaskMarker extends ConcreteMarker {
23
24
    private int priority;
25
26
    private int done;
27
28
    /**
29
     * @param toCopy
30
     */
31
    public TaskMarker(IMarker toCopy) {
32
        super(toCopy);
33
    }
34
35
    public void refresh() {
36
        super.refresh();
37
        priority = getMarker().getAttribute(IMarker.PRIORITY,
38
                IMarker.PRIORITY_NORMAL);
39
        done = -1;
40
        if (getMarker().getAttribute(IMarker.USER_EDITABLE, true)) {
41
            done = 0;
42
            if (getMarker().getAttribute(IMarker.DONE, false)) {
43
                done = 1;
44
            }
45
        }
46
    }
47
48
    public int getPriority() {
49
        return priority;
50
    }
51
52
    public int getDone() {
53
        return done;
54
    }
55
}
(-)src/org/eclipse/ui/views/markers/internal/TaskView.java (-10 / +18 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.core.resources.IMarker;
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.jface.action.IMenuManager;
18
import org.eclipse.jface.action.IMenuManager;
Lines 73-79 Link Here
73
    private ICellModifier cellModifier = new ICellModifier() {
72
    private ICellModifier cellModifier = new ICellModifier() {
74
        public Object getValue(Object element, String property) {
73
        public Object getValue(Object element, String property) {
75
            if (element instanceof ConcreteMarker) {
74
            if (element instanceof ConcreteMarker) {
76
                IMarker marker = ((ConcreteMarker) element).getMarker();
75
                IMarker marker;
76
				try {
77
					marker = ((ConcreteMarker) element).getMarker();
78
				} catch (CoreException e) {
79
					return null;
80
				}
77
81
78
                if (COMPLETION.equals(property))
82
                if (COMPLETION.equals(property))
79
                    return new Boolean(marker.getAttribute(IMarker.DONE, false));
83
                    return new Boolean(marker.getAttribute(IMarker.DONE, false));
Lines 91-97 Link Here
91
        }
95
        }
92
96
93
        public boolean canModify(Object element, String property) {
97
        public boolean canModify(Object element, String property) {
94
            return Util.isEditable(((ConcreteMarker) element).getMarker());
98
            try {
99
				return Util.isEditable(((ConcreteMarker) element).getMarker());
100
			} catch (CoreException e) {
101
				return false;
102
			}
95
        }
103
        }
96
104
97
        public void modify(Object element, String property, Object value) {
105
        public void modify(Object element, String property, Object value) {
Lines 102-110 Link Here
102
                if (data instanceof ConcreteMarker) {
110
                if (data instanceof ConcreteMarker) {
103
                    ConcreteMarker concreteMarker = (ConcreteMarker) data;
111
                    ConcreteMarker concreteMarker = (ConcreteMarker) data;
104
112
105
                    IMarker marker = concreteMarker.getMarker();
106
107
                    try {
113
                    try {
114
                        IMarker marker = concreteMarker.getMarker();
108
                        Object oldValue = getValue(data, property);
115
                        Object oldValue = getValue(data, property);
109
                        if (oldValue != null && !oldValue.equals(value)) {
116
                        if (oldValue != null && !oldValue.equals(value)) {
110
                            if (COMPLETION.equals(property))
117
                            if (COMPLETION.equals(property))
Lines 265-273 Link Here
265
        return ROOT_TYPES;
272
        return ROOT_TYPES;
266
    }
273
    }
267
274
268
    protected Object getViewerInput() {
275
//    protected Object getViewerInput() {
269
        return ResourcesPlugin.getWorkspace().getRoot();
276
//        return ResourcesPlugin.getWorkspace().getRoot();
270
    }
277
//    }
271
278
272
    protected IField[] getVisibleFields() {
279
    protected IField[] getVisibleFields() {
273
        return VISIBLE_FIELDS;
280
        return VISIBLE_FIELDS;
Lines 294-300 Link Here
294
    /* (non-Javadoc)
301
    /* (non-Javadoc)
295
     * @see org.eclipse.ui.views.markers.internal.MarkerView#getFilter()
302
     * @see org.eclipse.ui.views.markers.internal.MarkerView#getFilter()
296
     */
303
     */
297
    protected MarkerFilter getFilter() {
304
    protected MarkerFilterCriteria getFilterCriteria() {
298
        return taskFilter;
305
        return taskFilter;
299
    }
306
    }
300
307
Lines 308-314 Link Here
308
        if (dialog.open() == Window.OK) {
315
        if (dialog.open() == Window.OK) {
309
            taskFilter = (TaskFilter) dialog.getFilter();
316
            taskFilter = (TaskFilter) dialog.getFilter();
310
            taskFilter.saveState(getDialogSettings());
317
            taskFilter.saveState(getDialogSettings());
311
            refresh();
318
            setFilter(dialog.getFilter().getFilter());
319
            setLimit(getFilterCriteria().getMarkerLimit());
312
        }
320
        }
313
    }
321
    }
314
322
(-)src/org/eclipse/ui/views/markers/internal/MarkerFilterCriteria.java (+528 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.views.markers.internal;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.HashSet;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Set;
20
import java.util.StringTokenizer;
21
22
import org.eclipse.core.resources.IContainer;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IAdaptable;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.jface.dialogs.IDialogSettings;
29
import org.eclipse.jface.util.Assert;
30
import org.eclipse.jface.viewers.deferred.AcceptAllFilter;
31
import org.eclipse.jface.viewers.deferred.IFilter;
32
import org.eclipse.ui.IWorkingSet;
33
import org.eclipse.ui.internal.WorkbenchPlugin;
34
35
public class MarkerFilterCriteria {
36
37
    private static final String TAG_DIALOG_SECTION = "filter"; //$NON-NLS-1$
38
39
    private static final String TAG_ENABLED = "enabled"; //$NON-NLS-1$
40
41
    private static final String TAG_FILTER_ON_MARKER_LIMIT = "filterOnMarkerLimit"; //$NON-NLS-1$
42
43
    private static final String TAG_MARKER_LIMIT = "markerLimit"; //$NON-NLS-1$
44
45
    private static final String TAG_ON_RESOURCE = "onResource"; //$NON-NLS-1$
46
47
    private static final String TAG_SELECTED_TYPES = "selectedType"; //$NON-NLS-1$
48
49
    private static final String TAG_WORKING_SET = "workingSet"; //$NON-NLS-1$
50
51
    private static final String TAG_TYPES_DELIMITER = ":"; //$NON-NLS-1$
52
53
    static final int ON_ANY_RESOURCE = 0;
54
55
    static final int ON_SELECTED_RESOURCE_ONLY = 1;
56
57
    static final int ON_SELECTED_RESOURCE_AND_CHILDREN = 2;
58
59
    static final int ON_ANY_RESOURCE_OF_SAME_PROJECT = 3;
60
61
    static final int ON_WORKING_SET = 4;
62
63
    static final int DEFAULT_MARKER_LIMIT = 100;
64
65
    static final boolean DEFAULT_FILTER_ON_MARKER_LIMIT = true;
66
67
    static final int DEFAULT_ON_RESOURCE = ON_ANY_RESOURCE;
68
69
    static final boolean DEFAULT_ACTIVATION_STATUS = true;
70
71
    protected List rootTypes = new ArrayList();
72
73
    protected List selectedTypes = new ArrayList();
74
75
    protected IWorkingSet workingSet;
76
77
    protected int onResource;
78
79
    protected boolean filterOnMarkerLimit;
80
81
    protected boolean enabled;
82
83
    protected int markerLimit;
84
85
    private MarkerTypesModel typesModel;
86
87
    private IResource[] focusResource = new IResource[0];
88
89
    private Set cachedWorkingSet;
90
91
    MarkerFilterCriteria(String[] rootTypes) {
92
        typesModel = new MarkerTypesModel();
93
94
        for (int i = 0; i < rootTypes.length; i++) {
95
            MarkerType type = typesModel.getType(rootTypes[i]);
96
97
            if (!this.rootTypes.contains(type))
98
                this.rootTypes.add(type);
99
        }
100
    }
101
102
    private void addAllSubTypes() {
103
        for (int i = 0; i < rootTypes.size(); i++) {
104
            MarkerType rootType = (MarkerType) rootTypes.get(i);
105
            addAllSubTypes(rootType);
106
        }
107
    }
108
109
    private void addAllSubTypes(MarkerType type) {
110
        if (type == null)
111
            return;
112
113
        if (!selectedTypes.contains(type))
114
            selectedTypes.add(type);
115
116
        MarkerType[] subTypes = type.getSubtypes();
117
118
        for (int i = 0; i < subTypes.length; i++)
119
            addAllSubTypes(subTypes[i]);
120
    }
121
122
    IResource[] getResourcesInWorkingSet() {
123
        if (workingSet == null) {
124
            return new IResource[0];
125
        }
126
127
        IAdaptable[] elements = workingSet.getElements();
128
        List result = new ArrayList(elements.length);
129
130
        for (int idx = 0; idx < elements.length; idx++) {
131
            IResource next = (IResource) elements[idx]
132
                    .getAdapter(IResource.class);
133
134
            if (next != null) {
135
                result.add(next);
136
            }
137
        }
138
139
        return (IResource[]) result.toArray(new IResource[result.size()]);
140
    }
141
142
    /**
143
     * Returns a set of strings representing the full pathnames to every resource directly
144
     * or indirectly contained in the working set. A resource is in the working set iff its
145
     * path name can be found in this set.
146
     * 
147
     * @return
148
     */
149
    private Set getWorkingSetAsSetOfPaths() {
150
        if (cachedWorkingSet == null) {
151
            HashSet result = new HashSet();
152
153
            addResourcesAndChildren(result, getResourcesInWorkingSet());
154
155
            cachedWorkingSet = result;
156
        }
157
158
        return cachedWorkingSet;
159
    }
160
161
    /***
162
     * Adds the paths of all resources in the given array to the given set. 
163
     */
164
    private void addResourcesAndChildren(Set result, IResource[] resources) {
165
        for (int idx = 0; idx < resources.length; idx++) {
166
167
            IResource currentResource = resources[idx];
168
169
            IPath next = currentResource.getFullPath();
170
            if (result.contains(next)) {
171
            	return;
172
            }
173
            result.add(next);
174
175
            if (currentResource instanceof IContainer) {
176
                IContainer cont = (IContainer) currentResource;
177
178
                try {
179
                    addResourcesAndChildren(result, cont.members());
180
                } catch (CoreException e) {
181
                    // Ignore errors
182
                }
183
            }
184
185
        }
186
    }
187
188
    /**
189
     * Returns the set of projects that contain the given set of resources.
190
     * 
191
     * @param resources
192
     * @return
193
     */
194
    static IProject[] getProjects(IResource[] resources) {
195
        if (resources == null) {
196
            return new IProject[0];
197
        }
198
199
        Collection projects = getProjectsAsCollection(resources);
200
201
        return (IProject[]) projects.toArray(new IProject[projects.size()]);
202
    }
203
204
    static Collection getProjectsAsCollection(IResource[] resources) {
205
        HashSet projects = new HashSet();
206
207
        for (int idx = 0; idx < resources.length; idx++) {
208
            projects.add(resources[idx].getProject());
209
        }
210
211
        return projects;
212
    }
213
214
    /**
215
     * Returns if the given resource is enclosed by a working set element.
216
     * Previous versions of this method used IContainmentAdapter for 
217
     * containment tests. For performance reasons, this is no longer possible.
218
     * Code that relies on this behavior should be updated appropriately.
219
     * 
220
     * @param element resource to test for enclosure by a working set
221
     * 	element 
222
     * @return true if element is enclosed by a working set element and 
223
     * 	false otherwise. 
224
     */
225
    private boolean isEnclosed(IResource element) {
226
        if (workingSet == null) {
227
            return false;
228
        }
229
        Set workingSetPaths = getWorkingSetAsSetOfPaths();
230
231
        return workingSetPaths.contains(element.getFullPath().toString());
232
    }
233
234
    /**
235
     * @return the defined limit on the number of markers to be displayed.
236
     */
237
    int getMarkerLimit() {
238
        return markerLimit;
239
    }
240
241
    /**
242
     * Sets the limit on the number of markers to be displayed.
243
     * 
244
     * @param the new limit
245
     */
246
    void setMarkerLimit(int markerLimit) {
247
        this.markerLimit = markerLimit;
248
    }
249
250
    /**
251
     * @return <ul>
252
     * <li><code>MarkerFilter.ON_ANY_RESOURCE</code> if showing items associated with any resource.</li>
253
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_ONLY</code> if showing items associated with
254
     * the selected resource within the workbench.</li>
255
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN</code> if showing items associated with
256
     * the selected resource within the workbench and its children.</li>
257
     * <li><code>MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT</code> if showing items in the same project
258
     * as the selected resource within the workbench.</li>
259
     * <li><code>MarkerFilter.ON_WORKING_SET</code> if showing items in some working set.</li>
260
     * </ul>
261
     */
262
    int getOnResource() {
263
        return onResource;
264
    }
265
266
    /**
267
     * Sets the type of filtering by selection.
268
     * 
269
     * @param onResource must be one of:
270
     * <ul>
271
     * <li><code>MarkerFilter.ON_ANY_RESOURCE</code></li>
272
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_ONLY</code></li>
273
     * <li><code>MarkerFilter.ON_SELECTED_RESOURCE_AND_CHILDREN</code></li>
274
     * <li><code>MarkerFilter.ON_ANY_RESOURCE_OF_SAME_PROJECT</code></li>
275
     * <li><code>MarkerFilter.ON_WORKING_SET</code></li>
276
     * </ul>
277
     */
278
    void setOnResource(int onResource) {
279
        if (onResource >= ON_ANY_RESOURCE && onResource <= ON_WORKING_SET)
280
            this.onResource = onResource;
281
    }
282
283
    /**
284
     * @return the selected resource(s) withing the workbench.
285
     */
286
    IResource[] getFocusResource() {
287
        return focusResource;
288
    }
289
290
    /**
291
     * Sets the focused resources.
292
     */
293
    public void setFocusResource(IResource[] resources) {
294
    	Assert.isNotNull(resources);
295
        focusResource = resources;
296
    }
297
298
    /**
299
     * @return
300
     * <ul>
301
     * <li><code>true</code> if the filter is enabled.</li>
302
     * <li><code>false</code> if the filter is not enabled.</li>
303
     * </ul>
304
     */
305
    boolean isEnabled() {
306
        return enabled;
307
    }
308
309
    /**
310
     * @return
311
     * <ul>
312
     * <li><code>true</code> if filtering by marker limit is enabled.</li>
313
     * <li><code>false</code> if filtering by marker limit is not enabled.</li>
314
     * </ul>
315
     */
316
    boolean getFilterOnMarkerLimit() {
317
        return filterOnMarkerLimit;
318
    }
319
320
    /**
321
     * @return the root marker types.
322
     */
323
    List getRootTypes() {
324
        return rootTypes;
325
    }
326
327
    /**
328
     * @return the selected marker types to be displayed.
329
     */
330
    List getSelectedTypes() {
331
        return selectedTypes;
332
    }
333
334
    /**
335
     * @return the current working set or <code>null</code> if no working set is defined.
336
     */
337
    IWorkingSet getWorkingSet() {
338
        return workingSet;
339
    }
340
341
    /**
342
     * Sets the enablement state of the filter.
343
     */
344
    void setEnabled(boolean enabled) {
345
        this.enabled = enabled;
346
    }
347
348
    /**
349
     * Sets the enablement state of filtering by marker limit.
350
     */
351
    void setFilterOnMarkerLimit(boolean filterOnMarkerLimit) {
352
        this.filterOnMarkerLimit = filterOnMarkerLimit;
353
    }
354
355
    /**
356
     * Sets the selected marker types to be displayed. The List <b>MUST ONLY</b> contain 
357
     * <code>MarkerType</code> objects.
358
     */
359
    void setSelectedTypes(List selectedTypes) {
360
        this.selectedTypes = selectedTypes;
361
    }
362
363
    /**
364
     * Sets the current working set.
365
     */
366
    void setWorkingSet(IWorkingSet workingSet) {
367
        this.workingSet = workingSet;
368
        cachedWorkingSet = null;
369
    }
370
371
    void resetState() {
372
        enabled = DEFAULT_ACTIVATION_STATUS;
373
        filterOnMarkerLimit = DEFAULT_FILTER_ON_MARKER_LIMIT;
374
        markerLimit = DEFAULT_MARKER_LIMIT;
375
        onResource = DEFAULT_ON_RESOURCE;
376
        selectedTypes.clear();
377
        addAllSubTypes();
378
        setWorkingSet(null);
379
    }
380
381
    protected MarkerFilter getMarkerFilter() {
382
    	
383
    	List typesList = new ArrayList();
384
    	
385
    	for (Iterator iter = selectedTypes.iterator(); iter.hasNext();) {
386
			MarkerType type = (MarkerType) iter.next();
387
			
388
			typesList.add(type.getId());
389
		}
390
    	String[] types = (String[]) typesList.toArray(new String[typesList.size()]);
391
392
    	Set resources;
393
    	
394
    	switch(onResource) {
395
    	case ON_ANY_RESOURCE_OF_SAME_PROJECT: {
396
    		resources = new HashSet();
397
    		
398
            for (int i = 0; i < focusResource.length; i++) {
399
                IProject selectedProject = focusResource[i].getProject();
400
401
                if (selectedProject == null) {
402
                    continue;
403
                }
404
                
405
                resources.add(selectedProject.getFullPath());
406
            }
407
    		return new MarkerFilter(types, resources, true);
408
    	}
409
    	case ON_SELECTED_RESOURCE_AND_CHILDREN: {
410
    		resources = new HashSet();
411
    	
412
    		for (int i = 0; i < focusResource.length; i++) {
413
				IResource res = focusResource[i];
414
				
415
				resources.add(res.getFullPath());
416
			}
417
    		return new MarkerFilter(types, resources, true);
418
    	}
419
    	case ON_SELECTED_RESOURCE_ONLY: {
420
    		resources = new HashSet();
421
    	
422
    		for (int i = 0; i < focusResource.length; i++) {
423
				IResource res = focusResource[i];
424
				
425
				resources.add(res.getFullPath());
426
			}
427
    		return new MarkerFilter(types, resources, false);
428
    	} 
429
    	case ON_WORKING_SET: {
430
    		return new MarkerFilter(types, getWorkingSetAsSetOfPaths(), false);
431
    	}
432
    	default:
433
    		return new MarkerFilter(types);
434
    	}
435
    	
436
    }
437
    
438
    public final IFilter getFilter() {
439
    	if (!isEnabled()) {
440
    		return AcceptAllFilter.getInstance();
441
    	}
442
    	
443
    	return getMarkerFilter();
444
    }
445
    
446
    public void restoreState(IDialogSettings dialogSettings) {
447
        resetState();
448
        IDialogSettings settings = dialogSettings
449
                .getSection(TAG_DIALOG_SECTION);
450
451
        if (settings != null) {
452
            String setting = settings.get(TAG_ENABLED);
453
454
            if (setting != null)
455
                enabled = Boolean.valueOf(setting).booleanValue();
456
457
            setting = settings.get(TAG_FILTER_ON_MARKER_LIMIT);
458
459
            if (setting != null)
460
                filterOnMarkerLimit = Boolean.valueOf(setting).booleanValue();
461
462
            setting = settings.get(TAG_MARKER_LIMIT);
463
464
            if (setting != null)
465
                try {
466
                    markerLimit = Integer.parseInt(setting);
467
                } catch (NumberFormatException eNumberFormat) {
468
                }
469
470
            setting = settings.get(TAG_ON_RESOURCE);
471
472
            if (setting != null)
473
                try {
474
                    onResource = Integer.parseInt(setting);
475
                } catch (NumberFormatException eNumberFormat) {
476
                }
477
478
            setting = settings.get(TAG_SELECTED_TYPES);
479
480
            if (setting != null) {
481
                selectedTypes.clear();
482
                StringTokenizer stringTokenizer = new StringTokenizer(setting);
483
484
                while (stringTokenizer.hasMoreTokens()) {
485
                    MarkerType markerType = typesModel.getType(stringTokenizer
486
                            .nextToken(TAG_TYPES_DELIMITER));
487
488
                    if (markerType != null
489
                            && !selectedTypes.contains(markerType))
490
                        selectedTypes.add(markerType);
491
                }
492
            }
493
494
            setting = settings.get(TAG_WORKING_SET);
495
496
            if (setting != null)
497
                setWorkingSet(WorkbenchPlugin.getDefault()
498
                        .getWorkingSetManager().getWorkingSet(setting));
499
        }
500
    }
501
502
    public void saveState(IDialogSettings dialogSettings) {
503
        if (dialogSettings != null) {
504
            IDialogSettings settings = dialogSettings
505
                    .getSection(TAG_DIALOG_SECTION);
506
507
            if (settings == null)
508
                settings = dialogSettings.addNewSection(TAG_DIALOG_SECTION);
509
510
            settings.put(TAG_ENABLED, enabled);
511
            settings.put(TAG_FILTER_ON_MARKER_LIMIT, filterOnMarkerLimit);
512
            settings.put(TAG_MARKER_LIMIT, markerLimit);
513
            settings.put(TAG_ON_RESOURCE, onResource);
514
515
            String markerTypeIds = ""; //$NON-NLS-1$
516
517
            for (int i = 0; i < selectedTypes.size(); i++) {
518
                MarkerType markerType = (MarkerType) selectedTypes.get(i);
519
                markerTypeIds += markerType.getId() + TAG_TYPES_DELIMITER;
520
            }
521
522
            settings.put(TAG_SELECTED_TYPES, markerTypeIds);
523
524
            if (workingSet != null)
525
                settings.put(TAG_WORKING_SET, workingSet.getName());
526
        }
527
    }
528
}
(-)src/org/eclipse/ui/views/markers/internal/MarkerProvider.java (+228 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.views.markers.internal;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.resources.IMarkerDelta;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IResourceChangeEvent;
20
import org.eclipse.core.resources.IResourceChangeListener;
21
import org.eclipse.core.resources.IResourceDelta;
22
import org.eclipse.core.resources.IWorkspaceRoot;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Platform;
28
import org.eclipse.core.runtime.Status;
29
import org.eclipse.core.runtime.jobs.IJobManager;
30
import org.eclipse.core.runtime.jobs.Job;
31
import org.eclipse.jface.viewers.deferred.AbstractConcurrentModel;
32
import org.eclipse.jface.viewers.deferred.IConcurrentModel;
33
import org.eclipse.jface.viewers.deferred.IConcurrentModelListener;
34
35
/**
36
 * @since 3.1
37
 */
38
public class MarkerProvider extends AbstractConcurrentModel {
39
40
    private static final String WAITING_FOR_WORKSPACE_CHANGES_TO_FINISH = Messages
41
            .getString("MarkerView.waiting_on_changes"); //$NON-NLS-1$
42
43
    private static final String SEARCHING_FOR_MARKERS = Messages
44
            .getString("MarkerView.searching_for_markers"); //$NON-NLS-1$
45
46
    private static final String REFRESHING_MARKER_COUNTS = Messages
47
            .getString("MarkerView.refreshing_counts"); //$NON-NLS-1$
48
    
49
    private IWorkspaceRoot getWorkspaceRoot() {
50
        return ResourcesPlugin.getWorkspace().getRoot();
51
    }
52
    
53
    private Job searchJob = new Job(SEARCHING_FOR_MARKERS) {
54
	    /* (non-Javadoc)
55
	     * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
56
	     */
57
	    protected IStatus run(IProgressMonitor monitor) {
58
	        doRefresh(monitor);
59
	        return Status.OK_STATUS;
60
	    }  
61
    };
62
63
    private int totalMarkers = 0;
64
    private ArrayList awaitingRefresh = new ArrayList();
65
    private volatile boolean refreshScheduled = false;
66
    
67
    IResourceChangeListener resourceListener = new IResourceChangeListener() {
68
        public void resourceChanged(IResourceChangeEvent event) {
69
            MarkerProvider.this.resourceChanged(event);
70
        }
71
    };
72
    
73
    
74
    private static int refCount = 0;
75
    private static MarkerProvider singleton = null;
76
    
77
    public static IConcurrentModel getRef() {
78
    	if (singleton == null) {
79
    		singleton = new MarkerProvider();
80
    	}
81
    	
82
    	refCount++;
83
    	return singleton;
84
    }
85
    
86
    public static void releaseRef(IConcurrentModel toRelease) {
87
    	refCount--;
88
    	if (refCount == 0) {
89
    		singleton.dispose();
90
    		singleton = null;
91
    	}
92
    }
93
    
94
    
95
    private MarkerProvider() {
96
        ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener);
97
        searchJob.setSystem(true);
98
    }
99
100
    public void resourceChanged(IResourceChangeEvent event) {
101
        String[] markerTypes = getMarkerTypes();
102
103
        boolean refreshNeeded = false;
104
105
        for (int idx = 0; idx < markerTypes.length; idx++) {
106
            IMarkerDelta[] markerDeltas = event.findMarkerDeltas(
107
                    markerTypes[idx], true);
108
            List changes = new ArrayList(markerDeltas.length / 3);
109
            List additions = new ArrayList(markerDeltas.length / 3);
110
            List removals = new ArrayList(markerDeltas.length / 3);
111
112
            examineDelta(markerDeltas, changes, additions, removals);
113
114
            fireRemove(removals.toArray());
115
            fireAdd(additions.toArray());
116
            fireUpdate(changes.toArray());            
117
        }
118
    }
119
120
    private void examineDelta(IMarkerDelta[] deltas, List changes, List additions, List removals) {
121
        for (int idx = 0; idx < deltas.length; idx++) {
122
            IMarkerDelta delta = deltas[idx];
123
            int kind = delta.getKind();
124
125
            if (kind == IResourceDelta.CHANGED) {
126
                changes.add(MarkerList.createMarker(deltas[idx].getMarker()));
127
            } else if (kind == IResourceDelta.ADDED) {
128
                additions.add(MarkerList.createMarker(deltas[idx].getMarker()));
129
            } else if (kind == IResourceDelta.REMOVED) {
130
                removals.add(MarkerList.createMarker(deltas[idx].getMarker()));
131
            }
132
        }
133
    }
134
    
135
    public void dispose() {
136
        ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener);
137
    }
138
        
139
    public int getTotalMarkers() {
140
        return totalMarkers;
141
    }
142
    
143
    private String[] getMarkerTypes() {
144
        return new String[] {IMarker.MARKER};
145
    }
146
    
147
    /* (non-Javadoc)
148
     * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#getElements(org.eclipse.core.runtime.IProgressMonitor)
149
     */
150
    public void doRefresh(IProgressMonitor monitor) {
151
        IJobManager jobMan = Platform.getJobManager();
152
        IWorkspaceRoot root = getWorkspaceRoot();
153
154
        ArrayList result = new ArrayList();
155
        
156
        try {
157
            monitor.subTask(WAITING_FOR_WORKSPACE_CHANGES_TO_FINISH);
158
159
            jobMan.beginRule(root, monitor);
160
161
            if (monitor.isCanceled()) {
162
                throw new InterruptedException();
163
            }
164
165
            monitor.subTask(SEARCHING_FOR_MARKERS);
166
            IMarker[] markers = root.findMarkers(IMarker.MARKER,
167
                    true, IResource.DEPTH_INFINITE);
168
            
169
            for (int i = 0; i < markers.length; i++) {
170
                IMarker marker = markers[i];
171
                
172
                ConcreteMarker next = MarkerList.createMarker(marker);
173
174
                result.add(next);
175
            }
176
            
177
            IConcurrentModelListener[] listeners;
178
            synchronized(awaitingRefresh) {
179
            	listeners = (IConcurrentModelListener[]) awaitingRefresh.toArray(new IConcurrentModelListener[awaitingRefresh.size()]);
180
            	            
181
                awaitingRefresh.clear();
182
                refreshScheduled = false;
183
            }
184
185
            Object[] newContents = result.toArray();
186
            for (int i = 0; i < listeners.length; i++) {
187
    			IConcurrentModelListener listener = listeners[i];
188
    			
189
    			listener.setContents(newContents);
190
    		}
191
            
192
        } catch (CoreException e) {
193
            // TODO: SHOULD LOG THIS!!!!!!!!!!!!
194
        } catch (InterruptedException e) {
195
        } finally {
196
            jobMan.endRule(root);
197
        }
198
        
199
    }
200
201
    /* (non-Javadoc)
202
	 * @see org.eclipse.jface.viewers.deferred.AbstractConcurrentModel#removeListener(org.eclipse.jface.viewers.deferred.IConcurrentModelListener)
203
	 */
204
	public void removeListener(IConcurrentModelListener listener) {
205
		super.removeListener(listener);
206
		// If this listener is waiting for a refresh, cancel it
207
        synchronized(awaitingRefresh) {
208
            awaitingRefresh.remove(listener);
209
        }
210
211
	}
212
    
213
    /* (non-Javadoc)
214
     * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#requestUpdate(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
215
     */
216
    public void requestUpdate(IConcurrentModelListener listener) {
217
        synchronized(awaitingRefresh) {
218
        	if (!awaitingRefresh.contains(listener)) {
219
	            awaitingRefresh.add(listener);
220
	            // Ensure we don't reschedule the refresh job if it's already running
221
	            if (!refreshScheduled) {
222
	            	refreshScheduled = true;
223
	                searchJob.schedule();	
224
	            }
225
        	}
226
        }
227
    }
228
}

Return to bug 60117