/*******************************************************************************
* Copyright (c) 2004, 2007 Spring IDE Developers
* 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:
* Spring IDE Developers - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.beans.ui.graph;
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.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
* Central access point for the Spring Framework Editor plug-in
* (id <code>"org.springframework.ide.eclipse.beans.ui.graph"</code>).
* @author Torsten Juergeleit
* @author Christian Dupuis
*/
public class BeansGraphPlugin extends AbstractUIPlugin {
/**
* Plugin identifier for Spring UI Graph (value
* <code>org.springframework.ide.eclipse.beans.ui.graph</code>).
*/
public static final String PLUGIN_ID =
"org.springframework.ide.eclipse.beans.ui.graph";
private static final String RESOURCE_NAME = PLUGIN_ID + ".messages";
//The shared instance.
private static BeansGraphPlugin plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
/**
* Creates the Spring Beans Graph plug-in.
* <p>
* The plug-in instance is created automatically by the Eclipse platform.
* Clients must not call.
*/
public BeansGraphPlugin() {
plugin = this;
try {
resourceBundle = ResourceBundle.getBundle(RESOURCE_NAME);
} catch (MissingResourceException e) {
log(e);
resourceBundle = null;
}
}
/**
* Returns the shared instance.
*/
public static BeansGraphPlugin 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 = BeansGraphPlugin.getDefault().getResourceBundle();
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
return key;
}
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
/**
* Writes the message to the plug-in's log
*
* @param message the text to write to the log
*/
public static void log(String message, Throwable exception) {
IStatus status = createErrorStatus(message, exception);
getDefault().getLog().log(status);
}
public static void log(Throwable exception) {
getDefault().getLog().log(createErrorStatus(
getResourceString("Plugin.internal_error"), exception));
}
/**
* Returns a new <code>IStatus</code> for this plug-in
*/
public static IStatus createErrorStatus(String message) {
if (message == null) {
message= "";
}
return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, null);
}
/**
* Returns a new <code>IStatus</code> for this plug-in
*/
public static IStatus createErrorStatus(String message,
Throwable exception) {
if (message == null) {
message= "";
}
return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, exception);
}
}