Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Overriding Preferences
Overriding Preferences [message #1105189] Mon, 09 September 2013 13:38 Go to next message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
There is a preference that tells Eclipse to poll the file system looking for changes (Windows->Preferences expand General, click on workspace -> "Refresh using native hooks or polling". I have a plugin that uses the startup extension point so that it starts when the workspace starts - in the earlyStartup method I am attempting to overwrite this parameter with the following code (have tried both ways InstanceScope and ConfigurationScope):

		//IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(PLUGIN_ID);
		IEclipsePreferences prefs = ConfigurationScope.INSTANCE.getNode(PLUGIN_ID);
		prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
		
		try {
			prefs.flush();
		} catch (BackingStoreException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}


The purpose is so that a resource change listener I configure later gets notified if files under a project get modified externally. It does not appear to be working however... if I go into the preferences window the option is not checked - if I check it and hit apply and then modify a file externally my resource change listener does fire.

How to I properly set this preference?
Re: Overriding Preferences [message #1105274 is a reply to message #1105189] Mon, 09 September 2013 16:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Kevin,

This isn't really a JDT question. The problem is very likely that
you're just doing it too early. At some point, Eclipse will read the
stored preferences and that's likely to overwrite what you're setting
early, i.e, what you're setting before those preferences are read.


On 09/09/2013 3:38 PM, Kevin Regan wrote:
> There is a preference that tells Eclipse to poll the file system
> looking for changes (Windows->Preferences expand General, click on
> workspace -> "Refresh using native hooks or polling". I have a
> plugin that uses the startup extension point so that it starts when
> the workspace starts - in the earlyStartup method I am attempting to
> overwrite this parameter with the following code (have tried both ways
> InstanceScope and ConfigurationScope):
>
>
> //IEclipsePreferences prefs =
> InstanceScope.INSTANCE.getNode(PLUGIN_ID);
> IEclipsePreferences prefs =
> ConfigurationScope.INSTANCE.getNode(PLUGIN_ID);
> prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
>
> try {
> prefs.flush();
> } catch (BackingStoreException e2) {
> // TODO Auto-generated catch block
> e2.printStackTrace();
> }
>
>
> The purpose is so that a resource change listener I configure later
> gets notified if files under a project get modified externally. It
> does not appear to be working however... if I go into the preferences
> window the option is not checked - if I check it and hit apply and
> then modify a file externally my resource change listener does fire.
> How to I properly set this preference?
Re: Overriding Preferences [message #1105285 is a reply to message #1105274] Mon, 09 September 2013 16:25 Go to previous messageGo to next message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
Thanks Ed, should this be in the plugin development forum?
Re: Overriding Preferences [message #1105390 is a reply to message #1105189] Mon, 09 September 2013 20:06 Go to previous messageGo to next message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
I don't doing it to early is the problem... I think the problem is that I'm trying to modify a core eclipse preference but the way I'm doing it is just modifying it for my plugin's "node" and the actual service in eclipse that does the resource polling is not looking at my plugin's preference but the "core" one.

Basically, I got it to work by changing the node I'm getting from the preferences to the org.eclipse.core.resources one like this:


			IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.core.resources");
			prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);



What I'm worried about is whether this is OK. I'm finding that this setting gets persisted to the workspace preferences so if I run a completely separate plugin using that workspace the setting is still disabled. I intended to set this preference just for this one run of my plugin. I feel like I may be doing something wrong here but I'm not sure what the correct approach is.

Please let me know also if this is in the wrong forum and I will move it (I think I already have a similar thread in the plugin forum but it's a bit different).
Re: Overriding Preferences [message #1105658 is a reply to message #1105390] Tue, 10 September 2013 06:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Kevin,

Sorry, I didn't look closely at your code. It's just a similar issue to
a tool I've been working on to manage preferences as part of an
automated installation processes...

Definitely this preference is a global workspace-specific one that's
persisted in the workspace and I would expect the code that depends on
that setting to only look at that preference node. It's also generally
not a great idea to have a plugin override/change user preferences.
Perhaps it could record the old value and on shutdown restore that old
value...

This kind of question would be appropriate for the eclipse.platform forum.


On 09/09/2013 10:06 PM, Kevin Regan wrote:
> I don't doing it to early is the problem... I think the problem is
> that I'm trying to modify a core eclipse preference but the way I'm
> doing it is just modifying it for my plugin's "node" and the actual
> service in eclipse that does the resource polling is not looking at my
> plugin's preference but the "core" one.
> Basically, I got it to work by changing the node I'm getting from the
> preferences to the org.eclipse.core.resources one like this:
>
>
>
> IEclipsePreferences prefs =
> InstanceScope.INSTANCE.getNode("org.eclipse.core.resources");
> prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
>
>
>
> What I'm worried about is whether this is OK. I'm finding that this
> setting gets persisted to the workspace preferences so if I run a
> completely separate plugin using that workspace the setting is still
> disabled. I intended to set this preference just for this one run of
> my plugin. I feel like I may be doing something wrong here but I'm
> not sure what the correct approach is.
> Please let me know also if this is in the wrong forum and I will move
> it (I think I already have a similar thread in the plugin forum but
> it's a bit different).
Re: Overriding Preferences [message #1105966 is a reply to message #1105658] Tue, 10 September 2013 14:02 Go to previous message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
Thanks Ed, I am arriving at the conclusion that it is probably not a good idea for my plugin to rely on the value of a core workspace, non-plugin specific preference, as the users of the plugin can simply change it and cause the plugin to break... Unfortunately, I was hoping to leverage the resource listener functionality to monitor a file that can be externally modified that I need to keep track of but it seems like a safer bet for me to do this in a homegrown fashion considering the way it works now. Thanks for your input.
Previous Topic:Calling PlatformUI.getWorkbench().close() throws Exception (NullPointer?)
Next Topic:Windows Builder Pro Version difference between Indigo and the following
Goto Forum:
  


Current Time: Sun Nov 23 11:15:08 GMT 2014

Powered by FUDForum. Page generated in 0.01854 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software