Showing posts with label preferences. Show all posts
Showing posts with label preferences. Show all posts

Tuesday, January 10, 2017

Removing unwanted preference pages from eclipse


To remove unwanted preferences from your eclipse rcp app, we can do the following.


As part of your App MyRCPWorkbenchAdvisor#postStartup() method, you need to invoke the following code with the preference page id.


private void removeUnwantedPreferences()
{
PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
IPreferenceNode root = getRoot(pm);
if (root != null)
{
removePrefsPage(root"com.windows.preference.mypage.id"); 
}
}


//Identify preference node
private IPreferenceNode getRoot(PreferenceManager pm)
{
try
{
Method m = PreferenceManager.class.getDeclaredMethod("getRoot", (Class[]) null); 
m.setAccessible(true);
return (IPreferenceNode) m.invoke(pm);
}
catch (Exception e)
{
IdeLog.logWarning(TitaniumCorePlugin.getDefault(), e);
}
return null;
}


//remove preference id from the preference node
private void removePrefsPage(IPreferenceNode root, String id)
{
for (IPreferenceNode node : root.getSubNodes())
{
if (node.getId().equals(id))
{
root.remove(node);
}
else
{
removePrefsPage(node, id);
}
}

}



This seems to be work without any issues.

However, I could see other direct approach but that doesn't seem to work well in all scenarios.

PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
pm.remove("com.windows.preference.mypage.id");


Wednesday, December 9, 2015

Preferences sharing across all workspaces - Handling programatically

To share preferences across all workspaces in eclipse, you need to save preferences via ConfigurationScope.

What is configuration scope ?

Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by that user. On a multi-user installation, these preferences are shared by all users of the configuration.

How to save ?

IEclipsePreferences store = ConfigurationScope.INSTANCE.getNode(MyUIPlugin.PLUGIN_ID);
if (store != null)
{
store.putBoolean(MyFLAG_PREF, true);
try
{
store.flush();
}
catch (BackingStoreException e)
{
//Log exception
}
}


How to retrieve the saved preference value?

boolean isSet = Platform.getPreferencesService().getBoolean(MyUIPlugin.PLUGIN_ID,
MyFLAG_PREF, false, new IScopeContext[] { ConfigurationScope.INSTANCE });


Understand more about preference scopes:


Tuesday, March 24, 2015

Registering a listener for changes in network connections and proxy from eclipse preferences

import org.eclipse.core.net.proxy.IProxyChangeEvent;
import org.eclipse.core.net.proxy.IProxyChangeListener;
import org.eclipse.core.net.proxy.IProxyService;
import org.osgi.util.tracker.ServiceTracker;

public class ProxyHelper
{

public void registerListener()
{
ServiceTracker tracker = new ServiceTracker(MyPlugin.getDefault().getBundle().getBundleContext(),
IProxyService.class.getName(), null);
tracker.open();
IProxyService proxyService = (IProxyService) tracker.getService();
proxyService.addProxyChangeListener(new IProxyChangeListener()
{

@Override
public void proxyInfoChanged(IProxyChangeEvent event)
{
// TODO: your action for proxy changed
}
});
}

}

Tuesday, October 7, 2014

Where can I find eclipse preferences stored files ?

Eclipse stores all the preferences in the preference configuration files. This you can find in the below eclipse workspace location.

<eclipseworkspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\

Say for example, jre configuration will be stored in the "org.eclipse.jdt.launching.prefs" file.