View Javadoc

1   package org.eparapher.rcp;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.net.MalformedURLException;
6   import java.net.URL;
7   import java.util.PropertyResourceBundle;
8   
9   import org.apache.log4j.Logger;
10  import org.eclipse.core.runtime.FileLocator;
11  import org.eclipse.core.runtime.Path;
12  import org.eclipse.core.runtime.Platform;
13  import org.eclipse.core.runtime.Status;
14  import org.eclipse.jface.resource.ImageDescriptor;
15  import org.eclipse.ui.plugin.AbstractUIPlugin;
16  import org.eparapher.rcp.tools.RCPSettings;
17  import org.osgi.framework.BundleContext;
18  
19  /**
20   * The activator class controls the plug-in life cycle
21   */
22  public class Activator extends AbstractUIPlugin {
23  
24  	/** The plugin properties */
25      private PropertyResourceBundle properties;
26      
27  	//private static Logger log = Logger.getLogger(Activator.class);
28  
29  	// The shared instance
30  	private static Activator plugin;
31  	
32  	/**
33  	 * The constructor
34  	 */
35  	public Activator() {
36  		plugin = this;
37  	}
38  
39  	/*
40  	 * (non-Javadoc)
41  	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
42  	 */
43  	@SuppressWarnings("deprecation")
44  	public void start(BundleContext context) throws Exception {
45  		/*URL url = null;
46  		try {
47  			String configdir = EPConfig.getEParapherAppDirectory();
48  			url = new File(configdir).toURL();
49  			Platform.getInstanceLocation().setURL(url, true);
50  		} catch (IllegalStateException e) {
51  			log.fatal("Fatal error while setting eParapher workspace directory ("+url+")", e);
52  		} catch (MalformedURLException e) {
53  			log.fatal("Fatal error while setting eParapher workspace directory ("+url+")", e);
54  		}*/
55  		super.start(context);
56  	}
57  
58  	/*
59  	 * (non-Javadoc)
60  	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
61  	 */
62  	public void stop(BundleContext context) throws Exception {
63  		plugin = null;
64  		super.stop(context);
65  	}
66  
67  	/**
68  	 * Returns the shared instance
69  	 *
70  	 * @return the shared instance
71  	 */
72  	public static Activator getDefault() {
73  		return plugin;
74  	}
75  
76  	/**
77  	 * Returns an image descriptor for the image file at the given
78  	 * plug-in relative path
79  	 *
80  	 * @param path the path
81  	 * @return the image descriptor
82  	 */
83  	public static ImageDescriptor getImageDescriptor(String path) {
84  		return imageDescriptorFromPlugin(Application.PLUGIN_ID, path);
85  	}
86  
87      /**
88       * Gets the plugin properties.
89       *
90       * @return
91       *      the plugin properties
92       */
93      public PropertyResourceBundle getPluginProperties()
94      {
95          if ( properties == null )
96          {
97              try
98              {
99                  properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path(
100                     "plugin.properties" ), false ) );
101             }
102             catch ( IOException e )
103             {
104                 // We can't use the PLUGIN_ID constant since loading the plugin.properties file has failed,
105                 // So we're using a default plugin id.
106                 getLog().log(
107                     new Status( Status.ERROR, "org.eparapher.rcp", Status.OK,
108                         "Unable to get the plugin properties.", e ) );
109             }
110         }
111 
112         return properties;
113     }
114 }