001: /*******************************************************************************
002: * Copyright (c) 2003, 2007 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.internal.progress;
011:
012: import java.util.Date;
013:
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.jobs.Job;
016: import org.eclipse.jface.resource.JFaceResources;
017: import org.eclipse.osgi.util.NLS;
018: import org.eclipse.swt.graphics.Image;
019:
020: import com.ibm.icu.text.DateFormat;
021:
022: /**
023: * ErrorInfo is the info that displays errors.
024: */
025: public class ErrorInfo extends JobTreeElement {
026:
027: private final IStatus errorStatus;
028:
029: private final Job job;
030:
031: private final long timestamp;
032:
033: /**
034: * Create a new instance of the receiver.
035: *
036: * @param status
037: * @param job
038: * The Job to create
039: */
040: public ErrorInfo(IStatus status, Job job) {
041: errorStatus = status;
042: this .job = job;
043: timestamp = System.currentTimeMillis();
044: }
045:
046: /*
047: * (non-Javadoc)
048: *
049: * @see org.eclipse.ui.internal.progress.JobTreeElement#getParent()
050: */
051: Object getParent() {
052: return null;
053: }
054:
055: /*
056: * (non-Javadoc)
057: *
058: * @see org.eclipse.ui.internal.progress.JobTreeElement#hasChildren()
059: */
060: boolean hasChildren() {
061: return false;
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see org.eclipse.ui.internal.progress.JobTreeElement#getChildren()
068: */
069: Object[] getChildren() {
070: return ProgressManagerUtil.EMPTY_OBJECT_ARRAY;
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * @see org.eclipse.ui.internal.progress.JobTreeElement#getDisplayString()
077: */
078: String getDisplayString() {
079: return NLS
080: .bind(ProgressMessages.JobInfo_Error, (new Object[] {
081: job.getName(),
082: DateFormat.getDateTimeInstance(DateFormat.LONG,
083: DateFormat.LONG).format(
084: new Date(timestamp)) }));
085: }
086:
087: /**
088: * Return the image for the receiver.
089: *
090: * @return Image
091: */
092: Image getImage() {
093: return JFaceResources.getImage(ProgressManager.ERROR_JOB_KEY);
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see org.eclipse.ui.internal.progress.JobTreeElement#isJobInfo()
100: */
101: boolean isJobInfo() {
102: return false;
103: }
104:
105: /**
106: * Return the current status of the receiver.
107: *
108: * @return IStatus
109: */
110: IStatus getErrorStatus() {
111: return errorStatus;
112: }
113:
114: /*
115: * (non-Javadoc)
116: *
117: * @see org.eclipse.ui.internal.progress.JobTreeElement#isActive()
118: */
119: boolean isActive() {
120: return true;
121: }
122:
123: /**
124: * Return the job that generated the error.
125: *
126: * @return the job that generated the error
127: */
128: public Job getJob() {
129: return job;
130: }
131:
132: /**
133: * Return the timestamp for the job.
134: *
135: * @return long
136: */
137: public long getTimestamp() {
138: return timestamp;
139: }
140:
141: /*
142: * (non-Javadoc)
143: *
144: * @see org.eclipse.ui.internal.progress.JobTreeElement#compareTo(java.lang.Object)
145: */
146: public int compareTo(Object arg0) {
147: if (arg0 instanceof ErrorInfo) {
148: // Order ErrorInfo by time received
149: long otherTimestamp = ((ErrorInfo) arg0).timestamp;
150: if (timestamp < otherTimestamp) {
151: return -1;
152: } else if (timestamp > otherTimestamp) {
153: return 1;
154: } else {
155: return 0;
156: }
157: }
158: return super.compareTo(arg0);
159: }
160: }
|