001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2005, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.catalog.db2;
018:
019: import java.util.logging.Level;
020: import java.util.logging.Logger;
021:
022: import org.eclipse.core.runtime.IStatus;
023: import org.eclipse.core.runtime.Platform;
024: import org.eclipse.core.runtime.Status;
025: import org.eclipse.jface.resource.ImageDescriptor;
026: import org.eclipse.ui.plugin.AbstractUIPlugin;
027: import org.geotools.data.db2.DB2DataStoreFactory;
028: import org.osgi.framework.BundleContext;
029:
030: /**
031: * The main plugin class to be used in the desktop.
032: */
033: public class DB2Plugin extends AbstractUIPlugin {
034:
035: /** id of plugin, matches id decalred in plugin.xml * */
036: public static final String ID = "net.refractions.udig.catalog.db2"; //$NON-NLS-1$
037:
038: // The shared instance.
039: private static DB2Plugin plugin;
040:
041: /**
042: * The constructor.
043: */
044: public DB2Plugin() {
045: super ();
046: plugin = this ;
047: }
048:
049: /**
050: * This method is called upon plug-in activation
051: */
052: public void start(BundleContext context) throws Exception {
053: super .start(context);
054: ClassLoader loader = Thread.currentThread()
055: .getContextClassLoader();
056: try {
057: Thread.currentThread().setContextClassLoader(
058: DB2DataStoreFactory.class.getClassLoader());
059: Logger
060: .getLogger("org.geotools.data.db2").setLevel(Level.SEVERE); //$NON-NLS-1$
061: } finally {
062: Thread.currentThread().setContextClassLoader(loader);
063: }
064:
065: }
066:
067: /**
068: * This method is called when the plug-in is stopped
069: */
070: public void stop(BundleContext context) throws Exception {
071: super .stop(context);
072: plugin = null;
073: }
074:
075: /**
076: * Returns the shared instance.
077: */
078: public static DB2Plugin getDefault() {
079: return plugin;
080: }
081:
082: /**
083: * Returns an image descriptor for the image file at the given plug-in relative path.
084: *
085: * @param path the path
086: * @return the image descriptor
087: */
088: public static ImageDescriptor getImageDescriptor(String path) {
089: return AbstractUIPlugin.imageDescriptorFromPlugin(
090: "net.refractions.udig.catalog.db2", path); //$NON-NLS-1$
091: }
092:
093: /**
094: * Logs the Throwable in the plugin's log.
095: * <p>
096: * This will be a user visable ERROR iff:
097: * <ul>
098: * <li>t is an Exception we are assuming it is human readable or if a message is provided
099: */
100: public static void log(String message, Throwable t) {
101: if (message == null)
102: message = ""; //$NON-NLS-1$
103: int status = t instanceof Exception || message != null ? IStatus.ERROR
104: : IStatus.WARNING;
105: getDefault().getLog().log(
106: new Status(status, ID, IStatus.OK, message, t));
107: }
108:
109: /**
110: * Messages that only engage if getDefault().isDebugging()
111: * <p>
112: * It is much prefered to do this:
113: *
114: * <pre><code>
115: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
116: * if (ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase(RENDERING)) {
117: * System.out.println("your message here");
118: * }
119: *
120: */
121: public static void trace(String message, Throwable e) {
122: if (getDefault().isDebugging()) {
123: if (message != null)
124: System.out.println(message);
125: if (e != null)
126: e.printStackTrace();
127: }
128: }
129:
130: /**
131: * Performs the Platform.getDebugOption true check on the provided trace
132: * <p>
133: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
134: * <ul>
135: * <li>Trace.RENDER - trace rendering progress
136: * </ul>
137: * </p>
138: *
139: * @param trace currently only RENDER is defined
140: */
141: public static boolean isDebugging(final String trace) {
142: return getDefault().isDebugging()
143: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
144: }
145: }
|