KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > 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.ant.internal.ui.preferences;
12
13
14 import org.eclipse.ant.internal.ui.IAntUIConstants;
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.IStatus;
17
18 /**
19  * A settable IStatus.
20  * Can be an error, warning, info or ok. For error, info and warning states,
21  * a message describes the problem.
22  */

23 public class StatusInfo implements IStatus {
24
25     private String JavaDoc fStatusMessage;
26     private int fSeverity;
27
28     /**
29      * Creates a status set to OK (no message)
30      */

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

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

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

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

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

70     public boolean isError() {
71         return fSeverity == IStatus.ERROR;
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.core.runtime.IStatus#getMessage()
76      */

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

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

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

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

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

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

130     public boolean isMultiStatus() {
131         return false;
132     }
133
134     /*
135      * @see IStatus#getSeverity()
136      */

137     public int getSeverity() {
138         return fSeverity;
139     }
140
141     /*
142      * @see IStatus#getPlugin()
143      */

144     public String JavaDoc getPlugin() {
145         return IAntUIConstants.PLUGIN_ID;
146     }
147
148     /**
149      * Returns always <code>null</code>.
150      * @see IStatus#getException()
151      */

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

160     public int getCode() {
161         return fSeverity;
162     }
163
164     /**
165      * Returns always <code>null</code>.
166      * @see IStatus#getChildren()
167      */

168     public IStatus[] getChildren() {
169         return new IStatus[0];
170     }
171
172 }
173
Popular Tags