1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.jface.resource.JFaceResources; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 18 19 24 public class FieldPriority extends AbstractField { 25 26 static final String DESCRIPTION_IMAGE_PATH = "obj16/header_priority.gif"; 28 static final String HIGH_PRIORITY_IMAGE_PATH = "obj16/hprio_tsk.gif"; 30 static final String LOW_PRIORITY_IMAGE_PATH = "obj16/lprio_tsk.gif"; 32 private String description; 33 34 37 public FieldPriority() { 38 description = MarkerMessages.priority_description; 39 } 40 41 45 public String getDescription() { 46 return description; 47 } 48 49 54 private Image getImage(String path){ 55 return JFaceResources.getResources().createImageWithDefault( 56 IDEWorkbenchPlugin 57 .getIDEImageDescriptor(path)); 58 59 } 60 61 65 public Image getDescriptionImage() { 66 return getImage(DESCRIPTION_IMAGE_PATH); 67 } 68 69 73 public String getColumnHeaderText() { 74 return ""; } 76 77 81 public Image getColumnHeaderImage() { 82 return getDescriptionImage(); 83 } 84 85 89 public String getValue(Object obj) { 90 return ""; } 92 93 97 public Image getImage(Object obj) { 98 if (obj == null || !(obj instanceof TaskMarker)) { 99 return null; 100 } 101 try { 102 int priority = ((TaskMarker) obj).getPriority(); 103 if (priority == IMarker.PRIORITY_HIGH) { 104 return getImage(HIGH_PRIORITY_IMAGE_PATH); 105 } 106 if (priority == IMarker.PRIORITY_LOW) { 107 return getImage(LOW_PRIORITY_IMAGE_PATH); 108 } 109 } catch (NumberFormatException e) { 110 return null; 111 } 112 return null; 113 } 114 115 119 public int compare(Object obj1, Object obj2) { 120 if (obj1 == null || obj2 == null || !(obj1 instanceof TaskMarker) 121 || !(obj2 instanceof TaskMarker)) { 122 return 0; 123 } 124 int priority1 = ((TaskMarker) obj1).getPriority(); 125 int priority2 = ((TaskMarker) obj2).getPriority(); 126 return priority1 - priority2; 127 } 128 129 132 public int getDefaultDirection() { 133 return TableComparator.DESCENDING; 134 } 135 136 139 public int getPreferredWidth() { 140 return 16; 141 } 142 } 143 | Popular Tags |