blob: 40d25137feb703db6b0c3d092140b1390e84fae3 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.runtime;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.pde.internal.runtime.registry.PluginObjectAdapter;
import org.eclipse.pde.internal.runtime.registry.RegistryPropertySourceFactory;
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;
public class PDERuntimePlugin extends AbstractUIPlugin {
private static PDERuntimePlugin inst;
private ResourceBundle resourceBundle;
private BundleContext context;
public PDERuntimePlugin(IPluginDescriptor descriptor) {
super(descriptor);
inst = this;
try {
resourceBundle =
ResourceBundle.getBundle(
"org.eclipse.pde.internal.runtime.pderuntimeresources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
}
public static IWorkbenchPage getActivePage() {
return getDefault().internalGetActivePage();
}
public static Shell getActiveWorkbenchShell() {
return getActiveWorkbenchWindow().getShell();
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
public static PDERuntimePlugin getDefault() {
return inst;
}
/* package */
static IPath getInstallLocation() {
return new Path(getDefault().getDescriptor().getInstallURL().getFile());
}
public static String getPluginId() {
return getDefault().getDescriptor().getUniqueIdentifier();
}
public java.util.ResourceBundle getResourceBundle() {
return resourceBundle;
}
public static String getResourceString(String key) {
ResourceBundle bundle = inst.getResourceBundle();
if (bundle != null) {
try {
String bundleString = bundle.getString(key);
//return "$"+bundleString;
return bundleString;
} catch (MissingResourceException e) {
// default actions is to return key, which is OK
}
}
return key;
}
public static String getFormattedMessage(String key, String arg) {
String text = getResourceString(key);
return java.text.MessageFormat.format(text, new Object[] { arg });
}
private IWorkbenchPage internalGetActivePage() {
return getWorkbench().getActiveWorkbenchWindow().getActivePage();
}
public void startup() throws CoreException {
IAdapterManager manager = Platform.getAdapterManager();
RegistryPropertySourceFactory factory =
new RegistryPropertySourceFactory();
manager.registerAdapters(factory, PluginObjectAdapter.class);
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
this.context = context;
}
public BundleContext getBundleContext() {
return this.context;
}
}