1 11 12 package org.eclipse.ui.internal.ide.model; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.ui.IMarkerActionFilter; 19 import org.eclipse.ui.actions.SimpleWildcardTester; 20 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 21 import org.eclipse.ui.model.WorkbenchAdapter; 22 23 27 public class WorkbenchMarker extends WorkbenchAdapter implements 28 IMarkerActionFilter { 29 33 public ImageDescriptor getImageDescriptor(Object o) { 34 if (!(o instanceof IMarker)) { 35 return null; 36 } 37 return IDEWorkbenchPlugin.getDefault().getMarkerImageProviderRegistry() 38 .getImageDescriptor((IMarker) o); 39 } 40 41 45 public String getLabel(Object o) { 46 IMarker marker = (IMarker) o; 47 return marker.getAttribute(IMarker.MESSAGE, ""); } 49 50 54 public Object getParent(Object o) { 55 return ((IMarker) o).getResource(); 56 } 57 58 67 public boolean testAttribute(Object target, String name, String value) { 68 IMarker marker = (IMarker) target; 69 if (name.equals(TYPE)) { 70 try { 71 return value.equals(marker.getType()); 72 } catch (CoreException e) { 73 return false; 74 } 75 } else if (name.equals(SUPER_TYPE)) { 76 try { 77 return marker.isSubtypeOf(value); 78 } catch (CoreException e) { 79 return false; 80 } 81 } else if (name.equals(PRIORITY)) { 82 return testIntegerAttribute(marker, IMarker.PRIORITY, value); 83 } else if (name.equals(SEVERITY)) { 84 return testIntegerAttribute(marker, IMarker.SEVERITY, value); 85 } else if (name.equals(MESSAGE)) { 86 try { 87 String msg = (String ) marker.getAttribute(IMarker.MESSAGE); 88 if (msg == null) { 89 return false; 90 } 91 return SimpleWildcardTester.testWildcardIgnoreCase(value, msg); 92 } catch (CoreException e) { 93 return false; 94 } 95 } else if (name.equals(DONE)) { 96 try { 97 value = value.toLowerCase(); 98 Boolean done = (Boolean ) marker.getAttribute(IMarker.DONE); 99 if (done == null) { 100 return false; 101 } 102 return (done.booleanValue() == value.equals("true")); } catch (CoreException e) { 104 return false; 105 } 106 } else if (name.equals(RESOURCE_TYPE)) { 107 int desiredType = 0; 108 109 try { 110 desiredType = Integer.parseInt(value); 111 } catch (NumberFormatException eNumberFormat) { 112 } 113 114 if (!(desiredType == IResource.FILE 115 || desiredType == IResource.FOLDER 116 || desiredType == IResource.PROJECT || desiredType == IResource.ROOT)) { 117 return false; 118 } 119 120 return (marker.getResource().getType() & desiredType) > 0; 121 } 122 return false; 123 } 124 125 128 private boolean testIntegerAttribute(IMarker marker, String attrName, 129 String value) { 130 Integer i1, i2; 131 try { 132 i1 = (Integer ) marker.getAttribute(attrName); 133 if (i1 == null) { 134 return false; 135 } 136 } catch (CoreException e) { 137 return false; 138 } 139 try { 140 i2 = Integer.valueOf(value); 141 } catch (NumberFormatException e) { 142 return false; 143 } 144 return i1.equals(i2); 145 } 146 } 147 | Popular Tags |