001: /*******************************************************************************
002: * Copyright (c) 2005 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.ui.tests.navigator;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.core.runtime.Status;
014: import org.eclipse.ui.plugin.AbstractUIPlugin;
015:
016: /**
017: *
018: * Not exposed as API.
019: * @since 3.2
020: *
021: */
022: public class NavigatorTestsPlugin extends AbstractUIPlugin {
023:
024: //The shared instance.
025: private static NavigatorTestsPlugin plugin;
026: /**
027: * The plugin id
028: */
029: public static String PLUGIN_ID = "org.eclipse.ui.tests.navigator"; //$NON-NLS-1$
030:
031: /**
032: * Creates a new instance of the receiver
033: */
034: public NavigatorTestsPlugin() {
035: super ();
036: plugin = this ;
037: }
038:
039: /**
040: * Returns the shared instance.
041: */
042: public static NavigatorTestsPlugin getDefault() {
043: return plugin;
044: }
045:
046: /**
047: * Log the given status to the ISV log.
048: *
049: * When to use this:
050: *
051: * This should be used when a PluginException or a ExtensionException occur but for which an
052: * error dialog cannot be safely shown.
053: *
054: * If you can show an ErrorDialog then do so, and do not call this method.
055: *
056: * If you have a plugin exception or core exception in hand call log(String, IStatus)
057: *
058: * This convenience method is for internal use by the Workbench only and must not be called
059: * outside the workbench.
060: *
061: * This method is supported in the event the log allows plugin related information to be logged
062: * (1FTTJKV). This would be done by this method.
063: *
064: * This method is internal to the workbench and must not be called by any plugins, or examples.
065: *
066: * @param message
067: * A high level UI message describing when the problem happened.
068: *
069: */
070:
071: public static void log(String message) {
072: getDefault().getLog().log(
073: new Status(IStatus.ERROR, PLUGIN_ID, 0, message, null));
074: System.err.println(message);
075: //1FTTJKV: ITPCORE:ALL - log(status) does not allow plugin information to be recorded
076: }
077:
078: /**
079: * Logs errors.
080: */
081: public static void log(String message, IStatus status) {
082: if (message != null) {
083: getDefault().getLog().log(
084: new Status(IStatus.ERROR, PLUGIN_ID, 0, message,
085: null));
086: System.err.println(message + "\nReason:"); //$NON-NLS-1$
087: }
088: getDefault().getLog().log(status);
089: System.err.println(status.getMessage());
090: }
091:
092: public static void logError(int aCode, String aMessage,
093: Throwable anException) {
094: getDefault().getLog().log(
095: createErrorStatus(aCode, aMessage, anException));
096: }
097:
098: public static void log(int severity, int aCode, String aMessage,
099: Throwable exception) {
100: log(createStatus(severity, aCode, aMessage, exception));
101: }
102:
103: public static void log(IStatus aStatus) {
104: getDefault().getLog().log(aStatus);
105: }
106:
107: public static IStatus createStatus(int severity, int aCode,
108: String aMessage, Throwable exception) {
109: return new Status(severity, PLUGIN_ID, aCode, aMessage,
110: exception);
111: }
112:
113: public static IStatus createErrorStatus(int aCode, String aMessage,
114: Throwable exception) {
115: return createStatus(IStatus.ERROR, aCode, aMessage, exception);
116: }
117: }
|