Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Retarget Actions listening to model changes
Retarget Actions listening to model changes [message #335679] Tue, 21 April 2009 10:07 Go to next message
Rob is currently offline RobFriend
Messages: 27
Registered: July 2009
Junior Member
Hi,

In my plugin I have a tree view which displays my own model. The objects
in the tree can change state without the user making selection changes. So
I needed to update the enablement of commands to accomodate this. After A
LOT of searching, I got my plugin contributed functionality working from
the plugin.xml, using: commands, handlers, the <enabledWhen> tag, and a
PropertyTester. It took me ages to find a good solid example of how to use
the PropertyTester. But it is now working.

However, the main issue is the use of retarget actions. As was pointed out
in another thread, 3.3 still uses retarget actions. I cannot move to 3.4.
Therefore, I need to retarget rename, refresh, delete, properties, new,
etc. But the enablement of these actions can also change (without the user
changing selection). So it's not enough for my actions just to listen to
workbench selection changes.

I guess i'm trying to somehow hook my PropertyTester into the actions, and
get the "isEnabled()" method for each action called when the File or Edit
Menu is expanded.

Any ideas? My first thought was to add a menu listener to the main menu,
but I can't get access to the instance of the main menu bar.

Thanks
Re: Retarget Actions listening to model changes [message #335703 is a reply to message #335679] Wed, 22 April 2009 18:19 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You would have to provide an equivalent IAction using
getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.COPY.getId(),
yourAction)

That action will determine the RetargetAction state. You would probably
have to fiddle around with it to get it to play nice with commands and
handlers.

In the IDE, you're kinda stuck until 3.4. In an RCP app, you can
replace the RetargetAction in your ApplicationActionBarAdvisor.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Retarget Actions listening to model changes [message #335716 is a reply to message #335703] Thu, 23 April 2009 10:46 Go to previous messageGo to next message
Rob is currently offline RobFriend
Messages: 27
Registered: July 2009
Junior Member
Thanks for that. I'm actually using 3.4 now, and it is all a lot easier. I
still have one issue though. When my plugin is loaded by another
application, it retargets the Delete command correctly. I am using the
handler for "org.eclipse.ui.edit.delete" command, and the <activeWhen> and
<enabledWhen> tags. Everthing is fine.

However, my plugin can also be used as a standalone app. I have included
all the correct Advisor classes. In the ApplicationActionBarAdvisor, I
build the main menu by making the workbench actions as so:

deleteAction = ActionFactory.DELETE.create(window);
register(deleteAction);
:
editMenu.add(deleteAction);

Now the edit actions are added to my app ok, but the delete command is not
retargeted (even though I have added the delete command as a popup in my
view, and it is enabled/disabled correctly!)

Any ideas would be appreciated!
Re: Retarget Actions listening to model changes [message #335719 is a reply to message #335716] Thu, 23 April 2009 12:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Rob wrote:

>
> deleteAction = ActionFactory.DELETE.create(window);
> register(deleteAction);
> :
> editMenu.add(deleteAction);

Check out how WorkbenchActionBuilder does delete in 3.4,
org.eclipse.ui.internal.ide.WorkbenchActionBuilder.createEdi tMenu()

You can essentially do the same thing, instead of adding the
RetargetAction, add a CommandContributionItem for Delete, Cut, Copy,
Paste, etc

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Retarget Actions listening to model changes [message #335722 is a reply to message #335719] Thu, 23 April 2009 13:55 Go to previous message
Rob is currently offline RobFriend
Messages: 27
Registered: July 2009
Junior Member
That's working now. Thanks Paul.
Previous Topic:how to get toggle button state
Next Topic:Create editor's Toolbar like view's toolbar
Goto Forum:
  


Current Time: Fri Dec 27 16:49:40 GMT 2024

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

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

Back to the top