blob: 57d8bd4217f74fed68795a98920747de300ad310 [file] [log] [blame]
package org.eclipse.wst.xsl.internal.debug.ui;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class XSLDebugUIPlugin extends AbstractUIPlugin
{
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.wst.xsl.debug.ui";
// The shared instance
private static XSLDebugUIPlugin plugin;
public XSLDebugUIPlugin()
{
plugin = this;
}
@Override
public void start(BundleContext context) throws Exception
{
super.start(context);
}
@Override
public void stop(BundleContext context) throws Exception
{
plugin = null;
super.stop(context);
}
public static XSLDebugUIPlugin getDefault()
{
return plugin;
}
public static ImageDescriptor getImageDescriptor(String path)
{
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
public static void showPreferencePage(String id, IPreferencePage page)
{
final IPreferenceNode targetNode = new PreferenceNode(id, page);
PreferenceManager manager = new PreferenceManager();
manager.addToRoot(targetNode);
final PreferenceDialog dialog = new PreferenceDialog(XSLDebugUIPlugin.getActiveWorkbenchShell(), manager);
final boolean[] result = new boolean[]
{ false };
BusyIndicator.showWhile(XSLDebugUIPlugin.getStandardDisplay(), new Runnable()
{
public void run()
{
dialog.create();
dialog.setMessage(targetNode.getLabelText());
result[0] = (dialog.open() == Window.OK);
}
});
}
public static Display getStandardDisplay()
{
Display display;
display = Display.getCurrent();
if (display == null)
display = Display.getDefault();
return display;
}
public static IWorkbenchWindow getActiveWorkbenchWindow()
{
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
public static Shell getActiveWorkbenchShell()
{
IWorkbenchWindow window = getActiveWorkbenchWindow();
if (window != null)
{
return window.getShell();
}
return null;
}
public static IWorkbenchPage getActivePage()
{
IWorkbenchWindow w = getActiveWorkbenchWindow();
if (w != null)
{
return w.getActivePage();
}
return null;
}
public static void log(Exception e)
{
getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, 0, "", e));
}
public static void log(CoreException e)
{
getDefault().getLog().log(e.getStatus());
}
}