10c7efbc22ba1c8defc26de899596f5d6886e4d3
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / dialogs / StatusInfo.java
1 package net.sourceforge.phpdt.internal.ui.dialogs;
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. Can be an error, warning, info or ok. For error, info and
10  * warning states, a message describes the problem.
11  */
12 public class StatusInfo implements IStatus {
13
14         private String fStatusMessage;
15
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          * 
28          * @param severity
29          *            The status severity: ERROR, WARNING, INFO and OK.
30          * @param message
31          *            The message of the status. Applies only for ERROR, WARNING and
32          *            INFO.
33          */
34         public StatusInfo(int severity, String message) {
35                 fStatusMessage = message;
36                 fSeverity = severity;
37         }
38
39         /**
40          * Returns if the status' severity is OK.
41          */
42         public boolean isOK() {
43                 return fSeverity == IStatus.OK;
44         }
45
46         /**
47          * Returns if the status' severity is WARNING.
48          */
49         public boolean isWarning() {
50                 return fSeverity == IStatus.WARNING;
51         }
52
53         /**
54          * Returns if the status' severity is INFO.
55          */
56         public boolean isInfo() {
57                 return fSeverity == IStatus.INFO;
58         }
59
60         /**
61          * Returns if the status' severity is ERROR.
62          */
63         public boolean isError() {
64                 return fSeverity == IStatus.ERROR;
65         }
66
67         /**
68          * @see IStatus#getMessage
69          */
70         public String getMessage() {
71                 return fStatusMessage;
72         }
73
74         /**
75          * Sets the status to ERROR.
76          * 
77          * @param The
78          *            error message (can be empty, but not null)
79          */
80         public void setError(String errorMessage) {
81                 Assert.isNotNull(errorMessage);
82                 fStatusMessage = errorMessage;
83                 fSeverity = IStatus.ERROR;
84         }
85
86         /**
87          * Sets the status to WARNING.
88          * 
89          * @param The
90          *            warning message (can be empty, but not null)
91          */
92         public void setWarning(String warningMessage) {
93                 Assert.isNotNull(warningMessage);
94                 fStatusMessage = warningMessage;
95                 fSeverity = IStatus.WARNING;
96         }
97
98         /**
99          * Sets the status to INFO.
100          * 
101          * @param The
102          *            info message (can be empty, but not null)
103          */
104         public void setInfo(String infoMessage) {
105                 Assert.isNotNull(infoMessage);
106                 fStatusMessage = infoMessage;
107                 fSeverity = IStatus.INFO;
108         }
109
110         /**
111          * Sets the status to OK.
112          */
113         public void setOK() {
114                 fStatusMessage = null;
115                 fSeverity = IStatus.OK;
116         }
117
118         /*
119          * @see IStatus#matches(int)
120          */
121         public boolean matches(int severityMask) {
122                 return (fSeverity & severityMask) != 0;
123         }
124
125         /**
126          * Returns always <code>false</code>.
127          * 
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 getPlugin() {
145                 return PHPeclipsePlugin.PLUGIN_ID;
146         }
147
148         /**
149          * Returns always <code>null</code>.
150          * 
151          * @see IStatus#getException()
152          */
153         public Throwable getException() {
154                 return null;
155         }
156
157         /**
158          * Returns always the error severity.
159          * 
160          * @see IStatus#getCode()
161          */
162         public int getCode() {
163                 return fSeverity;
164         }
165
166         /**
167          * Returns always <code>null</code>.
168          * 
169          * @see IStatus#getChildren()
170          */
171         public IStatus[] getChildren() {
172                 return new IStatus[0];
173         }
174
175 }