b229b7d224d26c5f2cce416e9a97a3e65be807e1
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / dialog / StatusInfo.java
1 package net.sourceforge.phpdt.internal.ui.dialog;
2
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
4
5 import org.eclipse.core.runtime.IStatus;
6 import org.eclipse.jface.util.Assert;
7
8 /**
9  * A settable IStatus. 
10  * Can be an error, warning, info or ok. For error, info and warning states,
11  * a message describes the problem.
12  */
13 public class StatusInfo implements IStatus {
14
15         private String fStatusMessage;
16         private int fSeverity;
17
18         /**
19          * Creates a status set to OK (no message)
20          */
21         public StatusInfo() {
22                 this(OK, null);
23         }
24
25         /**
26          * Creates a status .
27          * @param severity The status severity: ERROR, WARNING, INFO and OK.
28          * @param message The message of the status. Applies only for ERROR,
29          * WARNING and INFO.
30          */
31         public StatusInfo(int severity, String message) {
32                 fStatusMessage = message;
33                 fSeverity = severity;
34         }
35
36         /**
37          *  Returns if the status' severity is OK.
38          */
39         public boolean isOK() {
40                 return fSeverity == IStatus.OK;
41         }
42
43         /**
44          *  Returns if the status' severity is WARNING.
45          */
46         public boolean isWarning() {
47                 return fSeverity == IStatus.WARNING;
48         }
49
50         /**
51          *  Returns if the status' severity is INFO.
52          */
53         public boolean isInfo() {
54                 return fSeverity == IStatus.INFO;
55         }
56
57         /**
58          *  Returns if the status' severity is ERROR.
59          */
60         public boolean isError() {
61                 return fSeverity == IStatus.ERROR;
62         }
63
64         /**
65          * @see IStatus#getMessage
66          */
67         public String getMessage() {
68                 return fStatusMessage;
69         }
70
71         /**
72          * Sets the status to ERROR.
73          * @param The error message (can be empty, but not null)
74          */
75         public void setError(String errorMessage) {
76                 Assert.isNotNull(errorMessage);
77                 fStatusMessage = errorMessage;
78                 fSeverity = IStatus.ERROR;
79         }
80
81         /**
82          * Sets the status to WARNING.
83          * @param The warning message (can be empty, but not null)
84          */
85         public void setWarning(String warningMessage) {
86                 Assert.isNotNull(warningMessage);
87                 fStatusMessage = warningMessage;
88                 fSeverity = IStatus.WARNING;
89         }
90
91         /**
92          * Sets the status to INFO.
93          * @param The info message (can be empty, but not null)
94          */
95         public void setInfo(String infoMessage) {
96                 Assert.isNotNull(infoMessage);
97                 fStatusMessage = infoMessage;
98                 fSeverity = IStatus.INFO;
99         }
100
101         /**
102          * Sets the status to OK.
103          */
104         public void setOK() {
105                 fStatusMessage = null;
106                 fSeverity = IStatus.OK;
107         }
108
109         /*
110          * @see IStatus#matches(int)
111          */
112         public boolean matches(int severityMask) {
113                 return (fSeverity & severityMask) != 0;
114         }
115
116         /**
117          * Returns always <code>false</code>.
118          * @see IStatus#isMultiStatus()
119          */
120         public boolean isMultiStatus() {
121                 return false;
122         }
123
124         /*
125          * @see IStatus#getSeverity()
126          */
127         public int getSeverity() {
128                 return fSeverity;
129         }
130
131         /*
132          * @see IStatus#getPlugin()
133          */
134         public String getPlugin() {
135                 return PHPeclipsePlugin.PLUGIN_ID;
136         }
137
138         /**
139          * Returns always <code>null</code>.
140          * @see IStatus#getException()
141          */
142         public Throwable getException() {
143                 return null;
144         }
145
146         /**
147          * Returns always the error severity.
148          * @see IStatus#getCode()
149          */
150         public int getCode() {
151                 return fSeverity;
152         }
153
154         /**
155          * Returns always <code>null</code>.
156          * @see IStatus#getChildren()
157          */
158         public IStatus[] getChildren() {
159                 return new IStatus[0];
160         }
161
162 }