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