001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.views.markers.internal;
011:
012: import org.eclipse.core.resources.IMarker;
013: import org.eclipse.osgi.util.NLS;
014: import org.eclipse.swt.graphics.Image;
015: import org.eclipse.ui.model.IWorkbenchAdapter;
016:
017: /**
018: * FieldLineNumber is the field for line numbers.
019: *
020: */
021: public class FieldLineNumber extends AbstractField {
022:
023: private String description;
024:
025: private Image image;
026:
027: /**
028: * Create a new instance of the receiver.
029: */
030: public FieldLineNumber() {
031: description = MarkerMessages.description_lineNumber;
032: }
033:
034: /*
035: * (non-Javadoc)
036: * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
037: */
038: public String getDescription() {
039: return description;
040: }
041:
042: /*
043: * (non-Javadoc)
044: * @see org.eclipse.ui.views.markers.internal.IField#getDescriptionImage()
045: */
046: public Image getDescriptionImage() {
047: return image;
048: }
049:
050: /*
051: * (non-Javadoc)
052: * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderText()
053: */
054: public String getColumnHeaderText() {
055: return description;
056: }
057:
058: /*
059: * (non-Javadoc)
060: * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
061: */
062: public Image getColumnHeaderImage() {
063: return image;
064: }
065:
066: /*
067: * (non-Javadoc)
068: * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
069: */
070: public String getValue(Object obj) {
071: if (obj == null) {
072: return MarkerMessages.FieldMessage_NullMessage;
073: }
074:
075: if (obj instanceof MarkerNode) {
076: MarkerNode node = (MarkerNode) obj;
077: if (node.isConcrete()) {
078: ConcreteMarker concreteNode = (ConcreteMarker) node;
079: if (concreteNode.getLocationString().length() == 0) {
080: if (concreteNode.getLine() < 0) {
081: return MarkerMessages.Unknown;
082: }
083: return NLS.bind(MarkerMessages.label_lineNumber,
084: Integer.toString(concreteNode.getLine()));
085: }
086: return concreteNode.getLocationString();
087: }
088: return Util.EMPTY_STRING;
089: }
090:
091: if (obj instanceof IWorkbenchAdapter) {
092: return Util.EMPTY_STRING;//Don't show pending
093: }
094:
095: if (obj instanceof IMarker) {
096: return Util.getProperty(IMarker.LINE_NUMBER, (IMarker) obj);
097: }
098:
099: return NLS.bind(MarkerMessages.FieldMessage_WrongType, obj
100: .toString());
101:
102: }
103:
104: /*
105: * (non-Javadoc)
106: * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
107: */
108: public Image getImage(Object obj) {
109: return null;
110: }
111:
112: /*
113: * (non-Javadoc)
114: * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
115: */
116: public int compare(Object obj1, Object obj2) {
117: if (obj1 == null || obj2 == null
118: || !(obj1 instanceof ConcreteMarker)
119: || !(obj2 instanceof ConcreteMarker)) {
120: return 0;
121: }
122:
123: ConcreteMarker marker1 = (ConcreteMarker) obj1;
124: ConcreteMarker marker2 = (ConcreteMarker) obj2;
125:
126: String location1 = marker1.getLocationString();
127: String location2 = marker2.getLocationString();
128:
129: if (location1.length() == 0 || location2.length() == 0) {
130: return marker1.getLine() - marker2.getLine();
131: }
132:
133: return location1.compareTo(location2);
134: }
135:
136: /* (non-Javadoc)
137: * @see org.eclipse.ui.views.markers.internal.IField#getDefaultDirection()
138: */
139: public int getDefaultDirection() {
140: return TableComparator.ASCENDING;
141: }
142:
143: /* (non-Javadoc)
144: * @see org.eclipse.ui.views.markers.internal.IField#getPreferredWidth()
145: */
146: public int getPreferredWidth() {
147: return 60;
148: }
149: }
|