KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > 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.ui.internal.editors.text;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IStatus;
15
16
17 import org.eclipse.ui.editors.text.EditorsUI;
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  * @since 2.1
25  */

26 class StatusInfo implements IStatus {
27
28     /** The message of this status. */
29     private String JavaDoc fStatusMessage;
30     /** The severity of this status. */
31     private int fSeverity;
32
33     /**
34      * Creates a status set to OK (no message).
35      */

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

47     public StatusInfo(int severity, String JavaDoc message) {
48         fStatusMessage= message;
49         fSeverity= severity;
50     }
51
52     /*
53      * @see org.eclipse.core.runtime.IStatus#isOK()
54      */

55     public boolean isOK() {
56         return fSeverity == IStatus.OK;
57     }
58
59     /**
60      * Returns whether this status indicates a warning.
61      *
62      * @return <code>true</code> if this status has severity
63      * {@link IStatus#WARNING} and <code>false</code> otherwise
64      */

65     public boolean isWarning() {
66         return fSeverity == IStatus.WARNING;
67     }
68
69     /**
70      * Returns whether this status indicates an info.
71      *
72      * @return <code>true</code> if this status has severity
73      * {@link IStatus#INFO} and <code>false</code> otherwise
74      */

75     public boolean isInfo() {
76         return fSeverity == IStatus.INFO;
77     }
78
79     /**
80      * Returns whether this status indicates an error.
81      *
82      * @return <code>true</code> if this status has severity
83      * {@link IStatus#ERROR} and <code>false</code> otherwise
84      */

85     public boolean isError() {
86         return fSeverity == IStatus.ERROR;
87     }
88
89     /*
90      * @see IStatus#getMessage()
91      */

92     public String JavaDoc getMessage() {
93         return fStatusMessage;
94     }
95
96     /**
97      * Sets the status to ERROR.
98      *
99      * @param errorMessage the error message which can be an empty string, but not <code>null</code>
100      */

101     public void setError(String JavaDoc errorMessage) {
102         Assert.isNotNull(errorMessage);
103         fStatusMessage= errorMessage;
104         fSeverity= IStatus.ERROR;
105     }
106
107     /**
108      * Sets the status to WARNING.
109      *
110      * @param warningMessage the warning message which can be an empty string, but not <code>null</code>
111      */

112     public void setWarning(String JavaDoc warningMessage) {
113         Assert.isNotNull(warningMessage);
114         fStatusMessage= warningMessage;
115         fSeverity= IStatus.WARNING;
116     }
117
118     /**
119      * Sets the status to INFO.
120      *
121      * @param infoMessage the info message which can be an empty string, but not <code>null</code>
122      */

123     public void setInfo(String JavaDoc infoMessage) {
124         Assert.isNotNull(infoMessage);
125         fStatusMessage= infoMessage;
126         fSeverity= IStatus.INFO;
127     }
128
129     /**
130      * Sets the status to OK.
131      */

132     public void setOK() {
133         fStatusMessage= null;
134         fSeverity= IStatus.OK;
135     }
136
137     /*
138      * @see IStatus#matches(int)
139      */

140     public boolean matches(int severityMask) {
141         return (fSeverity & severityMask) != 0;
142     }
143
144     /**
145      * Returns always <code>false</code>.
146      *
147      * @see IStatus#isMultiStatus()
148      */

149     public boolean isMultiStatus() {
150         return false;
151     }
152
153     /*
154      * @see IStatus#getSeverity()
155      */

156     public int getSeverity() {
157         return fSeverity;
158     }
159
160     /*
161      * @see IStatus#getPlugin()
162      */

163     public String JavaDoc getPlugin() {
164         return EditorsUI.PLUGIN_ID;
165     }
166
167     /**
168      * Returns always <code>null</code>.
169      *
170      * @see IStatus#getException()
171      */

172     public Throwable JavaDoc getException() {
173         return null;
174     }
175
176     /**
177      * Returns always the error severity.
178      *
179      * @see IStatus#getCode()
180      */

181     public int getCode() {
182         return fSeverity;
183     }
184
185     /**
186      * Returns always <code>null</code>.
187      *
188      * @see IStatus#getChildren()
189      */

190     public IStatus[] getChildren() {
191         return new IStatus[0];
192     }
193
194 }
195
Popular Tags