Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam R. Swanson2012-02-10 13:10:03 -0500
committerMarc Khouzam2012-02-10 13:12:15 -0500
commit093697a0167b5b9bb0287baa0dd38547a976f1e5 (patch)
treea69acac20fbc672dbdb12c36794f625b01bbce10 /visualizer/org.eclipse.cdt.visualizer.core
parentff94f47a9e2d77282bb3545d7d4a0ba07c676ebe (diff)
downloadorg.eclipse.cdt-093697a0167b5b9bb0287baa0dd38547a976f1e5.tar.gz
org.eclipse.cdt-093697a0167b5b9bb0287baa0dd38547a976f1e5.tar.xz
org.eclipse.cdt-093697a0167b5b9bb0287baa0dd38547a976f1e5.zip
Bug 335027: Visualizer View feature. Initial contribution.
Diffstat (limited to 'visualizer/org.eclipse.cdt.visualizer.core')
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/.classpath8
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/.project28
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/.settings/org.eclipse.jdt.core.prefs8
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/ABOUT.txt17
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/META-INF/MANIFEST.MF15
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.core/about.html24
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/build.properties17
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.core/plugin.properties17
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.core/pom.xml17
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.core/resources/messages.properties14
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java92
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java160
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java195
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java126
14 files changed, 738 insertions, 0 deletions
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/.classpath b/visualizer/org.eclipse.cdt.visualizer.core/.classpath
new file mode 100755
index 0000000000..31db9a9117
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="resources"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/.project b/visualizer/org.eclipse.cdt.visualizer.core/.project
new file mode 100755
index 0000000000..77747f8e3e
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.visualizer.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
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 0000000000..743b93d39f
--- /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 0000000000..ad3ea21360
--- /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 0000000000..6fec5fa40a
--- /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 0000000000..cb740ae8bc
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body></html> \ 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 0000000000..07409e935a
--- /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 0000000000..43181240cd
--- /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 0000000000..bde189daa9
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/pom.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.cdt</groupId>
+ <artifactId>cdt-parent</artifactId>
+ <version>8.1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <version>1.0.0-SNAPSHOT</version>
+ <artifactId>org.eclipse.cdt.visualizer.core</artifactId>
+ <packaging>eclipse-plugin</packaging>
+</project>
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 0000000000..70fa2ec922
--- /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 0000000000..10aac2651c
--- /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<Extension> getExtensions(String extensionPointID)
+ {
+ IExtensionPoint extensionPoint = getExtensionPoint(extensionPointID);
+ return getExtensions(extensionPoint);
+ }
+
+ /** Gets list of extensions for specified plugin and extension point name. */
+ public static List<Extension> 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<Extension> getExtensions(IExtensionPoint extensionPoint)
+ {
+ return (extensionPoint == null) ? null :
+ Extension.wrapExtensions(extensionPoint.getConfigurationElements());
+ }
+
+ /** Wraps list of raw extension declarations. */
+ public static List<Extension> wrapExtensions(IConfigurationElement[] elements)
+ {
+ int count = (elements == null) ? 0 : elements.length;
+ List<Extension> result = new ArrayList<Extension>(count);
+ for (int i=0; i<count; ++i) {
+ result.add(new Extension(elements[i]));
+ }
+ return result;
+ }
+
+ // --- members ---
+
+ // --- constructors/destructors ---
+
+ /** Constructor. */
+ public Extension(IConfigurationElement element) {
+ super(element);
+ }
+
+ // --- methods ---
+
+}
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java
new file mode 100755
index 0000000000..ca54789412
--- /dev/null
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * 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.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.lang.model.type.NullType;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IContributor;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+
+
+// ---------------------------------------------------------------------------
+// ExtensionElement
+// ---------------------------------------------------------------------------
+
+/** Facade/utility class for dealing with Eclipse extensions. */
+public class ExtensionElement {
+
+ // --- static methods ---
+
+ /** Wraps list of raw extension declarations. */
+ public static List<ExtensionElement> wrapExtensionElements(IConfigurationElement[] elements)
+ {
+ int count = (elements == null) ? 0 : elements.length;
+ List<ExtensionElement> result = new ArrayList<ExtensionElement>(count);
+ for (int i=0; i<count; ++i) {
+ result.add(new ExtensionElement(elements[i]));
+ }
+ return result;
+ }
+
+
+ // --- members ---
+
+ /** Actual extension description loaded from extension point. */
+ protected IConfigurationElement m_element = null;
+
+
+ // --- constructors/destructors ---
+
+ /** Constructor. */
+ public ExtensionElement(IConfigurationElement element) {
+ m_element = element;
+ }
+
+
+ // --- methods ---
+
+ /** Gets string value of specified attribute. */
+ public String getAttribute(String attributeName)
+ {
+ return m_element.getAttribute(attributeName);
+ }
+
+ /** Creates and returns instance of implementing class, using class name found in "class" attribute. */
+ public <T> T getClassAttribute()
+ {
+ return getClassAttribute("class");
+ }
+
+ /** Creates and returns instance of implementing class, using class name found in specified attribute. */
+ @SuppressWarnings("unchecked")
+ public <T> 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> 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<argumentsLength; ++i) {
+ argumentTypes[i] =
+ (arguments[i] == null) ? NullType.class : arguments[i].getClass();
+ }
+ Constructor<?> 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<ExtensionElement> 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 0000000000..91e4c54377
--- /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 0000000000..5b6b7e4488
--- /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);
+ }
+}

Back to the top