blob: 06a2f006a5d7d979ea7bf588a81c54d4f34de6b0 [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.welcome.internal;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.dialogs.*;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.*;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.welcome.internal.webbrowser.*;
/**
* The main plugin class to be used in the desktop.
*/
public class WelcomePortal extends AbstractUIPlugin {
public static final String PLUGIN_ID = "org.eclipse.update.ui.win32";
public static final String ID_BROWSER = PLUGIN_ID + "WebBrowser";
//The shared instance.
private static WelcomePortal plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
/* (non-Javadoc)
* @see org.eclipse.ui.IStartup#earlyStartup()
*/
public static void showURL(String name, String url) {
try {
WelcomePortal.getActivePage().openEditor(
new WebBrowserEditorInput(name, url),
"org.eclipse.welcome.webbrowser");
} catch (PartInitException e) {
WelcomePortal.logException(e);
}
}
/**
* The constructor.
*/
public WelcomePortal(IPluginDescriptor descriptor) {
super(descriptor);
plugin = this;
try {
resourceBundle =
ResourceBundle.getBundle(
"org.eclipse.welcome.internal.WelcomePortalResources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
}
/**
* Returns the shared instance.
*/
public static WelcomePortal getDefault() {
return plugin;
}
public static IWorkbenchPage getActivePage() {
return getDefault().internalGetActivePage();
}
private IWorkbenchPage internalGetActivePage() {
IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
if (window != null)
return window.getActivePage();
return null;
}
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getActiveWorkbenchWindow();
return window != null ? window.getShell() : null;
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
public static String getPluginId() {
return getDefault().getDescriptor().getUniqueIdentifier();
}
/**
* 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 getString(String key) {
ResourceBundle bundle = WelcomePortal.getDefault().getResourceBundle();
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
return key;
}
}
public static String getFormattedMessage(String key, String[] args) {
String text = getString(key);
return java.text.MessageFormat.format(text, args);
}
public static String getFormattedMessage(String key, String arg) {
String text = getString(key);
return java.text.MessageFormat.format(text, new String[] { arg });
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
public void startup() throws CoreException {
}
public void shutdown() throws CoreException {
}
public static void logException(Throwable e) {
logException(e, true);
}
public static void logException(Throwable e, boolean showErrorDialog) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
IStatus status = null;
if (e instanceof CoreException) {
status = ((CoreException) e).getStatus();
} else {
String message = e.getMessage();
if (message == null)
message = e.toString();
status =
new Status(
IStatus.ERROR,
getPluginId(),
IStatus.OK,
message,
e);
}
log(status, showErrorDialog);
}
public static void log(IStatus status, boolean showErrorDialog) {
if (status.getSeverity() != IStatus.INFO) {
if (showErrorDialog)
ErrorDialog.openError(
getActiveWorkbenchShell(),
null,
null,
status);
//ResourcesPlugin.getPlugin().getLog().log(status);
Platform.getPlugin("org.eclipse.core.runtime").getLog().log(status);
} else {
MessageDialog.openInformation(
getActiveWorkbenchShell(),
null,
status.getMessage());
}
}
}