001: package net.refractions.udig.tool.info;
002:
003: import org.eclipse.core.runtime.IStatus;
004: import org.eclipse.core.runtime.Platform;
005: import org.eclipse.core.runtime.Status;
006: import org.eclipse.ui.plugin.AbstractUIPlugin;
007: import org.osgi.framework.BundleContext;
008:
009: /**
010: * Plugin for UDIG Information facilities.
011: * <p>
012: * Information services is provided by:
013: * <ul>
014: * <li>InfoTool - a modal tool for the Map editor
015: * <li>InfoView - a view used to display the results of the last information request
016: * <li>InfoDisplay - allows tool to display new types of content
017: * </ul>
018: * </p>
019: * <p>
020: * Programatic access to the current information is not currently provided as part
021: * of the public API. If you are interested in this please let us know and it can
022: * be moved over.
023: * </p>
024: */
025: public class InfoPlugin extends AbstractUIPlugin {
026: //The shared instance.
027: private static InfoPlugin plugin;
028:
029: public static final String ID = "net.refractions.udig.tool.info"; //$NON-NLS-1$
030:
031: /**
032: * The constructor.
033: */
034: public InfoPlugin() {
035: super ();
036: plugin = this ;
037: }
038:
039: public void start(BundleContext context) throws Exception {
040: super .start(context);
041: }
042:
043: public void stop(BundleContext context) throws Exception {
044: plugin = null;
045: super .stop(context);
046: }
047:
048: /**
049: * Access shared InfoPlugin instance.
050: *
051: * @return Shared Instance
052: */
053: public static InfoPlugin getDefault() {
054: return plugin;
055: }
056:
057: /**
058: * Writes an info log in the plugin's log.
059: * <p>
060: * This should be used for user level messages.
061: * </p>
062: */
063: public static void log(String message, Throwable e) {
064: getDefault().getLog().log(
065: new Status(IStatus.INFO, ID, 0, message, e));
066: }
067:
068: /**
069: * Messages that only engage if getDefault().isDebugging()
070: * <p>
071: * It is much prefered to do this:<pre><code>
072: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
073: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
074: * System.out.println( "your message here" );
075: * }
076: */
077: public static void trace(String message, Throwable e) {
078: if (getDefault().isDebugging()) {
079: if (message != null)
080: System.out.println(message);
081: if (e != null)
082: e.printStackTrace();
083: }
084: }
085:
086: /**
087: * Performs the Platform.getDebugOption true check on the provided trace
088: * <p>
089: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
090: * <ul>
091: * <li>Trace.RENDER - trace rendering progress
092: * </ul>
093: * </p>
094: * @param trace currently only RENDER is defined
095: */
096: public static boolean isDebugging(final String trace) {
097: return getDefault().isDebugging()
098: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
099: }
100: }
|