Search code examples
loggingpropertiesrcp

Error Log View - Activate on new events' property value in RCP


This might be a strange question but.. How can I know from code the 'Activate on new events' property value that makes the Error Log view to pop up when there is an error to show? I am working in a RCP application.

I tried using this

IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.views.log");
Boolean activateOnNewEvents = store.getBoolean("activate");

and even this:

Preferences preferences = InstanceScope.INSTANCE.getNode("org.eclipse.ui.logs.view.prefs");
Boolean activateOnNewEvents = preferences.getBoolean("activate", true);

But the problem is I only get the correct values when I close and reopen Eclipse/the Product. If I change the value from Error Log View right top menu (from UI), my code still returns the old value till a new restart, so I'm guessing only when eclipse/rcp is closed, the new property value is stored in preferences.

EDIT:

So I figured out that this preference value from 'org.eclipse.ui.logs.view.prefs' does not retrieve the right information. It is not updated when user changes the "Activate on new events" value from Error Log Menu. So the question is: How can I determine when the user clicks on "Activate on new events" and checks/unchecks this value?


Solution

  • Both those code fragments just give you the current setting and are not updated if the preference is changed.

    For the IPreferenceStore method you can use the addPropertyChangeListener call to add a listener to the preference store which will be called whenever a preference changes.

    In the IPropertyChangeListener you can check for the key your are interested in changing:

    public void propertyChange(PropertyChangeEvent event) {
        String key = event.getProperty();
    
        if (key.equals(""activate"") {
           // TODO get the new value from the preference store
        }
    }