I am experiencing some problems with action enablements. I have a ViewPart
which contains a JFace TreeViewer. And my action class implements the
IWorkbenchWindowActionDelegate interface. I want to enable my action only
when a certain type of node is selected in the TreeViewer. Let's say my
TreeViewers contents can be Box as parent and Book as children. I only want
the action to be enabled if a Box element is selected.
So I added the enablement and objectClass extensions to my action. I chosed
the fully qualified class name of the Box class as the name of the
objectClass extension. As I understand that should mean: The action is
enabled only if all selection elements are instance of the Box class.
At the beginning it didn't work at all. I thought it was because the
ViewPart didn't return the TreeViewers selection when queried. So I let my
ViewPart implement the ISelectionProvider interface. Now it returns the
selection of my TreeViewer in the getSelection method. It did help, but only
partially. The selection is only updated when the view selection is changed.
So if I have the focus on my ViewPart and choose different elements in the
TreeViewer, the status of the action is not updated. To update the
enablement, I have to click on another view and then reselect my ViewPart.
I need to change the enablement of the action after selection change in the
TreeViewer.