/**
* This file Copyright (c) 2005-2008 Aptana, Inc. This program is
* dual-licensed under both the Aptana Public License and the GNU General
* Public license. You may elect to use one or the other of these licenses.
*
* This program is distributed in the hope that it will be useful, but
* AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
* NONINFRINGEMENT. Redistribution, except as permitted by whichever of
* the GPL or APL you select, is prohibited.
*
* 1. For the GPL license (GPL), you can redistribute and/or modify this
* program under the terms of the GNU General Public License,
* Version 3, as published by the Free Software Foundation. You should
* have received a copy of the GNU General Public License, Version 3 along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Aptana provides a special exception to allow redistribution of this file
* with certain other free and open source software ("FOSS") code and certain additional terms
* pursuant to Section 7 of the GPL. You may view the exception and these
* terms on the web at http://www.aptana.com/legal/gpl/.
*
* 2. For the Aptana Public License (APL), this program and the
* accompanying materials are made available under the terms of the APL
* v1.0 which accompanies this distribution, and is available at
* http://www.aptana.com/legal/apl/.
*
* You may view the GPL, Aptana's exception and additional terms, and the
* APL in the file titled license.html at the root of the corresponding
* plugin containing this source file.
*
* Any modifications to this file must keep this entire header intact.
*/
package com.aptana.ide.debug.internal.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.util.Assert;
import com.aptana.ide.debug.ui.DebugUiPlugin;
/**
* A settable IStatus. Can be an error, warning, info or ok. For error, info and warning states, a message describes the
* problem.
*/
public class StatusInfo implements IStatus
{
private String fStatusMessage;
private int fSeverity;
/**
* Creates a status set to OK (no message)
*/
public StatusInfo()
{
this(OK, null);
}
/**
* Creates a status .
*
* @param severity
* The status severity: ERROR, WARNING, INFO and OK.
* @param message
* The message of the status. Applies only for ERROR, WARNING and INFO.
*/
public StatusInfo(int severity, String message)
{
fStatusMessage = message;
fSeverity = severity;
}
/**
* Returns if the status' severity is OK.
*
* @return boolean
*/
public boolean isOK()
{
return fSeverity == IStatus.OK;
}
/**
* Returns if the status' severity is WARNING.
*
* @return boolean
*/
public boolean isWarning()
{
return fSeverity == IStatus.WARNING;
}
/**
* Returns if the status' severity is INFO.
*
* @return boolean
*/
public boolean isInfo()
{
return fSeverity == IStatus.INFO;
}
/**
* Returns if the status' severity is ERROR.
*
* @return boolean
*/
public boolean isError()
{
return fSeverity == IStatus.ERROR;
}
/**
* @see org.eclipse.core.runtime.IStatus#getMessage()
*/
public String getMessage()
{
return fStatusMessage;
}
/**
* Sets the status to ERROR.
*
* @param errorMessage
* The error message (can be empty, but not null)
*/
public void setError(String errorMessage)
{
Assert.isNotNull(errorMessage);
fStatusMessage = errorMessage;
fSeverity = IStatus.ERROR;
}
/**
* Sets the status to WARNING.
*
* @param warningMessage
* The warning message (can be empty, but not null)
*/
public void setWarning(String warningMessage)
{
Assert.isNotNull(warningMessage);
fStatusMessage = warningMessage;
fSeverity = IStatus.WARNING;
}
/**
* Sets the status to INFO.
*
* @param infoMessage
* The info message (can be empty, but not null)
*/
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;
}
/**
* @see org.eclipse.core.runtime.IStatus#matches(int)
*/
public boolean matches(int severityMask)
{
return (fSeverity & severityMask) != 0;
}
/**
* Returns always <code>false</code>.
*
* @see IStatus#isMultiStatus()
*/
public boolean isMultiStatus()
{
return false;
}
/**
* @see org.eclipse.core.runtime.IStatus#getSeverity()
*/
public int getSeverity()
{
return fSeverity;
}
/**
* @see org.eclipse.core.runtime.IStatus#getPlugin()
*/
public String getPlugin()
{
return DebugUiPlugin.ID;
}
/**
* Returns always <code>null</code>.
*
* @see IStatus#getException()
*/
public Throwable getException()
{
return null;
}
/**
* Returns always the error severity.
*
* @see IStatus#getCode()
*/
public int getCode()
{
return fSeverity;
}
/**
* Returns always <code>null</code>.
*
* @see IStatus#getChildren()
*/
public IStatus[] getChildren()
{
return new IStatus[0];
}
}