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