KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > TaskFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.markers.internal;
13
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.jface.dialogs.IDialogSettings;
16 import org.eclipse.ui.IMemento;
17
18 public class TaskFilter extends MarkerFilter {
19
20     private static final String JavaDoc TAG_CONTAINS = "contains"; //$NON-NLS-1$
21

22     private static final String JavaDoc TAG_DESCRIPTION = "description"; //$NON-NLS-1$
23

24     private static final String JavaDoc TAG_DONE = "done"; //$NON-NLS-1$
25

26     private static final String JavaDoc TAG_PRIORITY = "priority"; //$NON-NLS-1$
27

28     private static final String JavaDoc TAG_SELECT_BY_DONE = "selectByDone"; //$NON-NLS-1$
29

30     private static final String JavaDoc TAG_SELECT_BY_PRIORITY = "selectByPriority"; //$NON-NLS-1$
31

32     final static boolean DEFAULT_CONTAINS = true;
33
34     final static String JavaDoc DEFAULT_DESCRIPTION = ""; //$NON-NLS-1$
35

36     final static boolean DEFAULT_DONE = false;
37
38     final static int DEFAULT_PRIORITY = 0;
39
40     final static boolean DEFAULT_SELECT_BY_DONE = false;
41
42     final static boolean DEFAULT_SELECT_BY_PRIORITY = false;
43
44     final static int PRIORITY_HIGH = 1 << 2;
45
46     final static int PRIORITY_NORMAL = 1 << 1;
47
48     final static int PRIORITY_LOW = 1 << 0;
49
50     private boolean contains;
51
52     private String JavaDoc description;
53
54     private boolean done;
55
56     private int priority;
57
58     private boolean selectByPriority = false;
59
60     private boolean selectByDone = false;
61
62     /**
63      * Create a new instance of the receiver with the default name.
64      *
65      */

66     public TaskFilter() {
67         this(MarkerMessages.MarkerFilter_defaultFilterName);
68     }
69
70     /**
71      * Create a new instance of the receiver with the supplied name.
72      *
73      * @param newName
74      */

75     public TaskFilter(String JavaDoc newName) {
76         super(newName, new String JavaDoc[] { IMarker.TASK });
77     }
78
79     public boolean selectMarker(ConcreteMarker marker) {
80         if (!(marker instanceof TaskMarker)) {
81             return false;
82         }
83
84         TaskMarker taskMarker = (TaskMarker) marker;
85
86         return !isEnabled()
87                 || (super.selectMarker(taskMarker)
88                         && selectByDescription(taskMarker)
89                         && selectByDone(taskMarker) && selectByPriority(taskMarker));
90     }
91
92     private boolean selectByDescription(ConcreteMarker marker) {
93         if (description == null || description.equals("")) { //$NON-NLS-1$
94
return true;
95         }
96
97         int index = marker.getDescription().indexOf(description);
98         return contains ? (index >= 0) : (index < 0);
99     }
100
101     private boolean selectByDone(TaskMarker item) {
102         if (selectByDone) {
103             return done == (item.getDone() == 1);
104         }
105
106         return true;
107     }
108
109     private boolean selectByPriority(TaskMarker marker) {
110         if (priority != 0 && selectByPriority) {
111             int markerPriority = marker.getPriority();
112
113             if (markerPriority == IMarker.PRIORITY_HIGH) {
114                 return (priority & PRIORITY_HIGH) > 0;
115             } else if (markerPriority == IMarker.PRIORITY_NORMAL) {
116                 return (priority & PRIORITY_NORMAL) > 0;
117             } else if (markerPriority == IMarker.PRIORITY_LOW) {
118                 return (priority & PRIORITY_LOW) > 0;
119             }
120         }
121
122         return true;
123     }
124
125     public boolean getContains() {
126         return contains;
127     }
128
129     public String JavaDoc getDescription() {
130         return description;
131     }
132
133     public boolean getDone() {
134         return done;
135     }
136
137     public int getPriority() {
138         return priority;
139     }
140
141     public boolean getSelectByDone() {
142         return selectByDone;
143     }
144
145     public boolean getSelectByPriority() {
146         return selectByPriority;
147     }
148
149     public void setContains(boolean contains) {
150         this.contains = contains;
151     }
152
153     public void setDescription(String JavaDoc description) {
154         this.description = description;
155     }
156
157     public void setDone(boolean done) {
158         this.done = done;
159     }
160
161     public void setPriority(int priority) {
162         this.priority = priority;
163     }
164
165     public void setSelectByDone(boolean selectByDone) {
166         this.selectByDone = selectByDone;
167     }
168
169     public void setSelectByPriority(boolean selectByPriority) {
170         this.selectByPriority = selectByPriority;
171     }
172
173     /* (non-Javadoc)
174      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#resetState()
175      */

176     public void resetState() {
177         super.resetState();
178         contains = DEFAULT_CONTAINS;
179         description = DEFAULT_DESCRIPTION;
180         done = DEFAULT_DONE;
181         priority = DEFAULT_PRIORITY;
182         selectByDone = DEFAULT_SELECT_BY_DONE;
183         selectByPriority = DEFAULT_SELECT_BY_PRIORITY;
184     }
185
186     /*
187      * (non-Javadoc)
188      *
189      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#restoreFilterSettings(org.eclipse.jface.dialogs.IDialogSettings)
190      */

191     public void restoreFilterSettings(IDialogSettings settings) {
192         super.restoreFilterSettings(settings);
193
194         String JavaDoc setting = settings.get(TAG_CONTAINS);
195
196         if (setting != null) {
197             contains = Boolean.valueOf(setting).booleanValue();
198         }
199
200         setting = settings.get(TAG_DESCRIPTION);
201
202         if (setting != null) {
203             description = new String JavaDoc(setting);
204         }
205
206         setting = settings.get(TAG_DONE);
207
208         if (setting != null) {
209             done = Boolean.valueOf(setting).booleanValue();
210         }
211
212         setting = settings.get(TAG_PRIORITY);
213
214         if (setting != null) {
215             try {
216                 priority = Integer.parseInt(setting);
217             } catch (NumberFormatException JavaDoc eNumberFormat) {
218             }
219         }
220
221         setting = settings.get(TAG_SELECT_BY_DONE);
222
223         if (setting != null) {
224             selectByDone = Boolean.valueOf(setting).booleanValue();
225         }
226
227         setting = settings.get(TAG_SELECT_BY_PRIORITY);
228
229         if (setting != null) {
230             selectByPriority = Boolean.valueOf(setting).booleanValue();
231         }
232
233     }
234     
235     /* (non-Javadoc)
236      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#restoreFilterSettings(org.eclipse.ui.IMemento)
237      */

238     protected void restoreFilterSettings(IMemento settings) {
239         super.restoreFilterSettings(settings);
240
241         String JavaDoc setting = settings.getString(TAG_CONTAINS);
242
243         if (setting != null) {
244             contains = Boolean.valueOf(setting).booleanValue();
245         }
246
247         setting = settings.getString(TAG_DESCRIPTION);
248
249         if (setting != null) {
250             description = new String JavaDoc(setting);
251         }
252
253         setting = settings.getString(TAG_DONE);
254
255         if (setting != null) {
256             done = Boolean.valueOf(setting).booleanValue();
257         }
258
259         Integer JavaDoc priorityValue = settings.getInteger(TAG_PRIORITY);
260
261         if (setting != null) {
262             priority = priorityValue.intValue();
263         }
264
265         setting = settings.getString(TAG_SELECT_BY_DONE);
266
267         if (setting != null) {
268             selectByDone = Boolean.valueOf(setting).booleanValue();
269         }
270
271         setting = settings.getString(TAG_SELECT_BY_PRIORITY);
272
273         if (setting != null) {
274             selectByPriority = Boolean.valueOf(setting).booleanValue();
275         }
276
277     }
278
279     
280     /* (non-Javadoc)
281      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#saveFilterSettings(org.eclipse.ui.IMemento)
282      */

283     public void saveFilterSettings(IMemento settings) {
284         super.saveFilterSettings(settings);
285         settings.putString(TAG_CONTAINS, String.valueOf(contains));
286         settings.putString(TAG_DESCRIPTION, description);
287         settings.putString(TAG_DONE, String.valueOf(done));
288         settings.putInteger(TAG_PRIORITY, priority);
289         settings.putString(TAG_SELECT_BY_DONE, String.valueOf(selectByDone));
290         settings.putString(TAG_SELECT_BY_PRIORITY, String.valueOf(selectByPriority));
291
292     }
293
294 }
295
Popular Tags