|
|
Re: Howto get IPropertyChangeListener to trigger build? [message #116903 is a reply to message #114982] |
Tue, 26 August 2003 22:00 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: John_Arthorne.oti.com_
You do realize this code does a FULL REBUILD OF THE ENTIRE WORKSPACE
every time that property changes?? This means, for example, that all
java projects in the workspace will delete all of their .class files and
build everything from scratch. In general this is quite bad. I would
suggest inside that your property listener sets some bit (for example a
session property) on each project that has your nature. Your builder
would consult this bit when called, and then throw away state and do a
rebuild if it is set (and then clear the bit). Otherwise all other
builders will also throw away their built state. Also, if the user has
auto-build turned off, then any code that gratuitously builds is being
very rude... Other problems with the code below are left as an excercise
to the reader ;)
--
Paul T. Keyser wrote:
> Thanks to a colleague, who gave me the necessary clues ("you want to invoke
> IWorkspace.build(). You can get the current IWorkspace from
> ResourcesPlugin.getWorkspace(). ... properly encapsulate the call to build()
> in a workspace "runnable""), here is how it's done:
>
> static {
>
> OUR_PLUGIN_NAME.getDefault().getPreferenceStore().addPropert yChangeListener(new
> TriggerBuild());
> }
>
> /**
> * TriggerBuild is a IPropertyChangeListener that when attached to the
> PreferenceStore
> * will trigger a build when relevant items are changed
> *
> * @author Keyser
> */
> protected static class TriggerBuild implements IPropertyChangeListener {
>
> /**
> * @see
> org.eclipse.jface.util.IPropertyChangeListener#propertyChang e(org.eclipse.jface.util.PropertyChangeEvent)
>
> */
> public void propertyChange (final PropertyChangeEvent e) {
> if (needToBuild(e.getProperty())) {
> doBuild();
> }
> }
>
> /**
> * Perform a full build of the projects in the workspace
> */
> protected void doBuild () {
> try {
> final IWorkspace ws = ResourcesPlugin.getWorkspace();
>
> final IWorkspaceRunnable _runner = new IWorkspaceRunnable()
> {
> public void run (IProgressMonitor m) {
> try {
> ws.build(TYPE, m);
>
> } catch (CoreException e) {
> System.err.println(
> "Autobuild on change-preferences failed in "
>
> + getClass().getName());
> e.printStackTrace();
> }
> }
> };
> ws.run(_runner, null); // TODO keyser: find out how to
> create a ProgressMonitor
>
> } catch (CoreException e) {
> System.err.println(
> "Autobuild on change-preferences failed in "
> + getClass().getName());
> e.printStackTrace();
> }
> }
>
> /**
> * Is a build required?
> * @param prop the preference that has changed
> * @return boolean <code>true</code> if the changed preference
> requires a build
> */
> protected boolean needToBuild (final String prop) {
> return prop.equals(THE_ONE_TO_CHECK.TAG);
> }
>
> private static final int TYPE =
> IncrementalProjectBuilder.FULL_BUILD;
> }
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04004 seconds