开发者

Eclipse: Altering preferences at startup

I'm working on an Eclipse plugin that has a preference page, the performOk() method of which alters preferences of a few other plugins to accommodate the changes. Works nicely so far.

However, if the user changes the prefs file of my plugin manually or updates the plugin, he has to go to the preferences page and press "OK" manually, otherwise the other plugin's preferences will be out of date.

I would like to avoid this problem by adjusting the other plugins' preferences on each start of Eclipse. I've made my plugin class implement the IStartup interface and its earlyStartup() method to alter the preferences th开发者_如何学Pythonere, but I have two problems with that:

  1. I need to read a setting from my own plugin before altering the preferences of the other ones, but the getPreferenceStore() method does not work within the earlyStartup() method. I was able to work around this by implementing earlyStartup() empty and doing what I want in the plugin's start() method, is this behaviour reliable?

  2. I get Invalid thread access exceptions when actually altering the preferences in the start() method. I've read that start() is executed by its own job, can jobs change preferences?

If there is an alternative way to achieve what I want, I'd naturally also like to know.


If your main concern is that someone is importing some changes from some exported eclipse preferences file, then you should be able to solve the problem by using a preference changed listener. This would handle the situation you mention above. If preferences change through Eclipse and while eclipse is open, then your preference changed listener will be activated.

I have never heard of anyone manually editing their preference files outside of eclipse (this is the one situation that a preference changed listener will not catch). And if someone does, they shouldn't expect reliable behavior.

However, if you really do want to use IEarlyStartup, you can, but you should use a Display.synchExec() to execute the preference changing code. See: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/runtime/preferences/AbstractPreferenceInitializer.html


There is an extension point org.eclipse.core.runtime.preferences. You can use this to set the default values for any preference in your plugin's preference store. You may be able to use this extension point to set preferences in other plugins and this may be some way that you can get around the problem that you are having.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜