Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Disabling and enabling Actions
Disabling and enabling Actions [message #461809] Wed, 17 January 2007 15:21 Go to next message
Ali Alauoubiy is currently offline Ali AlauoubiyFriend
Messages: 20
Registered: July 2009
Junior Member
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 #461883 is a reply to message #461809] Wed, 17 January 2007 16:32 Go to previous messageGo to next message
Patrick Godeau is currently offline Patrick GodeauFriend
Messages: 64
Registered: July 2009
Member
Ali Alauoubiy a écrit :
> 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..

Hi,
Do something like this:

tree.addSelectionChangedListener (new ISelectionChangedListener () {
public void selectionChanged (SelectionChangedEvent event) {
if (((StructuredSelection) event.getSelection ()).getFirstElement ()
instanceof Y)
action.setEnabled (true);
else
action.setEnabled (false);
}
});
Re: Disabling and enabling Actions [message #461884 is a reply to message #461883] Wed, 17 January 2007 16:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I do this the other way round.

TableViewer v = new TableViewer(parent);
MenuManager mgr = new MenuManager();
v.getTable().setMenu(mgr.createContextMenu(v.getTable()));
mgr.addMenuListener( new IMenuListener() {
public void menuAboutToShow(IMenuManager mgr) {
// ...
}
}
);

Tom

Patrick Godeau schrieb:
> Ali Alauoubiy a écrit :
>> 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..
>
> Hi,
> Do something like this:
>
> tree.addSelectionChangedListener (new ISelectionChangedListener () {
> public void selectionChanged (SelectionChangedEvent event) {
> if (((StructuredSelection) event.getSelection ()).getFirstElement ()
> instanceof Y)
> action.setEnabled (true);
> else
> action.setEnabled (false);
> }
> });
Re: Disabling and enabling Actions [message #461886 is a reply to message #461809] Wed, 17 January 2007 18:30 Go to previous message
Ilya Shinkarenko is currently offline Ilya ShinkarenkoFriend
Messages: 22
Registered: July 2009
Junior Member
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
Previous Topic:avoid view beeing restored
Next Topic:IAdaptable Help
Goto Forum:
  


Current Time: Sat Apr 27 03:24:00 GMT 2024

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

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

Back to the top