Wednesday, January 25, 2017

Adding filter to tree viewer



PatternFilter filter = new PatternFilter();
FilteredTree tree = new FilteredTree(sash, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
TreeViewer viewer = tree.getViewer();

//go on..

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");


Sunday, January 8, 2017

Tip: Eclipse plugins error - prerequisite build errors

I've faced this issue many times with eclipse.

Even though we have all the plugins and their dependencies defined correctly, still eclipse shows the errors by saying the prerequisite has to be build first.

It's frustrating since I have not made any changes in the project from the last time.

Okay, so the solution for this is:

1. Identify the root prerequisite plugin which eclipse is complaining about.
2. Close that root plugin
3. Re-open it
4. Do clean build for all projects