1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.ui.model.IWorkbenchAdapter; 18 19 23 public class FieldLineNumber extends AbstractField { 24 25 private String description; 26 27 private Image image; 28 29 32 public FieldLineNumber() { 33 description = MarkerMessages.description_lineNumber; 34 } 35 36 40 public String getDescription() { 41 return description; 42 } 43 44 48 public Image getDescriptionImage() { 49 return image; 50 } 51 52 56 public String getColumnHeaderText() { 57 return description; 58 } 59 60 64 public Image getColumnHeaderImage() { 65 return image; 66 } 67 68 72 public String getValue(Object obj) { 73 if (obj == null) { 74 return MarkerMessages.FieldMessage_NullMessage; 75 } 76 77 if (obj instanceof MarkerNode){ 78 MarkerNode node = (MarkerNode) obj; 79 if(node.isConcrete()){ 80 ConcreteMarker concreteNode = (ConcreteMarker) node; 81 if(concreteNode.getLocationString().length() == 0){ 82 if (concreteNode.getLine() < 0) { 83 return MarkerMessages.Unknown; 84 } 85 return NLS.bind( 86 MarkerMessages.label_lineNumber, 87 Integer.toString(concreteNode.getLine())); 88 } 89 return concreteNode.getLocationString(); 90 } 91 return Util.EMPTY_STRING; 92 } 93 94 if(obj instanceof IWorkbenchAdapter) { 95 return Util.EMPTY_STRING; } 97 98 if(obj instanceof IMarker) { 99 return Util.getProperty(IMarker.LINE_NUMBER, (IMarker) obj); 100 } 101 102 return NLS.bind(MarkerMessages.FieldMessage_WrongType,obj.toString()); 103 104 } 105 106 110 public Image getImage(Object obj) { 111 return null; 112 } 113 114 118 public int compare(Object obj1, Object obj2) { 119 if (obj1 == null || obj2 == null || !(obj1 instanceof ConcreteMarker) 120 || !(obj2 instanceof ConcreteMarker)) { 121 return 0; 122 } 123 124 ConcreteMarker marker1 = (ConcreteMarker) obj1; 125 ConcreteMarker marker2 = (ConcreteMarker) obj2; 126 127 String location1 = marker1.getLocationString(); 128 String location2 = marker2.getLocationString(); 129 130 if(location1.length() == 0 || location2.length() == 0) { 131 return marker1.getLine() - marker2.getLine(); 132 } 133 134 return location1.compareTo(location2); 135 } 136 137 140 public int getDefaultDirection() { 141 return TableComparator.ASCENDING; 142 } 143 144 147 public int getPreferredWidth() { 148 return 60; 149 } 150 } 151 | Popular Tags |