Update of /cvsroot/easystruts/easyexplore-plugin/src/org/sf/easyexplore
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29640/src/org/sf/easyexplore
Added Files:
EasyExplorePlugin.java
Log Message:
major refactoring on this little puppy to get it OSGI compliant and have visbility enabled as needed....
--- NEW FILE: EasyExplorePlugin.java ---
package org.sf.easyexplore;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.sf.easyexplore.preferences.EasyExplorePreferencePage;
/**
* The main plugin class to be used in the desktop.
*/
public class EasyExplorePlugin extends AbstractUIPlugin {
//The shared instance.
private static EasyExplorePlugin plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
/**
* The constructor.
*/
public EasyExplorePlugin(IPluginDescriptor descriptor) {
super(descriptor);
plugin = this;
try {
resourceBundle= ResourceBundle.getBundle("org.sf.easyexplore.EasyExplorePluginResources");
} catch (MissingResourceException x) {
// throw new NullPointerException("unnable to load resources org.sf.easyexplore.EasyExplorePluginResources");
}
}
/**
* Returns the shared instance.
*/
public static EasyExplorePlugin getDefault() {
return plugin;
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
*/
public static String getResourceString(String key) {
ResourceBundle bundle= EasyExplorePlugin.getDefault().getResourceBundle();
String res = null;
try {
res = bundle.getString(key);
} catch (MissingResourceException e) {
res = key;
}
return res;
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
static public void log(Object msg) {
ILog log = EasyExplorePlugin.getDefault().getLog();
Status status = new Status(IStatus.INFO, EasyExplorePlugin.getDefault().getDescriptor().getUniqueIdentifier(), IStatus.ERROR, msg + "\n", null);
log.log(status);
}
static public void log(Throwable ex) {
ILog log = EasyExplorePlugin.getDefault().getLog();
StringWriter stringWriter = new StringWriter();
ex.printStackTrace(new PrintWriter(stringWriter));
String msg = stringWriter.getBuffer().toString();
Status status = new Status(IStatus.ERROR, EasyExplorePlugin.getDefault().getDescriptor().getUniqueIdentifier(), IStatus.ERROR, msg, null);
log.log(status);
}
/**
* @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
*/
protected void initializeDefaultPreferences(IPreferenceStore store) {
String defaultTarget = "shell_open_command {0}";
String osName = System.getProperty("os.name");
if ( osName.indexOf("Windows") != -1 ) {
defaultTarget = "explorer.exe {0}";
}
else if ( osName.indexOf("Mac") != -1 ) {
defaultTarget = "open {0}";
}
store.setDefault(EasyExplorePreferencePage.P_TARGET, defaultTarget);
}
/**
* Return the target program setted in EasyExplorePreferencePage.
* @return String
*/
public String getTarget() {
return getPreferenceStore().getString(EasyExplorePreferencePage.P_TARGET);
}
/**
* Tells whether this platform is currently supported.
* The implementation of this method must be in sync with the implementation of
* <a href="#initializeDefaultPreferences(IPreferenceStore)">initializeDefaultPreferences(IPreferenceStore)</a>.
*/
public boolean isSupported() {
String osName = System.getProperty("os.name");
return (( osName.indexOf("Windows") != -1 )
|| ( osName.indexOf("Mac") != -1 ));
}
}
|