001: package net.refractions.udig.tools.edit;
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.jface.resource.ImageDescriptor;
007: import org.eclipse.ui.plugin.AbstractUIPlugin;
008: import org.osgi.framework.BundleContext;
009:
010: /**
011: * The main plugin class to be used in the desktop.
012: */
013: public class EditPlugin extends AbstractUIPlugin {
014:
015: public static final String ID = "net.refractions.udig.tools.edit"; //$NON-NLS-1$
016: public static final String SELECTION = "net.refractions.udig.tools.edit/selection"; //$NON-NLS-1$
017: public static final String ACTIVATOR = "net.refractions.udig.tools.edit/activator"; //$NON-NLS-1$
018: public static final String HANDLER_LOCK = "net.refractions.udig.tools.edit/handler/lock"; //$NON-NLS-1$
019: public static final String BEHAVIOUR = "net.refractions.udig.tools.edit/behaviour"; //$NON-NLS-1$
020: public static final String RUN_ASSERTIONS = "net.refractions.udig.tools.edit/debug/assertions"; //$NON-NLS-1$
021: //The shared instance.
022: private static EditPlugin plugin;
023:
024: /**
025: * The constructor.
026: */
027: public EditPlugin() {
028: plugin = this ;
029: }
030:
031: /**
032: * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
033: */
034: public void start(BundleContext context) throws Exception {
035: super .start(context);
036: try {
037: } catch (Exception e) {
038: log("Error loading messages, check that file exists", e); //$NON-NLS-1$
039: }
040: }
041:
042: /**
043: * This method is called when the plug-in is stopped
044: */
045: public void stop(BundleContext context) throws Exception {
046: super .stop(context);
047: plugin = null;
048: }
049:
050: /**
051: * Returns the shared instance.
052: */
053: public static EditPlugin getDefault() {
054: return plugin;
055: }
056:
057: /**
058: * Returns an image descriptor for the image file at the given
059: * plug-in relative path.
060: *
061: * @param path the path
062: * @return the image descriptor
063: */
064: public static ImageDescriptor getImageDescriptor(String path) {
065: return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path);
066: }
067:
068: /**
069: * Writes an info log in the plugin's log.
070: * <p>
071: * This should be used for user level messages.
072: * </p>
073: * @param message
074: * @param e
075: */
076: public static void log(String message2, Throwable e) {
077: String message = message2;
078: if (message == null)
079: message = ""; //$NON-NLS-1$
080: getDefault().getLog().log(
081: new Status(IStatus.INFO, ID, 0, message, e));
082: }
083:
084: /**
085: * Messages that only engage if getDefault().isDebugging()
086: * <p>
087: * It is much prefered to do this:<pre><code>
088: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
089: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
090: * System.out.println( "your message here" );
091: *
092: */
093: public static void trace(String message, Throwable e) {
094: if (getDefault().isDebugging()) {
095: if (message != null)
096: System.out.println(message + "\n"); //$NON-NLS-1$
097: if (e != null)
098: e.printStackTrace(System.out);
099: }
100: }
101:
102: /**
103: * Messages that only engage if getDefault().isDebugging() and the trace option traceID is true.
104: * Available trace options can be found in the Trace class. (They must also be part of the .options file)
105: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
106: * System.out.println( "your message here" );
107: *
108: */
109: public static void trace(String traceID, String message, Throwable e) {
110: if (getDefault().isDebugging()) {
111: if (isDebugging(traceID)) {
112: if (message != null)
113: System.out.println(message + "\n"); //$NON-NLS-1$
114: if (e != null)
115: e.printStackTrace(System.out);
116: }
117: }
118: }
119:
120: /**
121: * Performs the Platform.getDebugOption true check on the provided trace
122: * @return true if this plugig is in your .options file
123: */
124: public static boolean isDebugging(final String trace) {
125: return getDefault().isDebugging()
126: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
127: }
128: }
|