KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > progress > ErrorInfo


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.progress;
12
13 import java.util.Date JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.jobs.Job;
17 import org.eclipse.jface.resource.JFaceResources;
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.swt.graphics.Image;
20
21 import com.ibm.icu.text.DateFormat;
22
23 /**
24  * ErrorInfo is the info that displays errors.
25  */

26 public class ErrorInfo extends JobTreeElement {
27
28     private final IStatus errorStatus;
29
30     private final Job job;
31
32     private final long timestamp;
33
34     /**
35      * Create a new instance of the receiver.
36      *
37      * @param status
38      * @param job
39      * The Job to create
40      */

41     public ErrorInfo(IStatus status, Job job) {
42         errorStatus = status;
43         this.job = job;
44         timestamp = System.currentTimeMillis();
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see org.eclipse.ui.internal.progress.JobTreeElement#getParent()
51      */

52     Object JavaDoc getParent() {
53         return null;
54     }
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.eclipse.ui.internal.progress.JobTreeElement#hasChildren()
60      */

61     boolean hasChildren() {
62         return false;
63     }
64
65     /*
66      * (non-Javadoc)
67      *
68      * @see org.eclipse.ui.internal.progress.JobTreeElement#getChildren()
69      */

70     Object JavaDoc[] getChildren() {
71         return ProgressManagerUtil.EMPTY_OBJECT_ARRAY;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.ui.internal.progress.JobTreeElement#getDisplayString()
78      */

79     String JavaDoc getDisplayString() {
80         return NLS.bind(ProgressMessages.JobInfo_Error, (new Object JavaDoc[] {
81                 job.getName(),
82                 DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG).format(new Date JavaDoc(timestamp)) }));
83     }
84
85     /**
86      * Return the image for the receiver.
87      *
88      * @return Image
89      */

90     Image getImage() {
91         return JFaceResources.getImage(ProgressManager.ERROR_JOB_KEY);
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.eclipse.ui.internal.progress.JobTreeElement#isJobInfo()
98      */

99     boolean isJobInfo() {
100         return false;
101     }
102
103     /**
104      * Return the current status of the receiver.
105      *
106      * @return IStatus
107      */

108     IStatus getErrorStatus() {
109         return errorStatus;
110     }
111
112     /*
113      * (non-Javadoc)
114      *
115      * @see org.eclipse.ui.internal.progress.JobTreeElement#isActive()
116      */

117     boolean isActive() {
118         return true;
119     }
120
121     /**
122      * Return the job that generated the error.
123      *
124      * @return the job that generated the error
125      */

126     public Job getJob() {
127         return job;
128     }
129
130     /**
131      * Return the timestamp for the job.
132      *
133      * @return long
134      */

135     public long getTimestamp() {
136         return timestamp;
137     }
138
139     /*
140      * (non-Javadoc)
141      *
142      * @see org.eclipse.ui.internal.progress.JobTreeElement#compareTo(java.lang.Object)
143      */

144     public int compareTo(Object JavaDoc arg0) {
145         if (arg0 instanceof ErrorInfo) {
146             // Order ErrorInfo by time received
147
long otherTimestamp = ((ErrorInfo) arg0).timestamp;
148             if (timestamp < otherTimestamp) {
149                 return -1;
150             } else if (timestamp > otherTimestamp) {
151                 return 1;
152             } else {
153                 return 0;
154             }
155         }
156         return super.compareTo(arg0);
157     }
158 }
159
Popular Tags