diff options
Diffstat (limited to 'rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/rpm/ui/RPMUIPlugin.java')
-rw-r--r-- | rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/rpm/ui/RPMUIPlugin.java | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/rpm/ui/RPMUIPlugin.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/rpm/ui/RPMUIPlugin.java new file mode 100644 index 0000000000..8838b981ef --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/rpm/ui/RPMUIPlugin.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2005-2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.rpm.ui; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class RPMUIPlugin extends AbstractUIPlugin { + //The shared instance. + private static RPMUIPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + public static final String ID = "org.eclipse.linuxtools.rpm.ui"; //$NON-NLS-1$ + + /** + * The constructor. + */ + public RPMUIPlugin() { + super(); + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + @Override + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + resourceBundle = null; + } + + /** + * Returns the shared instance. + */ + public static RPMUIPlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, + * or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = RPMUIPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + try { + if (resourceBundle == null) + resourceBundle = ResourceBundle.getBundle("rpmui.RpmuiPluginResources"); //$NON-NLS-1$ + } catch (MissingResourceException x) { + resourceBundle = null; + } + return resourceBundle; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path. + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return AbstractUIPlugin.imageDescriptorFromPlugin("rpmui", path); //$NON-NLS-1$ + } + + public void log(Throwable e) { + log(new Status(IStatus.ERROR, ID, IStatus.ERROR, "Error", e)); //$NON-NLS-1$ + } + + public void log(IStatus status) { + getLog().log(status); + } + + public void logErrorMessage(String message) { + log(new Status(IStatus.ERROR, ID, 1, message, null)); + } + + public static Shell getActiveWorkbenchShell() { + IWorkbenchWindow window= getActiveWorkbenchWindow(); + if (window != null) { + return window.getShell(); + } + return null; + } + + public static IWorkbenchWindow getActiveWorkbenchWindow() { + return getDefault().getWorkbench().getActiveWorkbenchWindow(); + } +} |