001: package net.refractions.udig.validation;
002:
003: import java.net.URL;
004:
005: import org.eclipse.ui.plugin.*;
006: import org.eclipse.core.runtime.IStatus;
007: import org.eclipse.core.runtime.Platform;
008: import org.eclipse.core.runtime.Status;
009: import org.eclipse.jface.resource.ImageDescriptor;
010: import org.osgi.framework.BundleContext;
011:
012: /**
013: * The main plugin class to be used in the desktop.
014: */
015: public class ValidationPlugin extends AbstractUIPlugin {
016:
017: private static ValidationPlugin plugin;
018: private Images images = new Images();
019: private static final String ID = "net.refractions.udig.validation"; //$NON-NLS-1$
020: public final static String ICONS_PATH = "icons/";//$NON-NLS-1$
021:
022: /**
023: * The constructor.
024: */
025: public ValidationPlugin() {
026: plugin = this ;
027: }
028:
029: /**
030: * This method is called upon plug-in activation
031: */
032: public void start(BundleContext context) throws Exception {
033: super .start(context);
034: final URL iconsUrl = context.getBundle().getEntry(ICONS_PATH);
035: images.initializeImages(iconsUrl, getImageRegistry());
036: }
037:
038: /**
039: * This method is called when the plug-in is stopped
040: */
041: public void stop(BundleContext context) throws Exception {
042: super .stop(context);
043: plugin = null;
044: }
045:
046: /**
047: * Returns the shared instance.
048: */
049: public static ValidationPlugin getDefault() {
050: return plugin;
051: }
052:
053: /**
054: * Returns an image descriptor for the image file at the given
055: * plug-in relative path.
056: *
057: * @param path the path
058: * @return the image descriptor
059: */
060: public static ImageDescriptor getImageDescriptor(String path) {
061: return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path);
062: }
063:
064: /**
065: * Writes an info log in the plugin's log.
066: * @param message
067: */
068: public static void log(String message) {
069: log(message, null);
070: }
071:
072: /**
073: * Writes an info log in the plugin's log.
074: * <p>
075: * This should be used for user level messages.
076: * </p>
077: */
078: public static void log(String message, Throwable e) {
079: getDefault().getLog().log(
080: new Status(IStatus.INFO, ID, 0,
081: message == null ? "" : message, e)); //$NON-NLS-1$
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);
097: if (e != null)
098: e.printStackTrace();
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: * <p>
106: * It is much prefered to do this:<pre><code>
107: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
108: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
109: * System.out.println( "your message here" );
110: *
111: */
112: public static void trace(String traceID, String message, Throwable e) {
113: if (getDefault().isDebugging()) {
114: if (isDebugging(traceID)) {
115: if (message != null)
116: System.out.println(message);
117: if (e != null)
118: e.printStackTrace();
119: }
120: }
121: }
122:
123: /**
124: * Performs the Platform.getDebugOption true check on the provided trace
125: * <p>
126: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
127: * <ul>
128: * <li>Trace.RENDER - trace rendering progress
129: * </ul>
130: * </p>
131: *
132: * @param trace currently only RENDER is defined
133: */
134: public static boolean isDebugging(final String trace) {
135: return getDefault().isDebugging()
136: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
137:
138: }
139:
140: /**
141: * Images instance for use with ImageConstants.
142: *
143: * @return Images for use with ImageConstants.
144: */
145: public Images getImages() {
146: return images;
147: }
148:
149: }
|