package org.csstudio.opibuilder.util;

import java.util.logging.Level;

import org.csstudio.opibuilder.OPIBuilderPlugin;
import org.eclipse.jface.dialogs.MessageDialog;

/**
 * The utility class help to handle exceptions.
 * @author Xihui Chen
 *
 */
public class ErrorHandlerUtil {	
	
	/**General error handle method.
	 * @param message message of the error.
	 * @param exception the exception.
	 * @param writeToConsole true if message will output to console.
	 * @param popErrorDialog true if an error dialog will popup. Must be called in UI thread if this is true.
	 */
	public static void handleError(final String message, 
			final Throwable exception, final boolean writeToConsole, final boolean popErrorDialog){
		OPIBuilderPlugin.getLogger().log(Level.WARNING,
            message, exception); //$NON-NLS-1$	
		if(writeToConsole)
			ConsoleService.getInstance().writeError(message + "\n" + exception);
		if(popErrorDialog){
			if(DisplayUtils.getDisplay() != null)
				MessageDialog.openError(
						DisplayUtils.getDisplay().getActiveShell(), "Error",	message);
		}
	}
	
	
	/**This method will call {@link #handleError(String, Throwable, boolean, boolean)} with writeToConsole as true
	 * and popErrorDialog as false.
	 * @param message message of the error.
	 * @param exception the exception.
	 */
	public static void handleError(final String message, 
			final Exception exception){
		handleError(message, exception, true, false);
	}

}

@@ -134,43 +134,143 @@
 org.
-eclipse.jface.dialogs.MessageDialog
+csstudio.ui.util.dialogs.ExceptionDetailsErrorDialog;%0D%0Aimport org.eclipse.core.runtime.IStatus;%0D%0Aimport org.eclipse.core.runtime.Status
 ;%0D%0A%0D
@@ -1097,40 +1097,310 @@
 ull)
+%7B
 %0D%0A%09%09%09%09
-MessageDialog.openError(%0D%0A
+IStatus status = new Status(IStatus.ERROR, OPIBuilderPlugin.PLUGIN_ID,%0D%0A%09%09%09%09%09%09exception.getLocalizedMessage(), exception);%0D%0A%09%09%09%09ExceptionDetailsErrorDialog.openError(%0D%0A%09%09%09%09%09%09DisplayUtils.getDisplay().getActiveShell(),%0D%0A%09%09%09%09%09%09%22Error%22, message, %0D%0A%09%09%09%09%09%09status);%0D%0A//%09%09%09%09MessageDialog.openError(%0D%0A//
 %09%09%09%09
@@ -1463,16 +1463,28 @@
 essage);
+%09%09%09%09%0D%0A%09%09%09%7D%0D%0A
 %0D%0A%09%09%7D%0D%0A%09

use ExceptionDetailsErrorDialog for error handling