diff options
author | Jose <jose@zeroc.com> | 2011-12-10 01:57:19 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2011-12-10 01:57:19 +0100 |
commit | 42e31f18dc2f34c6b0c427ca0a976ac795349864 (patch) | |
tree | 91f81872e55f06c5d6b859039e3c2a633c70c684 /eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/Activator.java | |
parent | ICE-4705 voip glacier2 configuration (diff) | |
download | ice-42e31f18dc2f34c6b0c427ca0a976ac795349864.tar.bz2 ice-42e31f18dc2f34c6b0c427ca0a976ac795349864.tar.xz ice-42e31f18dc2f34c6b0c427ca0a976ac795349864.zip |
Eclipse plug-in updates for release 3.4.2.20111024
Diffstat (limited to 'eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/Activator.java')
-rw-r--r-- | eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/Activator.java | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/Activator.java b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/Activator.java new file mode 100644 index 00000000000..8a4c847b031 --- /dev/null +++ b/eclipse/java/Slice2javaPlugin/src/com/zeroc/slice2javaplugin/Activator.java @@ -0,0 +1,181 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved. +// +// This plug-in 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. +// +// ********************************************************************** + +package com.zeroc.slice2javaplugin; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.jdt.core.IJavaModel; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +import com.zeroc.slice2javaplugin.builder.Slice2JavaBuilder; +import com.zeroc.slice2javaplugin.builder.Slice2JavaNature; +import com.zeroc.slice2javaplugin.internal.IceClasspathContainerIntializer; +import com.zeroc.slice2javaplugin.internal.IceClasspathVariableInitializer; +import com.zeroc.slice2javaplugin.preferences.PluginPreferencePage; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin +{ + + // The plug-in ID + public static final String PLUGIN_ID = "com.zeroc.Slice2JavaPlugin"; + + /** + * The constructor + */ + public Activator() + { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) + throws Exception + { + super.start(context); + _plugin = this; + + IEclipsePreferences prefs = new InstanceScope().getNode(PLUGIN_ID); + // set the listener for the preference change + //Preferences prefs = getPluginPreferences(); + prefs.addPreferenceChangeListener(new IPreferenceChangeListener() + { + public List<IJavaProject> getSlice2JavaProjects(IJavaModel javaModel) + { + ArrayList<IJavaProject> pl = new ArrayList<IJavaProject>(); + try + { + for(IJavaProject p : javaModel.getJavaProjects()) + { + try + { + if(p.getProject().hasNature(Slice2JavaNature.NATURE_ID)) + { + pl.add(p); + } + } + catch(CoreException e) + { + // The project isn't opened, or does not exist. + } + } + } + catch(JavaModelException jme) + { + } + + return pl; + } + + public void preferenceChange(PreferenceChangeEvent event) + { + String property = event.getKey(); + if(PluginPreferencePage.SDK_PATH.equals(property)) + { + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IJavaModel javaModel = JavaCore.create(workspaceRoot); + List<IJavaProject> projects = getSlice2JavaProjects(javaModel); + String value = (String)event.getNewValue(); + IceClasspathContainerIntializer.updateProjects(value, projects); + IceClasspathVariableInitializer.update(value); + // Need to trigger a clean build of the projects. + for(final IJavaProject p : projects) + { + Job job = new Job("Rebuild") + { + protected IStatus run(IProgressMonitor monitor) + { + try + { + p.getProject().build(IncrementalProjectBuilder.FULL_BUILD, Slice2JavaBuilder.BUILDER_ID, null, + monitor); + } + catch(CoreException e) + { + return new Status(Status.ERROR, Activator.PLUGIN_ID, 0, "rebuild failed", e); + } + return Status.OK_STATUS; + } + }; + job.setPriority(Job.BUILD); + job.schedule(); // start as soon as possible + } + } + + } + }); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) + throws Exception + { + _plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() + { + return _plugin; + } + + /** + * Returns an image descriptor for the image file at the given plug-in + * relative path + * + * @param path + * the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) + { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + + // The shared instance + private static Activator _plugin; +} |