KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > dialogs > StatusInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.dialogs;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IStatus;
15
16
17 import org.eclipse.jdt.ui.JavaUI;
18
19 /**
20  * A settable IStatus.
21  * Can be an error, warning, info or ok. For error, info and warning states,
22  * a message describes the problem.
23  */

24 public class StatusInfo implements IStatus {
25     
26     public static final IStatus OK_STATUS= new StatusInfo();
27     
28     private String JavaDoc fStatusMessage;
29     private int fSeverity;
30     
31     /**
32      * Creates a status set to OK (no message)
33      */

34     public StatusInfo() {
35         this(OK, null);
36     }
37
38     /**
39      * Creates a status .
40      * @param severity The status severity: ERROR, WARNING, INFO and OK.
41      * @param message The message of the status. Applies only for ERROR,
42      * WARNING and INFO.
43      */

44     public StatusInfo(int severity, String JavaDoc message) {
45         fStatusMessage= message;
46         fSeverity= severity;
47     }
48     
49     /**
50      * Returns if the status' severity is OK.
51      */

52     public boolean isOK() {
53         return fSeverity == IStatus.OK;
54     }
55
56     /**
57      * Returns if the status' severity is WARNING.
58      */

59     public boolean isWarning() {
60         return fSeverity == IStatus.WARNING;
61     }
62
63     /**
64      * Returns if the status' severity is INFO.
65      */

66     public boolean isInfo() {
67         return fSeverity == IStatus.INFO;
68     }
69
70     /**
71      * Returns if the status' severity is ERROR.
72      */

73     public boolean isError() {
74         return fSeverity == IStatus.ERROR;
75     }
76     
77     /**
78      * @see IStatus#getMessage
79      */

80     public String JavaDoc getMessage() {
81         return fStatusMessage;
82     }
83     
84     /**
85      * Sets the status to ERROR.
86      * @param errorMessage The error message (can be empty, but not null)
87      */

88     public void setError(String JavaDoc errorMessage) {
89         Assert.isNotNull(errorMessage);
90         fStatusMessage= errorMessage;
91         fSeverity= IStatus.ERROR;
92     }
93
94     /**
95      * Sets the status to WARNING.
96      * @param warningMessage The warning message (can be empty, but not null)
97      */

98     public void setWarning(String JavaDoc warningMessage) {
99         Assert.isNotNull(warningMessage);
100         fStatusMessage= warningMessage;
101         fSeverity= IStatus.WARNING;
102     }
103
104     /**
105      * Sets the status to INFO.
106      * @param infoMessage The info message (can be empty, but not null)
107      */

108     public void setInfo(String JavaDoc infoMessage) {
109         Assert.isNotNull(infoMessage);
110         fStatusMessage= infoMessage;
111         fSeverity= IStatus.INFO;
112     }
113
114     /**
115      * Sets the status to OK.
116      */

117     public void setOK() {
118         fStatusMessage= null;
119         fSeverity= IStatus.OK;
120     }
121     
122     /*
123      * @see IStatus#matches(int)
124      */

125     public boolean matches(int severityMask) {
126         return (fSeverity & severityMask) != 0;
127     }
128
129     /**
130      * Returns always <code>false</code>.
131      * @see IStatus#isMultiStatus()
132      */

133     public boolean isMultiStatus() {
134         return false;
135     }
136
137     /*
138      * @see IStatus#getSeverity()
139      */

140     public int getSeverity() {
141         return fSeverity;
142     }
143
144     /*
145      * @see IStatus#getPlugin()
146      */

147     public String JavaDoc getPlugin() {
148         return JavaUI.ID_PLUGIN;
149     }
150
151     /**
152      * Returns always <code>null</code>.
153      * @see IStatus#getException()
154      */

155     public Throwable JavaDoc getException() {
156         return null;
157     }
158
159     /**
160      * Returns always the error severity.
161      * @see IStatus#getCode()
162      */

163     public int getCode() {
164         return fSeverity;
165     }
166
167     /**
168      * Returns always an empty array.
169      * @see IStatus#getChildren()
170      */

171     public IStatus[] getChildren() {
172         return new IStatus[0];
173     }
174     
175     /**
176      * Returns a string representation of the status, suitable
177      * for debugging purposes only.
178      */

179     public String JavaDoc toString() {
180         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
181         buf.append("StatusInfo "); //$NON-NLS-1$
182
if (fSeverity == OK) {
183             buf.append("OK"); //$NON-NLS-1$
184
} else if (fSeverity == ERROR) {
185             buf.append("ERROR"); //$NON-NLS-1$
186
} else if (fSeverity == WARNING) {
187             buf.append("WARNING"); //$NON-NLS-1$
188
} else if (fSeverity == INFO) {
189             buf.append("INFO"); //$NON-NLS-1$
190
} else {
191             buf.append("severity="); //$NON-NLS-1$
192
buf.append(fSeverity);
193         }
194         buf.append(": "); //$NON-NLS-1$
195
buf.append(fStatusMessage);
196         return buf.toString();
197     }
198 }
199
Popular Tags