Disabling and enabling Actions [message #461809] |
Wed, 17 January 2007 10:21  |
Eclipse User |
|
|
|
Hi Everyone,
i have few actions added to my toolbar/menu and I want to disable/enable some of them depends on the selection of the tree.. Lets say I want to enable Action X when I select TreeItem from The TreeViewer of Type Y, otherwise it will stay disable. I recall in swing this can be done easily but I am finding it difficult to do this in SWT/RCP/JFace..
Regards
Ali
|
|
|
|
|
Re: Disabling and enabling Actions [message #461886 is a reply to message #461809] |
Wed, 17 January 2007 13:30  |
Eclipse User |
|
|
|
Hi Ali,
first of all let your TreeViewer be a SelectionProvider for a Site.
Ssomewhere in the createPartControl(Composite aParent) method say:
getSite().setSelectionProvider(treeViewer);
From now on your tree viewer will inform a SelectionService about
selection events.
Then you have to tweak your actions.
If you use the declarative way of contributing actions (your actions
implement IActionDelegate interface), then you have this method:
public void selectionChanged(IAction action, ISelection selection);
This method will be called by a Workbench every time the selection
changes within a relevant context. Using this method you can enable or
disable the actual action what you see in a tool/menubar.
If you derive from org.eclipse.jface.action.Action, then you have to
register your action as a listener in the SelectionService:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSele ctionService().addSelectionListener(new
ISelectionListener(){
public void selectionChanged(IWorkbenchPart aPart, ISelection aSelection)
{
//react upon selection changed events
}});
Hope that helps,
Ilya Shinkarenko
--
www.rcp-training.com
www.weiglewilczek.com
Ali Alauoubiy wrote:
> Hi Everyone,
>
> i have few actions added to my toolbar/menu and I want to disable/enable some of them depends on the selection of the tree.. Lets say I want to enable Action X when I select TreeItem from The TreeViewer of Type Y, otherwise it will stay disable. I recall in swing this can be done easily but I am finding it difficult to do this in SWT/RCP/JFace..
>
> Regards
> Ali
|
|
|
Powered by
FUDForum. Page generated in 0.26068 seconds