Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/error
In directory sc8-pr-cvs1:/tmp/cvs-serv20662/src/java/org/krysalis/version/eclipse/plugin/error
Added Files:
ErrorHandler.java PluginErrorHandler.java
Log Message:
--- NEW FILE: ErrorHandler.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.error;
/**
* @author Anou Manavalan
*
*/
public interface ErrorHandler
{
/**
* Reports an exception to the user by displaying and logging
*
* @param e The exception
* @param msg The message to display
*/
public void handleExceptionMessage(Throwable e, String msg);
/**
* Reports an error to the user by displaying and logging
*
* @param msg The message to display
*/
public void handleErrorMessage(String msg);
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: PluginErrorHandler.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.error;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.krysalis.version.eclipse.plugin.log.PluginLogger;
/**
* @author Anou Manavalan
*
*/
public class PluginErrorHandler implements ErrorHandler
{
private Plugin m_plugin = null;
private PluginLogger m_logger = null;
private static final String ERROR_TITLE = "Error";
private static final String CORE_ERROR_TITLE = "CoreError";
/**
* Constructor for PluginErrorHandler.
*/
public PluginErrorHandler(Plugin plugin)
{
super();
m_plugin = plugin;
m_logger = new PluginLogger(m_plugin);
}
/**
* Reports an exception to the user by displaying and logging
*
* @param e The exception
* @param msg The message to display
*/
public void handleExceptionMessage(Throwable e, String msg)
{
m_logger.log(e, msg);
displayException(e, msg);
}
/**
* Reports an exception to the user by displaying and logging
*
* @param e The exception
* @param msg The message to display
*/
public void handleErrorMessage(String msg)
{
m_logger.error(msg);
displayError(msg);
}
/**
* Displays an error to the user
*
* @param msg The message to display
*/
public void displayError(String msg)
{
Shell shell = new Shell();
// Create an error message
String title = ERROR_TITLE;
MessageDialog.openError(shell, title, msg);
}
/**
* Displays an exception to the user
*
* @param e The exception
* @param msg The message to display
*/
public void displayException(Throwable e, String msg)
{
if (e instanceof CoreException)
{
displayCoreExceptionMessage((CoreException) e, msg);
}
else
{
displayExceptionMessage(e, msg);
}
}
/**
* Displays an exception to the user
*
* @param e The exception
* @param msg The message to display
*/
public void displayExceptionMessage(Throwable e, String msg)
{
Shell shell = new Shell();
// Create an error message
String title = ERROR_TITLE;
MessageDialog.openError(shell, title, msg);
}
/**
* Displays a <code>CoreException</code> to the user
*
* @param e The exception
*/
static public void displayCoreExceptionMessage(CoreException e, String msg)
{
Shell shell = new Shell();
// Create an error message
String title = CORE_ERROR_TITLE;
String dispMsg = msg + "\n\n" + e.getMessage();
// If there was a CoreException, show the appropriate dialog
IStatus status = e.getStatus();
if (status != null)
{
switch (status.getSeverity())
{
case IStatus.INFO :
MessageDialog.openInformation(shell, title, dispMsg);
break;
case IStatus.WARNING :
MessageDialog.openWarning(shell, title, dispMsg);
break;
default :
MessageDialog.openError(shell, title, dispMsg);
}
}
else
{
// Everything else is an error
MessageDialog.openError(shell, title, dispMsg);
}
}
public static void main(String[] args)
{
}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open!
Get cracking and register here for some mind boggling fun and
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.