1 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 TAG_CONTAINS = "contains"; 22 private static final String TAG_DESCRIPTION = "description"; 24 private static final String TAG_DONE = "done"; 26 private static final String TAG_PRIORITY = "priority"; 28 private static final String TAG_SELECT_BY_DONE = "selectByDone"; 30 private static final String TAG_SELECT_BY_PRIORITY = "selectByPriority"; 32 final static boolean DEFAULT_CONTAINS = true; 33 34 final static String DEFAULT_DESCRIPTION = ""; 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 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 66 public TaskFilter() { 67 this(MarkerMessages.MarkerFilter_defaultFilterName); 68 } 69 70 75 public TaskFilter(String newName) { 76 super(newName, new String [] { 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("")) { 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 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 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 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 191 public void restoreFilterSettings(IDialogSettings settings) { 192 super.restoreFilterSettings(settings); 193 194 String 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 (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 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 238 protected void restoreFilterSettings(IMemento settings) { 239 super.restoreFilterSettings(settings); 240 241 String 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 (setting); 251 } 252 253 setting = settings.getString(TAG_DONE); 254 255 if (setting != null) { 256 done = Boolean.valueOf(setting).booleanValue(); 257 } 258 259 Integer 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 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 |