001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.texteditor.templates;
011:
012: import org.eclipse.core.runtime.Assert;
013: import org.eclipse.core.runtime.IStatus;
014:
015: import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
016:
017: /**
018: * A settable IStatus.
019: * Can be an error, warning, info or OKk. For error, info and warning states,
020: * a message describes the problem.
021: *
022: * @since 3.0
023: */
024: class StatusInfo implements IStatus {
025:
026: private String fStatusMessage;
027: private int fSeverity;
028:
029: /**
030: * Creates a status set to OK (no message)
031: */
032: public StatusInfo() {
033: this (OK, null);
034: }
035:
036: /**
037: * Creates a status .
038: * @param severity The status severity: ERROR, WARNING, INFO and OK.
039: * @param message The message of the status. Applies only for ERROR,
040: * WARNING and INFO.
041: */
042: public StatusInfo(int severity, String message) {
043: fStatusMessage = message;
044: fSeverity = severity;
045: }
046:
047: /**
048: * Returns if the status' severity is OK.
049: *
050: * @return <code>true</code> if the status' severity is OK
051: */
052: public boolean isOK() {
053: return fSeverity == IStatus.OK;
054: }
055:
056: /**
057: * Returns if the status' severity is WARNING.
058: *
059: * @return <code>true</code> if the status' severity is WARNING
060: */
061: public boolean isWarning() {
062: return fSeverity == IStatus.WARNING;
063: }
064:
065: /**
066: * Returns if the status' severity is INFO.
067: *
068: * @return <code>true</code> if the status' severity is INFO
069: */
070: public boolean isInfo() {
071: return fSeverity == IStatus.INFO;
072: }
073:
074: /**
075: * Returns if the status' severity is ERROR.
076: *
077: * @return <code>true</code> if the status' severity is ERROR
078: */
079: public boolean isError() {
080: return fSeverity == IStatus.ERROR;
081: }
082:
083: /**
084: * Returns the message.
085: *
086: * @return the message
087: * @see IStatus#getMessage()
088: */
089: public String getMessage() {
090: return fStatusMessage;
091: }
092:
093: /**
094: * Sets the status to ERROR.
095: * @param errorMessage the error message (can be empty, but not null)
096: */
097: public void setError(String errorMessage) {
098: Assert.isNotNull(errorMessage);
099: fStatusMessage = errorMessage;
100: fSeverity = IStatus.ERROR;
101: }
102:
103: /**
104: * Sets the status to WARNING.
105: * @param warningMessage the warning message (can be empty, but not null)
106: */
107: public void setWarning(String warningMessage) {
108: Assert.isNotNull(warningMessage);
109: fStatusMessage = warningMessage;
110: fSeverity = IStatus.WARNING;
111: }
112:
113: /**
114: * Sets the status to INFO.
115: * @param infoMessage the info message (can be empty, but not null)
116: */
117: public void setInfo(String infoMessage) {
118: Assert.isNotNull(infoMessage);
119: fStatusMessage = infoMessage;
120: fSeverity = IStatus.INFO;
121: }
122:
123: /**
124: * Sets the status to OK.
125: */
126: public void setOK() {
127: fStatusMessage = null;
128: fSeverity = IStatus.OK;
129: }
130:
131: /*
132: * @see IStatus#matches(int)
133: */
134: public boolean matches(int severityMask) {
135: return (fSeverity & severityMask) != 0;
136: }
137:
138: /**
139: * Returns always <code>false</code>.
140: * @see IStatus#isMultiStatus()
141: */
142: public boolean isMultiStatus() {
143: return false;
144: }
145:
146: /*
147: * @see IStatus#getSeverity()
148: */
149: public int getSeverity() {
150: return fSeverity;
151: }
152:
153: /*
154: * @see IStatus#getPlugin()
155: */
156: public String getPlugin() {
157: return TextEditorPlugin.PLUGIN_ID;
158: }
159:
160: /**
161: * Returns always <code>null</code>.
162: * @see IStatus#getException()
163: */
164: public Throwable getException() {
165: return null;
166: }
167:
168: /**
169: * Returns always the error severity.
170: * @see IStatus#getCode()
171: */
172: public int getCode() {
173: return fSeverity;
174: }
175:
176: /**
177: * Returns always <code>null</code>.
178: * @see IStatus#getChildren()
179: */
180: public IStatus[] getChildren() {
181: return new IStatus[0];
182: }
183:
184: }
|