My Tree structure looks like this, containing three classes Index,Key,Value
Index1
|
-- Key1
|
-- Value1
Index2
|
-- Key2
|
-- Value2
I’m creating a context menu for an index entry which should have three actions(newKeyAction , newValueAction, removeAction)
and by right clicking on the empty space addAction should be popped up.
This is the code responsible:
protected void fillContextMenu( IMenuManager manager )
{
ITreeSelection mySelection = (ITreeSelection) viewer.getSelection();
if(mySelection.size() == 1)
{
if(mySelection.getFirstElement() instanceof Index)
{
manager.add( newKeyAction );
manager.add( newValueAction );
manager.add( removeAction );
}
}
else
{
manager.add( addAction);
}
}
Everything works fine, but the addAction is being invoked only once when the treeViewer is empty, and there after by right clicking on the empty space, node last selected in the tree is being selected and its respective actions are displayed.
Please let me know where i’m going wrong .
That’s your problem and you can’t do anything about it. It’s just not possible to clear the selection like this. You should find another way to make addAction available.