KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > templates > 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.texteditor.templates;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IStatus;
15
16
17 import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
18
19 /**
20  * A settable IStatus.
21  * Can be an error, warning, info or OKk. For error, info and warning states,
22  * a message describes the problem.
23  *
24  * @since 3.0
25  */

26 class StatusInfo implements IStatus {
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      * @return <code>true</code> if the status' severity is OK
53      */

54     public boolean isOK() {
55         return fSeverity == IStatus.OK;
56     }
57
58     /**
59      * Returns if the status' severity is WARNING.
60      *
61      * @return <code>true</code> if the status' severity is WARNING
62      */

63     public boolean isWarning() {
64         return fSeverity == IStatus.WARNING;
65     }
66
67     /**
68      * Returns if the status' severity is INFO.
69      *
70      * @return <code>true</code> if the status' severity is INFO
71      */

72     public boolean isInfo() {
73         return fSeverity == IStatus.INFO;
74     }
75
76     /**
77      * Returns if the status' severity is ERROR.
78      *
79      * @return <code>true</code> if the status' severity is ERROR
80      */

81     public boolean isError() {
82         return fSeverity == IStatus.ERROR;
83     }
84
85     /**
86      * Returns the message.
87      *
88      * @return the message
89      * @see IStatus#getMessage()
90      */

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

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

109     public void setWarning(String JavaDoc warningMessage) {
110         Assert.isNotNull(warningMessage);
111         fStatusMessage= warningMessage;
112         fSeverity= IStatus.WARNING;
113     }
114
115     /**
116      * Sets the status to INFO.
117      * @param infoMessage the info message (can be empty, but not null)
118      */

119     public void setInfo(String JavaDoc infoMessage) {
120         Assert.isNotNull(infoMessage);
121         fStatusMessage= infoMessage;
122         fSeverity= IStatus.INFO;
123     }
124
125     /**
126      * Sets the status to OK.
127      */

128     public void setOK() {
129         fStatusMessage= null;
130         fSeverity= IStatus.OK;
131     }
132
133     /*
134      * @see IStatus#matches(int)
135      */

136     public boolean matches(int severityMask) {
137         return (fSeverity & severityMask) != 0;
138     }
139
140     /**
141      * Returns always <code>false</code>.
142      * @see IStatus#isMultiStatus()
143      */

144     public boolean isMultiStatus() {
145         return false;
146     }
147
148     /*
149      * @see IStatus#getSeverity()
150      */

151     public int getSeverity() {
152         return fSeverity;
153     }
154
155     /*
156      * @see IStatus#getPlugin()
157      */

158     public String JavaDoc getPlugin() {
159         return TextEditorPlugin.PLUGIN_ID;
160     }
161
162     /**
163      * Returns always <code>null</code>.
164      * @see IStatus#getException()
165      */

166     public Throwable JavaDoc getException() {
167         return null;
168     }
169
170     /**
171      * Returns always the error severity.
172      * @see IStatus#getCode()
173      */

174     public int getCode() {
175         return fSeverity;
176     }
177
178     /**
179      * Returns always <code>null</code>.
180      * @see IStatus#getChildren()
181      */

182     public IStatus[] getChildren() {
183         return new IStatus[0];
184     }
185
186 }
187
Popular Tags