⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eclipsemeuierrors.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/*  
 ********************************************************************
 * 
 *	File    	:   EclipseMEUIErrors.java
 *  Package     :   eclipseme.ui
 *	System      :   eclipseme.ui
 *	Author      :   Kevin Hunter
 *	Description :   
 *	                
 * Copyright (c) 2004 Kevin Hunter
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 *
 *  CVS
 *	$Source: /cvsroot/eclipseme/eclipseme.ui/src/eclipseme/ui/EclipseMEUIErrors.java,v $
 *	$Author: setera $
 *	$Date: 2005/07/08 21:47:10 $
 *	$Revision: 1.3 $
 *
 ********************************************************************
 */
package eclipseme.ui;

import java.text.MessageFormat;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Shell;

import eclipseme.ui.EclipseMEUIErrors;
import eclipseme.ui.EclipseMEUIStrings;
import eclipseme.ui.internal.EclipseMEUIPlugin;

/**
 * This interface holds the error, warning codes for the EclipseME
 * eclipseme.ui package.
 * 
 * @author khunter
 * 
 */
public class EclipseMEUIErrors
{
	/**
	 * This string represents the prefix used in looking up messages for
	 * error and warning codes.
	 */
	
	public static final String MESSAGE_PREFIX = "EclipseMEUIError.";

	
	/*
	 * The constants below represent errors that the eclipseme.ui plugin
	 * can generate.  Messages for these will be found in the EclipseMECoreStrings.properties
	 * file.
	 */
	public static final int UI_ERROR_BASE = 110000;
	public static final int UI_ERROR_EXCEPTION = UI_ERROR_BASE + 1;
	
	/*
	 * The constants below represent warnings that the eclipseme.core plugin
	 * can generate.  Messages for these will be found in the EclipseMECoreStrings.properties
	 * file.
	 */
	public static final int UI_WARNING_BASE = 120000;
	
	/*
	 * The constants below represent internal errors.  These indicate some kind of
	 * logic fault, as opposed to being something that could happen under normal
	 * conditions.  As such, these items do not have messages.  Instead, a "generic"
	 * message is generated.
	 */
	public static final int UI_INTERNAL_BASE = 190000;
	
	/**
	 * This routine returns the message associated with a particular error code
	 * or warning.  If there's a specific text message in the resource bundle,
	 * associated with this code, that one is returned.  Otherwise, a default
	 * message is used.  In either case, the error code is optionally (based
	 * on the string contents) substituted into the message.
	 * 
	 * @param nCode		The error code.
	 * @return
	 */
	
	public static final String getErrorMessage(int nCode)
	{
		String strTemplate;
		
		strTemplate = EclipseMEUIStrings.getBundleString(MESSAGE_PREFIX + nCode);
		if (strTemplate == null)
		{
			if (nCode < UI_INTERNAL_BASE)
			{
				strTemplate = EclipseMEUIStrings.getString(MESSAGE_PREFIX+"Default");
			}
			else
			{
				strTemplate = EclipseMEUIStrings.getString(MESSAGE_PREFIX+"InternalTemplate");
			}
		}
		
		String strMessage = MessageFormat.format(strTemplate, new Integer[] { new Integer(nCode) });
		return(strMessage);
	}
	
	/**
	 * This routine throws a CoreException with a status code of
	 * "ERROR", the specified error code, and a message that is
	 * internationalized.
	 * 
	 * @param code
	 * @throws CoreException
	 */
	public static void throwCoreExceptionError(int code) throws CoreException
	{
		IStatus status = new Status(IStatus.ERROR,
									IEclipseMEUIConstants.PLUGIN_ID,
									code,
									EclipseMEUIErrors.getErrorMessage(code),
									null);
		throw new CoreException(status);
	}

	/**
	 * This routine throws a CoreException with a status code of
	 * "ERROR", the specified error code, and a message that is
	 * internationalized.
	 * 
	 * @param code
	 * @throws CoreException
	 */
	public static void throwCoreExceptionError(int code, Throwable e) throws CoreException
	{
		IStatus status = new Status(IStatus.ERROR,
									IEclipseMEUIConstants.PLUGIN_ID,
									code,
									EclipseMEUIErrors.getErrorMessage(code),
									e);
		throw new CoreException(status);
	}
	
	/**
	 * This routine handles the problems of displaying internationalized error messages.
	 * 
	 * @param s					<code>Shell</code> on which to display.
	 * @param dialogTitleKey	Key in the resource file for dialog title
	 * @param messageKey		Key in the resource file for dialog message.
	 * @param status			Optional <code>IStatus</code> object that is the source of the error.
	 */
	
	public static void displayError(Shell s, String dialogTitleKey, String messageKey, IStatus status)
	{
		if (dialogTitleKey == null)
		{
			dialogTitleKey = MESSAGE_PREFIX+"Default";
		}
		
		if (messageKey == null)
		{
			messageKey = MESSAGE_PREFIX+"Default";
		}
		
		int nCode = 0;
		if (status != null)
		{
			nCode = status.getCode();
		}
		
		Integer[] substitutions = new Integer[] { new Integer(nCode) };
		
		String strTitle = MessageFormat.format(EclipseMEUIStrings.getString(dialogTitleKey), substitutions);
		String strMessage = MessageFormat.format(EclipseMEUIStrings.getString(messageKey), substitutions);
		
		ErrorDialog.openError(	s,
								strTitle,
								strMessage,
								status);
	}
	
	public static void displayError(Shell s, String dialogTitleKey, String messageKey, Exception e)
	{
		if (dialogTitleKey == null)
		{
			dialogTitleKey = MESSAGE_PREFIX+"Default";
		}
		
		if (messageKey == null)
		{
			messageKey = MESSAGE_PREFIX+"Default";
		}
		
		String[] substitutions = new String[] { e.getMessage() };
		
		String message = e.getMessage();
		if (message == null) message = "No Message";
		Status status = 
			new Status(IStatus.ERROR, IEclipseMEUIConstants.PLUGIN_ID, UI_ERROR_EXCEPTION, message, e);
		
		String strTitle = MessageFormat.format(EclipseMEUIStrings.getString(dialogTitleKey), substitutions);
		String strMessage = MessageFormat.format(EclipseMEUIStrings.getString(messageKey), substitutions);
		
		EclipseMEUIPlugin.getDefault().getLog().log(status);
		ErrorDialog.openError(	s,
								strTitle,
								strMessage,
								status);
	}
	
}


/*
 ********************************************************************
 *	CVS History:
 *	$Log: EclipseMEUIErrors.java,v $
 *	Revision 1.3  2005/07/08 21:47:10  setera
 *	Initial 1.1.0 changes:
 *	- Convert to manifest files for plugin.xml
 *	- Require JDT 3.1.0 for our feature
 *	- Fix up build files to include new manifest files
 *	- Fix up some of the deprecations
 *	
 *	Revision 1.2  2005/04/17 00:18:29  setera
 *	Add support for SonyEricsson version 2.2.0 toolkit (RFE 1174027)
 *	
 *	Revision 1.1  2004/12/12 18:32:35  kdhunter
 *	Improved mechanism for error message display
 *	
 *
 ********************************************************************
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -