Skip to main content
summaryrefslogtreecommitdiffstats
blob: fdacfcba15403db173272a6734cfd3bb6b9e3405 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.internal.editors.text;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;

import org.eclipse.ui.editors.text.EditorsUI;

/**
 * A settable IStatus.
 * Can be an error, warning, info or ok. For error, info and warning states,
 * a message describes the problem.
 *
 * @since 2.1
 */
class StatusInfo implements IStatus {

	/** The message of this status.  */
	private String fStatusMessage;
	/** The severity of this status. */
	private int fSeverity;

	/**
	 * Creates a status set to OK (no message).
	 */
	public StatusInfo() {
		this(OK, null);
	}

	/**
	 * Creates a status with the given severity and message.
	 *
	 * @param severity the severity of this status: ERROR, WARNING, INFO and OK.
	 * @param message the message of this status. Applies only for ERROR,
	 * WARNING and INFO.
	 */
	public StatusInfo(int severity, String message) {
		fStatusMessage= message;
		fSeverity= severity;
	}

	@Override
	public boolean isOK() {
		return fSeverity == IStatus.OK;
	}

	/**
	 * Returns whether this status indicates a warning.
	 *
	 * @return <code>true</code> if this status has severity
	 *    {@link IStatus#WARNING} and <code>false</code> otherwise
	 */
	public boolean isWarning() {
		return fSeverity == IStatus.WARNING;
	}

	/**
	 * Returns whether this status indicates an info.
	 *
	 * @return <code>true</code> if this status has severity
	 *    {@link IStatus#INFO} and <code>false</code> otherwise
	 */
	public boolean isInfo() {
		return fSeverity == IStatus.INFO;
	}

	/**
	 * Returns whether this status indicates an error.
	 *
	 * @return <code>true</code> if this status has severity
	 *    {@link IStatus#ERROR} and <code>false</code> otherwise
	 */
	public boolean isError() {
		return fSeverity == IStatus.ERROR;
	}

	@Override
	public String getMessage() {
		return fStatusMessage;
	}

	/**
	 * Sets the status to ERROR.
	 *
	 * @param errorMessage the error message which can be an empty string, but not <code>null</code>
	 */
	public void setError(String errorMessage) {
		Assert.isNotNull(errorMessage);
		fStatusMessage= errorMessage;
		fSeverity= IStatus.ERROR;
	}

	/**
	 * Sets the status to WARNING.
	 *
	 * @param warningMessage the warning message which can be an empty string, but not <code>null</code>
	 */
	public void setWarning(String warningMessage) {
		Assert.isNotNull(warningMessage);
		fStatusMessage= warningMessage;
		fSeverity= IStatus.WARNING;
	}

	/**
	 * Sets the status to INFO.
	 *
	 * @param infoMessage the info message which can be an empty string, but not <code>null</code>
	 */
	public void setInfo(String infoMessage) {
		Assert.isNotNull(infoMessage);
		fStatusMessage= infoMessage;
		fSeverity= IStatus.INFO;
	}

	/**
	 * Sets the status to OK.
	 */
	public void setOK() {
		fStatusMessage= null;
		fSeverity= IStatus.OK;
	}

	@Override
	public boolean matches(int severityMask) {
		return (fSeverity & severityMask) != 0;
	}

	/**
	 * Returns always <code>false</code>.
	 *
	 * @see IStatus#isMultiStatus()
	 */
	@Override
	public boolean isMultiStatus() {
		return false;
	}

	@Override
	public int getSeverity() {
		return fSeverity;
	}

	@Override
	public String getPlugin() {
		return EditorsUI.PLUGIN_ID;
	}

	/**
	 * Returns always <code>null</code>.
	 *
	 * @see IStatus#getException()
	 */
	@Override
	public Throwable getException() {
		return null;
	}

	/**
	 * Returns always the error severity.
	 *
	 * @see IStatus#getCode()
	 */
	@Override
	public int getCode() {
		return fSeverity;
	}

	/**
	 * Returns always <code>null</code>.
	 *
	 * @see IStatus#getChildren()
	 */
	@Override
	public IStatus[] getChildren() {
		return new IStatus[0];
	}

}

Back to the top