Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Metadata in TreeViewer(Retrieve data from node in TreeViewer (in e4) on RMB click)
Metadata in TreeViewer [message #1087593] Thu, 15 August 2013 22:05 Go to next message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
I have been trying to figure this out for a couple of days:

I have a TreeViewer with nodes that extend:
public abstract class TreeNode implements ITreeNode, IAdaptable
{
...
public ITreeNode getParent() {
return fParent;
}
...
}

I would like to store a unique database table key for each item in the tree (as well as the item name) and retrieve the key on RMB selection of the item so that I can show a popup with details of the selected item. The names could be duplicates so a unique key is required.

As I want to get the key on RMB click (not doubleclick where I could use IStructuredSelection) I can't access the selected node to check against node model objects, RMB is SWT world.

Also as TreeLabelProvider does not have a getData() method there is no way to retrieve data as per SWT treeItem.

As far as I can tell my options are:
1) Use SWT Tree and TreeItem instead of TreeViewer and build the tree manually and use .setData(uniqueKey) of the TreeItems.
2) Use IPropertySource from eclipse 3.x but I need to research more to see If I would be able to link up a RMB click to SelectionService. Also I would prefer to keep the application pure e4.
3) Extend jface.viewers.StructureViewer? to implement a right mouse button listener - which might be fun but seems a bit more than I can chew at the moment.

Has anyone else come accross this issue and found a solution using TreeViewer?
Re: Metadata in TreeViewer [message #1087606 is a reply to message #1087593] Thu, 15 August 2013 22:23 Go to previous messageGo to next message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
I worked this out 5 min after posting Smile - use MenuManager then you can access the node model.

MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(viewer.getControl());
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
if(viewer.getSelection().isEmpty()) {
return;
}

if(viewer.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();

Object selectedNode = selection.getFirstElement();
if(selectedNode instanceof TestObject){
TestObject testObject = (TestObject)selectedNode;
logger.debug("--menuAboutToShow() testObject "+testObject.getName());
}


}
}
});
Re: Metadata in TreeViewer [message #1089268 is a reply to message #1087606] Sun, 18 August 2013 12:39 Go to previous message
Don Smyth is currently offline Don SmythFriend
Messages: 35
Registered: April 2013
Member
PS,

I then changed to use pure e4 - as per my post on ContextMenu in the e4 forum.
Previous Topic:React on value change along with databinding
Next Topic:TableViewer not preserved sorting
Goto Forum:
  


Current Time: Fri Mar 29 07:41:34 GMT 2024

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

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

Back to the top