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.pde.internal.ui.parts;
011:
012: import org.eclipse.core.runtime.Assert;
013: import org.eclipse.core.runtime.IStatus;
014: import org.eclipse.pde.internal.ui.IPDEUIConstants;
015:
016: /**
017: * A settable IStatus.
018: * Can be an error, warning, info or ok. For error, info and warning states,
019: * a message describes the problem.
020: */
021: public class StatusInfo implements IStatus {
022:
023: private String fStatusMessage;
024: private int fSeverity;
025:
026: /**
027: * Creates a status set to OK (no message)
028: */
029: public StatusInfo() {
030: this (OK, null);
031: }
032:
033: /**
034: * Creates a status .
035: * @param severity The status severity: ERROR, WARNING, INFO and OK.
036: * @param message The message of the status. Applies only for ERROR,
037: * WARNING and INFO.
038: */
039: public StatusInfo(int severity, String message) {
040: fStatusMessage = message;
041: fSeverity = severity;
042: }
043:
044: /**
045: * Returns if the status' severity is OK.
046: */
047: public boolean isOK() {
048: return fSeverity == IStatus.OK;
049: }
050:
051: /**
052: * Returns if the status' severity is WARNING.
053: */
054: public boolean isWarning() {
055: return fSeverity == IStatus.WARNING;
056: }
057:
058: /**
059: * Returns if the status' severity is INFO.
060: */
061: public boolean isInfo() {
062: return fSeverity == IStatus.INFO;
063: }
064:
065: /**
066: * Returns if the status' severity is ERROR.
067: */
068: public boolean isError() {
069: return fSeverity == IStatus.ERROR;
070: }
071:
072: /**
073: * @see IStatus#getMessage
074: */
075: public String getMessage() {
076: return fStatusMessage;
077: }
078:
079: /**
080: * Sets the status to ERROR.
081: * @param The error message (can be empty, but not null)
082: */
083: public void setError(String errorMessage) {
084: Assert.isNotNull(errorMessage);
085: fStatusMessage = errorMessage;
086: fSeverity = IStatus.ERROR;
087: }
088:
089: /**
090: * Sets the status to WARNING.
091: * @param The warning message (can be empty, but not null)
092: */
093: public void setWarning(String warningMessage) {
094: Assert.isNotNull(warningMessage);
095: fStatusMessage = warningMessage;
096: fSeverity = IStatus.WARNING;
097: }
098:
099: /**
100: * Sets the status to INFO.
101: * @param The info message (can be empty, but not null)
102: */
103: public void setInfo(String infoMessage) {
104: Assert.isNotNull(infoMessage);
105: fStatusMessage = infoMessage;
106: fSeverity = IStatus.INFO;
107: }
108:
109: /**
110: * Sets the status to OK.
111: */
112: public void setOK() {
113: fStatusMessage = null;
114: fSeverity = IStatus.OK;
115: }
116:
117: /*
118: * @see IStatus#matches(int)
119: */
120: public boolean matches(int severityMask) {
121: return (fSeverity & severityMask) != 0;
122: }
123:
124: /**
125: * Returns always <code>false</code>.
126: * @see IStatus#isMultiStatus()
127: */
128: public boolean isMultiStatus() {
129: return false;
130: }
131:
132: /*
133: * @see IStatus#getSeverity()
134: */
135: public int getSeverity() {
136: return fSeverity;
137: }
138:
139: /*
140: * @see IStatus#getPlugin()
141: */
142: public String getPlugin() {
143: return IPDEUIConstants.PLUGIN_ID;
144: }
145:
146: /**
147: * Returns always <code>null</code>.
148: * @see IStatus#getException()
149: */
150: public Throwable getException() {
151: return null;
152: }
153:
154: /**
155: * Returns always the error severity.
156: * @see IStatus#getCode()
157: */
158: public int getCode() {
159: return fSeverity;
160: }
161:
162: /**
163: * Returns always <code>null</code>.
164: * @see IStatus#getChildren()
165: */
166: public IStatus[] getChildren() {
167: return new IStatus[0];
168: }
169:
170: }
|