1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.jface.dialogs.IDialogSettings; 17 import org.eclipse.ui.IMemento; 18 import org.eclipse.ui.IPluginContribution; 19 import org.eclipse.ui.IWorkbenchPage; 20 import org.eclipse.ui.IWorkbenchPreferenceConstants; 21 import org.eclipse.ui.IWorkbenchWindow; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.activities.IIdentifier; 24 import org.eclipse.ui.activities.WorkbenchActivityHelper; 25 26 30 public class ProblemFilter extends MarkerFilter { 31 32 private static final String TAG_CONTAINS = "contains"; 34 private static final String TAG_DESCRIPTION = "description"; 36 private static final String TAG_SELECT_BY_SEVERITY = "selectBySeverity"; 38 private static final String TAG_SEVERITY = "severity"; 40 final static boolean DEFAULT_CONTAINS = true; 41 42 final static String DEFAULT_DESCRIPTION = ""; 44 final static boolean DEFAULT_SELECT_BY_SEVERITY = false; 45 46 final static int DEFAULT_SEVERITY = 0; 47 48 51 public final static int SEVERITY_ERROR = 1 << 2; 52 53 56 public final static int SEVERITY_WARNING = 1 << 1; 57 58 61 public final static int SEVERITY_INFO = 1 << 0; 62 63 private boolean contains; 64 65 private String description; 66 67 private boolean selectBySeverity; 68 69 private int severity; 70 71 private IPluginContribution contributionDescriptor = null; 72 73 private IIdentifier identifier; 74 75 81 public ProblemFilter(String filterName) { 82 super(filterName, new String [] { IMarker.PROBLEM }); 83 if ((PlatformUI.getPreferenceStore() 84 .getBoolean(IWorkbenchPreferenceConstants.USE_WINDOW_WORKING_SET_BY_DEFAULT))) { 85 IWorkbenchWindow window = PlatformUI.getWorkbench() 86 .getActiveWorkbenchWindow(); 87 if (window != null) { 88 IWorkbenchPage page = window.getActivePage(); 89 if (page != null) { 90 setOnResource(MarkerFilter.ON_WORKING_SET); 91 setWorkingSet(page.getAggregateWorkingSet()); 92 } 93 } 94 } 95 96 } 97 98 public boolean selectMarker(ConcreteMarker marker) { 99 if (!(marker instanceof ProblemMarker)) { 100 return false; 101 } 102 103 ProblemMarker problemMarker = (ProblemMarker) marker; 104 105 return !isEnabled() 106 || (super.selectMarker(problemMarker) 107 && selectByDescription(problemMarker) && selectBySeverity(problemMarker)); 108 } 109 110 private boolean selectByDescription(ConcreteMarker item) { 111 if (description == null || description.equals("")) { return true; 113 } 114 115 String markerDescription = item.getDescription(); 116 int index = markerDescription.indexOf(description); 117 return contains ? (index >= 0) : (index < 0); 118 } 119 120 private boolean selectBySeverity(ProblemMarker item) { 121 if (selectBySeverity) { 122 int markerSeverity = item.getSeverity(); 123 124 if (markerSeverity == IMarker.SEVERITY_ERROR) { 125 return (severity & SEVERITY_ERROR) > 0; 126 } else if (markerSeverity == IMarker.SEVERITY_WARNING) { 127 return (severity & SEVERITY_WARNING) > 0; 128 } else if (markerSeverity == IMarker.SEVERITY_INFO) { 129 return (severity & SEVERITY_INFO) > 0; 130 } 131 } 132 133 return true; 134 } 135 136 141 public boolean getContains() { 142 return contains; 143 } 144 145 150 public String getDescription() { 151 return description; 152 } 153 154 159 public boolean getSelectBySeverity() { 160 return selectBySeverity; 161 } 162 163 168 public int getSeverity() { 169 return severity; 170 } 171 172 177 public void setContains(boolean contains) { 178 this.contains = contains; 179 } 180 181 186 public void setDescription(String description) { 187 this.description = description; 188 } 189 190 195 public void setSelectBySeverity(boolean selectBySeverity) { 196 this.selectBySeverity = selectBySeverity; 197 } 198 199 204 public void setSeverity(int severity) { 205 this.severity = severity; 206 } 207 208 213 public void resetState() { 214 super.resetState(); 215 contains = DEFAULT_CONTAINS; 216 description = DEFAULT_DESCRIPTION; 217 selectBySeverity = DEFAULT_SELECT_BY_SEVERITY; 218 severity = DEFAULT_SEVERITY; 219 } 220 221 226 public void restoreFilterSettings(IDialogSettings settings) { 227 228 super.restoreFilterSettings(settings); 229 230 String setting = settings.get(TAG_CONTAINS); 231 232 if (setting != null) { 233 contains = Boolean.valueOf(setting).booleanValue(); 234 } 235 236 setting = settings.get(TAG_DESCRIPTION); 237 238 if (setting != null) { 239 description = new String (setting); 240 } 241 242 setting = settings.get(TAG_SELECT_BY_SEVERITY); 243 244 if (setting != null) { 245 selectBySeverity = Boolean.valueOf(setting).booleanValue(); 246 } 247 248 setting = settings.get(TAG_SEVERITY); 249 250 if (setting != null) { 251 try { 252 severity = Integer.parseInt(setting); 253 } catch (NumberFormatException eNumberFormat) { 254 } 255 } 256 257 } 258 259 264 protected void restoreFilterSettings(IMemento memento) { 265 266 super.restoreFilterSettings(memento); 267 268 String setting = memento.getString(TAG_CONTAINS); 269 270 if (setting != null) { 271 contains = Boolean.valueOf(setting).booleanValue(); 272 } 273 274 setting = memento.getString(TAG_DESCRIPTION); 275 276 if (setting != null) { 277 description = new String (setting); 278 } 279 280 setting = memento.getString(TAG_SELECT_BY_SEVERITY); 281 282 if (setting != null) { 283 selectBySeverity = Boolean.valueOf(setting).booleanValue(); 284 } 285 286 Integer severitySetting = memento.getInteger(TAG_SEVERITY); 287 288 if (setting != null) { 289 severity = severitySetting.intValue(); 290 } 291 } 292 293 298 public void saveFilterSettings(IMemento settings) { 299 super.saveFilterSettings(settings); 300 settings.putString(TAG_CONTAINS, String.valueOf(contains)); 301 settings.putString(TAG_DESCRIPTION, description); 302 settings.putString(TAG_SELECT_BY_SEVERITY, String 303 .valueOf(selectBySeverity)); 304 settings.putInteger(TAG_SEVERITY, severity); 305 306 } 307 308 314 public String getId() { 315 if (contributionDescriptor == null) { 316 return null; 317 } 318 return contributionDescriptor.getLocalId(); 319 } 320 321 void createContributionFrom(IConfigurationElement element) { 322 final String id = element.getAttribute(MarkerSupportRegistry.ID); 323 final String namespace = element.getNamespace(); 324 contributionDescriptor = new IPluginContribution() { 325 330 public String getLocalId() { 331 return id; 332 } 333 334 339 public String getPluginId() { 340 return namespace; 341 } 342 }; 343 } 344 345 351 public boolean isFilteredOutByActivity() { 352 if (contributionDescriptor == null) { 353 return false; 354 } 355 if (identifier == null) { 356 identifier = WorkbenchActivityHelper 357 .getIdentifier(contributionDescriptor); 358 } 359 return !identifier.isEnabled(); 360 } 361 362 public boolean isEnabled() { 363 return super.isEnabled() && !isFilteredOutByActivity(); 364 } 365 366 } 367 | Popular Tags |