From 093697a0167b5b9bb0287baa0dd38547a976f1e5 Mon Sep 17 00:00:00 2001
From: William R. Swanson
Date: Fri, 10 Feb 2012 13:10:03 -0500
Subject: Bug 335027: Visualizer View feature. Initial contribution.
---
.../org.eclipse.cdt.visualizer.core/.classpath | 8 +
.../org.eclipse.cdt.visualizer.core/.project | 28 +++
.../.settings/org.eclipse.jdt.core.prefs | 8 +
.../org.eclipse.cdt.visualizer.core/ABOUT.txt | 17 ++
.../META-INF/MANIFEST.MF | 15 ++
.../org.eclipse.cdt.visualizer.core/about.html | 24 +++
.../build.properties | 17 ++
.../plugin.properties | 17 ++
visualizer/org.eclipse.cdt.visualizer.core/pom.xml | 17 ++
.../resources/messages.properties | 14 ++
.../org/eclipse/cdt/visualizer/core/Extension.java | 92 ++++++++++
.../cdt/visualizer/core/ExtensionElement.java | 160 +++++++++++++++++
.../cdt/visualizer/core/ResourceManager.java | 195 +++++++++++++++++++++
.../core/plugin/CDTVisualizerCorePlugin.java | 126 +++++++++++++
14 files changed, 738 insertions(+)
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/.classpath
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/.project
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/.settings/org.eclipse.jdt.core.prefs
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/ABOUT.txt
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/META-INF/MANIFEST.MF
create mode 100644 visualizer/org.eclipse.cdt.visualizer.core/about.html
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/build.properties
create mode 100644 visualizer/org.eclipse.cdt.visualizer.core/plugin.properties
create mode 100644 visualizer/org.eclipse.cdt.visualizer.core/pom.xml
create mode 100644 visualizer/org.eclipse.cdt.visualizer.core/resources/messages.properties
create mode 100644 visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java
create mode 100755 visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java
(limited to 'visualizer/org.eclipse.cdt.visualizer.core')
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/.classpath b/visualizer/org.eclipse.cdt.visualizer.core/.classpath
new file mode 100755
index 00000000000..31db9a91174
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/.project b/visualizer/org.eclipse.cdt.visualizer.core/.project
new file mode 100755
index 00000000000..77747f8e3ea
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/.project
@@ -0,0 +1,28 @@
+
+
+ org.eclipse.cdt.visualizer.core
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/.settings/org.eclipse.jdt.core.prefs b/visualizer/org.eclipse.cdt.visualizer.core/.settings/org.eclipse.jdt.core.prefs
new file mode 100755
index 00000000000..743b93d39ff
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Fri Jul 01 09:20:33 EDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/ABOUT.txt b/visualizer/org.eclipse.cdt.visualizer.core/ABOUT.txt
new file mode 100755
index 00000000000..ad3ea21360a
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/ABOUT.txt
@@ -0,0 +1,17 @@
+# =============================================================================
+# Copyright (c) 2012 Tilera Corporation and others.
+# 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:
+# William R. Swanson (Tilera Corporation)
+# =============================================================================
+
+This plugin defines the non-UI components of the CDT Visualizer feature.
+
+For an overview of the Visualizer feature, see the following file:
+
+ /org.eclipse.cdt.visualizer-feature/ABOUT.txt.
+
\ No newline at end of file
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/META-INF/MANIFEST.MF b/visualizer/org.eclipse.cdt.visualizer.core/META-INF/MANIFEST.MF
new file mode 100755
index 00000000000..6fec5fa40a4
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %plugin.name
+Bundle-SymbolicName: org.eclipse.cdt.visualizer.core;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.cdt.visualizer.core.plugin.CDTVisualizerCorePlugin
+Bundle-Vendor: %provider.name
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
+Export-Package: org.eclipse.cdt.visualizer.core,
+ org.eclipse.cdt.visualizer.core.plugin
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/about.html b/visualizer/org.eclipse.cdt.visualizer.core/about.html
new file mode 100644
index 00000000000..cb740ae8bc8
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/about.html
@@ -0,0 +1,24 @@
+
+
+
+
+About
+About This Content
+
+June 5, 2007
+License
+
+The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at http://www.eclipse.org/legal/epl-v10.html.
+For purposes of the EPL, "Program" will mean the Content.
+
+If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at http://www.eclipse.org.
+
+
\ No newline at end of file
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/build.properties b/visualizer/org.eclipse.cdt.visualizer.core/build.properties
new file mode 100755
index 00000000000..07409e935ad
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/build.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2012 Tilera Corporation and others.
+# 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:
+# William R. Swanson (Tilera Corporation)
+###############################################################################
+source.. = src/,\
+ resources/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.properties,\
+ about.html
\ No newline at end of file
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/plugin.properties b/visualizer/org.eclipse.cdt.visualizer.core/plugin.properties
new file mode 100644
index 00000000000..43181240cd1
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/plugin.properties
@@ -0,0 +1,17 @@
+# =============================================================================
+# Copyright (c) 2012 Tilera Corporation and others.
+# 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:
+# William R. Swanson (Tilera Corporation)
+# =============================================================================
+
+# -----------------------------------------------------------------------------
+# Plugin string resources
+# -----------------------------------------------------------------------------
+
+plugin.name=CDT Visualizer Core Plug-in
+provider.name=Eclipse CDT
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/pom.xml b/visualizer/org.eclipse.cdt.visualizer.core/pom.xml
new file mode 100644
index 00000000000..bde189daa95
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/pom.xml
@@ -0,0 +1,17 @@
+
+
+ 4.0.0
+
+
+ org.eclipse.cdt
+ cdt-parent
+ 8.1.0-SNAPSHOT
+ ../../pom.xml
+
+
+ 1.0.0-SNAPSHOT
+ org.eclipse.cdt.visualizer.core
+ eclipse-plugin
+
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/resources/messages.properties b/visualizer/org.eclipse.cdt.visualizer.core/resources/messages.properties
new file mode 100644
index 00000000000..70fa2ec9226
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/resources/messages.properties
@@ -0,0 +1,14 @@
+# =============================================================================
+# Copyright (c) 2012 Tilera Corporation and others.
+# 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:
+# William R. Swanson (Tilera Corporation)
+# =============================================================================
+
+# -----------------------------------------------------------------------------
+# Application string resources
+# -----------------------------------------------------------------------------
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java
new file mode 100644
index 00000000000..10aac2651c2
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tilera Corporation and others.
+ * 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:
+ * William R. Swanson (Tilera Corporation)
+ *******************************************************************************/
+
+package org.eclipse.cdt.visualizer.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+
+
+// ---------------------------------------------------------------------------
+// Extension
+// ---------------------------------------------------------------------------
+
+/** Facade/utility class for dealing with Eclipse extensions. */
+public class Extension extends ExtensionElement
+{
+ // --- static methods ---
+
+ /** Gets extension point declaration with specified full ID (including plugin ID prefix). */
+ public static IExtensionPoint getExtensionPoint(String extensionPointID)
+ {
+ IExtensionPoint extensionPoint =
+ Platform.getExtensionRegistry().getExtensionPoint(
+ extensionPointID);
+ return extensionPoint;
+ }
+
+ /** Gets extension point declaration with specified name defined by specified plugin. */
+ public static IExtensionPoint getExtensionPoint(String pluginID, String extensionPointName)
+ {
+ IExtensionPoint extensionPoint =
+ Platform.getExtensionRegistry().getExtensionPoint(
+ pluginID, extensionPointName);
+ return extensionPoint;
+ }
+
+ /** Gets list of extensions for specified extension point ID (including plugin ID prefix). */
+ public static List getExtensions(String extensionPointID)
+ {
+ IExtensionPoint extensionPoint = getExtensionPoint(extensionPointID);
+ return getExtensions(extensionPoint);
+ }
+
+ /** Gets list of extensions for specified plugin and extension point name. */
+ public static List getExtensions(String pluginID, String extensionPointName)
+ {
+ IExtensionPoint extensionPoint = getExtensionPoint(pluginID, extensionPointName);
+ return getExtensions(extensionPoint);
+ }
+
+ /** Gets list of extensions for specified plugin and extension point name. */
+ public static List getExtensions(IExtensionPoint extensionPoint)
+ {
+ return (extensionPoint == null) ? null :
+ Extension.wrapExtensions(extensionPoint.getConfigurationElements());
+ }
+
+ /** Wraps list of raw extension declarations. */
+ public static List wrapExtensions(IConfigurationElement[] elements)
+ {
+ int count = (elements == null) ? 0 : elements.length;
+ List result = new ArrayList(count);
+ for (int i=0; i wrapExtensionElements(IConfigurationElement[] elements)
+ {
+ int count = (elements == null) ? 0 : elements.length;
+ List result = new ArrayList(count);
+ for (int i=0; i T getClassAttribute()
+ {
+ return getClassAttribute("class");
+ }
+
+ /** Creates and returns instance of implementing class, using class name found in specified attribute. */
+ @SuppressWarnings("unchecked")
+ public T getClassAttribute(String attributeName)
+ {
+ T result = null;
+ try {
+ // TODO: Hmm... is there a right way to do this, without an unchecked cast?
+ result = (T) m_element.createExecutableExtension(attributeName);
+ }
+ catch (ClassCastException ex) {
+ // For now, eat it, and don't return this extension.
+ // TODO: decide how to log this
+ }
+ catch (CoreException ex) {
+ // For now, eat it, and don't return this extension.
+ // TODO: decide how to log this
+ }
+ return result;
+ }
+
+ /** Creates and returns instance of implementing class, using class name found in specified attribute. */
+ @SuppressWarnings("unchecked")
+ public T getClassAttribute(String attributeName, Object... arguments)
+ {
+ // Make sure we default to zero-argument form if we can.
+ if (arguments == null || arguments.length == 0)
+ return getClassAttribute(attributeName);
+
+ // If we have arguments, have to do a little extra work.
+ T result = null;
+ try {
+ // Get name of class we're trying to load from attribute.
+ String className = getAttribute(attributeName);
+
+ // Attempt to load class using the source plugin's class loader.
+ // TODO: is there a better way?
+ IContributor contributor = m_element.getContributor();
+ String pluginID = contributor.getName();
+ Bundle plugin = Platform.getBundle(pluginID);
+ Class> instance = plugin.loadClass(className);
+
+ // Select appropriate constructor for provided argument(s).
+ int argumentsLength = (arguments == null) ? 0 : arguments.length;
+ Class>[] argumentTypes = new Class>[argumentsLength];
+ for (int i=0; i constructor = (Constructor>)
+ instance.getConstructor(argumentTypes);
+
+ // Invoke the constructor.
+ result = (T) constructor.newInstance(arguments);
+ }
+ catch (ClassNotFoundException ex) {
+ // TODO: decide how to log this
+ }
+ catch (NoSuchMethodException ex) {
+ // TODO: decide how to log this
+ }
+ catch (InvocationTargetException ex) {
+ // TODO: decide how to log this
+ }
+ catch (IllegalAccessException ex) {
+ // TODO: decide how to log this
+ }
+ catch (InstantiationException ex) {
+ // TODO: decide how to log this
+ }
+ catch (ClassCastException ex) {
+ // TODO: decide how to log this
+ }
+ catch (Exception ex) {
+ // TODO: decide how to log this
+ }
+ return result;
+ }
+
+ /** Returns child elements of this element. */
+ public List getChildren()
+ {
+ return wrapExtensionElements(m_element.getChildren());
+ }
+}
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java
new file mode 100755
index 00000000000..91e4c54377f
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tilera Corporation and others.
+ * 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:
+ * William R. Swanson (Tilera Corporation)
+ *******************************************************************************/
+
+package org.eclipse.cdt.visualizer.core;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.runtime.Plugin;
+
+
+// ---------------------------------------------------------------------------
+// ResourceManager
+// ---------------------------------------------------------------------------
+
+/**
+ * Plugin resource manager.
+ * This class should be instanced in the plugin's "start()" method,
+ * and disposed in the "stop()" method.
+ */
+public class ResourceManager{
+
+ // --- members ---
+
+ /** Plugin ID */
+ protected String m_pluginID = null;
+
+ /** Plugin */
+ protected Plugin m_plugin = null;
+
+ /** Parent resource manager, if any */
+ protected ResourceManager m_parentManager = null;
+
+ /** String resource manager */
+ protected ResourceBundle m_stringResources = null;
+
+ /** String resource property file name */
+ protected String m_stringResourceFilename = null;
+
+
+ // --- constructors/destructors ---
+
+ /**
+ * Constructor,
+ * Assumes string resources are in the file "messages.properties".
+ */
+ public ResourceManager(Plugin plugin) {
+ this(plugin, "messages.properties");
+ }
+
+ /** Constructor */
+ public ResourceManager(Plugin plugin, String stringResourceFilename) {
+ m_pluginID = plugin.getBundle().getSymbolicName();
+ m_plugin = plugin;
+ m_stringResourceFilename = stringResourceFilename;
+ getStringRegistry(); // creates registry object
+ }
+
+ /** Dispose method */
+ public void dispose() {
+ disposeStringRegistry();
+ m_stringResourceFilename = null;
+ m_plugin = null;
+ m_pluginID = null;
+ }
+
+
+ // --- accessors ---
+
+ /** Returns plugin we're associated with */
+ public Plugin getPlugin() {
+ return m_plugin;
+ }
+
+
+ // --- parent manager management ---
+
+ /** Sets parent resource manager, if any */
+ public void setParentManager(ResourceManager parentManager) {
+ m_parentManager = parentManager;
+ }
+
+ /** Gets parent resource manager, if any */
+ public ResourceManager getParentManager() {
+ return m_parentManager;
+ }
+
+
+ // --- string resource management ---
+
+ /** Creates/returns string registry */
+ protected ResourceBundle getStringRegistry() {
+ if (m_stringResources == null) {
+ String filename = m_stringResourceFilename;
+
+ // The ".properties" extension is assumed, so we trim it here
+ String propertiesExtension = ".properties";
+ if (filename.endsWith(propertiesExtension)) {
+ filename = filename.substring(0, filename.length() -
+ propertiesExtension.length());
+ }
+
+ // NOTE: We have to be careful to pick up the class loader
+ // from the plugin class, otherwise we default to the classloader
+ // of the ResourceManager class, which is the classloader
+ // for the plugin the ResourceManager comes from.
+ ClassLoader classLoader = m_plugin.getClass().getClassLoader();
+ Locale locale = Locale.getDefault();
+
+ // we'll check for .properties file first
+ // in the same directory as the plugin activator class
+ String propertyFileName1 = m_pluginID + ".plugin." + filename;
+ try {
+ m_stringResources =
+ ResourceBundle.getBundle(propertyFileName1,
+ locale, classLoader);
+ }
+ catch (MissingResourceException e) {
+ // TODO: log this exception (probably a .properties file is missing)
+ m_stringResources = null;
+ }
+
+ // if not found, we try in the default package
+ // (that is, the top-level "src" or "resources" folder)
+ String propertyFileName2 = filename;
+ if (m_stringResources == null) {
+ try {
+ m_stringResources =
+ ResourceBundle.getBundle(propertyFileName2,
+ locale, classLoader);
+ }
+ catch (MissingResourceException e) {
+ // TODO: log this exception (probably a .properties file is missing)
+ m_stringResources = null;
+ }
+ }
+ }
+ return m_stringResources;
+ }
+
+ /** Disposes of string registry */
+ protected void disposeStringRegistry() {
+ m_stringResources = null;
+ }
+
+ /** Returns string resource for specified key */
+ public String getString(String key) {
+ String result = null;
+ if (key == null) return "(null resource)";
+
+ // get string registry, look up key
+ ResourceBundle strings = getStringRegistry();
+ if (strings == null) {
+ // if we can't get the registry, display the key instead,
+ // so we know what's missing (e.g. the .properties file)
+ result = "(" + key + ")";
+ }
+ else {
+ try {
+ result = strings.getString(key);
+ }
+ catch (MissingResourceException e) {
+ // we fail, but don't throw an exception
+ // so we don't screw any UI setup that depends
+ // on this string resource
+ result = null;
+ }
+ }
+
+ // if we fail, try the parent manager if there is one
+ if (result == null && m_parentManager != null) {
+ result = m_parentManager.getString(key);
+ }
+
+ // if we still fail, display the key instead,
+ // so we know what's missing
+ if (result == null) result = "[" + key + "]";
+ return result;
+ }
+
+ /** Formats string resource with specified argument(s) */
+ public String getString(String key, Object... arguments) {
+ return MessageFormat.format(getString(key), arguments);
+ }
+}
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java
new file mode 100755
index 00000000000..5b6b7e44881
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tilera Corporation and others.
+ * 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:
+ * William R. Swanson (Tilera Corporation)
+ *******************************************************************************/
+
+package org.eclipse.cdt.visualizer.core.plugin;
+
+import org.eclipse.cdt.visualizer.core.ResourceManager;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+
+// ----------------------------------------------------------------------------
+// CDTVisualizerCorePlugin
+// ----------------------------------------------------------------------------
+
+/**
+ * CDT visualizer core plugin class.
+ *
+ * This plugin contains the non-UI components of the visualizer framework.
+ */
+public class CDTVisualizerCorePlugin extends AbstractUIPlugin
+{
+ // --- constants ---
+
+ /** The plug-in ID */
+ public static final String PLUGIN_ID = "org.eclipse.cdt.visualizer.core"; //$NON-NLS-1$
+
+
+ // --- static members ---
+
+ /** Singleton instance */
+ protected static CDTVisualizerCorePlugin s_plugin;
+
+ /** Returns the singleton instance */
+ public static CDTVisualizerCorePlugin getDefault() {
+ return s_plugin;
+ }
+
+ /** Resource manager */
+ protected static ResourceManager s_resources = null;
+
+
+ // --- constructors/destructors ---
+
+ /** Constructor */
+ public CDTVisualizerCorePlugin() {
+ }
+
+
+ // --- plugin startup/shutdown methods ---
+
+ /** Invoked when plugin is loaded. */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ s_plugin = this;
+
+ // touch activator classes of any plugins we depend on,
+ // to ensure their start() methods are called first
+ // (None for now.)
+
+ // initialize resource management (strings, images, fonts, colors, etc.)
+ getPluginResources();
+ }
+
+ /** Invoked when plugin is stopped. */
+ public void stop(BundleContext context) throws Exception {
+ // clean up resource management
+ cleanupPluginResources();
+
+ s_plugin = null;
+ super.stop(context);
+ }
+
+
+ // --- logging ---
+
+ /**
+ * Writes message to Eclipse log.
+ * Severity can be one of:
+ * Status.OK, Status.ERROR, Status.INFO, Status.WARNING, Status.CANCEL
+ */
+ public static void log(int severity, String text)
+ {
+ Status status = new Status(severity, PLUGIN_ID, text);
+ ResourcesPlugin.getPlugin().getLog().log(status);
+ }
+
+
+ // --- resource management ---
+
+ /** Returns resource manager for this plugin */
+ public ResourceManager getPluginResources() {
+ if (s_resources == null) {
+ s_resources = new ResourceManager(this);
+ }
+ return s_resources;
+ }
+
+ /** Releases resource manager for this plugin. */
+ public void cleanupPluginResources() {
+ s_resources.dispose();
+ }
+
+ /** Convenience method for getting plugin resource manager */
+ public static ResourceManager getResources() {
+ return getDefault().getPluginResources();
+ }
+
+ /** Convenience method for looking up string resources */
+ public static String getString(String key) {
+ return getDefault().getPluginResources().getString(key);
+ }
+ /** Convenience method for looking up string resources */
+ public static String getString(String key, Object... arguments) {
+ return getDefault().getPluginResources().getString(key, arguments);
+ }
+}
--
cgit v1.2.3