blob: e3d5e754086d6bffd96952785dbd250c284ad696 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
// **********************************************************************
//
// Copyright (c) 2003-2010 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.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
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.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;
// set the listener for the preference change
Preferences prefs = getPluginPreferences();
prefs.addPropertyChangeListener(new IPropertyChangeListener()
{
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 propertyChange(PropertyChangeEvent event)
{
String property = event.getProperty();
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);
// 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;
}
|