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.swt.graphics.Image;
013:
014: /**
015: * Creation time field. Designed to display and compare creation times of IMarker objects.
016: */
017: public class FieldCreationTime extends AbstractField {
018:
019: private String description;
020:
021: private Image image;
022:
023: /**
024: * The constructor
025: */
026: public FieldCreationTime() {
027: description = MarkerMessages.description_creationTime;
028: }
029:
030: /*
031: * (non-Javadoc)
032: * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
033: */
034: public String getDescription() {
035: return description;
036: }
037:
038: /*
039: * (non-Javadoc)
040: * @see org.eclipse.ui.views.markers.internal.IField#getDescriptionImage()
041: */
042: public Image getDescriptionImage() {
043: return image;
044: }
045:
046: /*
047: * (non-Javadoc)
048: * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderText()
049: */
050: public String getColumnHeaderText() {
051: return description;
052: }
053:
054: /*
055: * (non-Javadoc)
056: * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
057: */
058: public Image getColumnHeaderImage() {
059: return image;
060: }
061:
062: /*
063: * (non-Javadoc)
064: * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
065: */
066: public String getValue(Object obj) {
067: if (obj == null || !(obj instanceof ConcreteMarker)) {
068: return ""; //$NON-NLS-1$
069: }
070: ConcreteMarker marker = (ConcreteMarker) obj;
071: return String.valueOf(marker.getCreationTime());
072: }
073:
074: /*
075: * (non-Javadoc)
076: * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
077: */
078: public Image getImage(Object obj) {
079: return null;
080: }
081:
082: /*
083: * (non-Javadoc)
084: * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
085: */
086: public int compare(Object obj1, Object obj2) {
087: if (obj1 == null || obj2 == null
088: || !(obj1 instanceof ConcreteMarker)
089: || !(obj2 instanceof ConcreteMarker)) {
090: return 0;
091: }
092:
093: ConcreteMarker marker1 = (ConcreteMarker) obj1;
094: ConcreteMarker marker2 = (ConcreteMarker) obj2;
095:
096: long value = marker1.getCreationTime()
097: - marker2.getCreationTime();
098: if (value < 0) {
099: return -1;
100: } else if (value > 0) {
101: return 1;
102: } else {
103: return 0;
104: }
105: }
106:
107: /* (non-Javadoc)
108: * @see org.eclipse.ui.views.markers.internal.IField#getDefaultDirection()
109: */
110: public int getDefaultDirection() {
111: return TableComparator.ASCENDING;
112: }
113:
114: /* (non-Javadoc)
115: * @see org.eclipse.ui.views.markers.internal.IField#getPreferredWidth()
116: */
117: public int getPreferredWidth() {
118: return 0;
119: }
120: }
|