Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Commands and the Common Navigation Framework
Commands and the Common Navigation Framework [message #512094] Wed, 03 February 2010 21:27 Go to next message
Jason Walton is currently offline Jason WaltonFriend
Messages: 6
Registered: July 2009
Junior Member
I've been playing around with the Common Navigation Framework (CNF). I've read through Michael Elder's excellent tutorials, but I noticed they're very "action" oriented, as in IAction. How do we get CNF up and running with commands instead?

Pop menu contributions are pretty easy; when you extend org.eclipse.ui.navigator.viewer, in your "viewer" element, set popupMenuId to something (say "com.myDomain.myApp.cnfMenu"). Then, extend org.eclipse.ui.menus, and create a "menuContribution" for the locationURI "popup:com.myDomain.myApp.cnfMenu". Commands added to the menuContribution can have a "visibleWhen" set, which will let them behave like objectContributions.

But, when you double-click a CommonNavigator tree, CommonNavigator will try to get an action handler for ICommonActionConstants.OPEN and run it. The only way I've found to set this is using a CommonActionProvider, which by definition relies on actions.

The "hack" way to do it is to subclass CommonNavigator and override handleDoubleClick():

  @Override
  protected void handleDoubleClick(DoubleClickEvent anEvent) {
    ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class);
    
    Command command = commandService.getCommand(OPEN_COMMAND_ID); 
    if(command.isEnabled()) {
      IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
      try {
        handlerService.executeCommand(OPEN_COMMAND_ID, null);
      } catch (NotDefinedException e) {
        throw new RuntimeException("Could not find open command: " + OPEN_COMMAND_ID);
      } catch (Exception e) {
        // Ignore
      }
    } else {

      // Pass the double click up to the super-class so it can expand/colapse trees
      super.handleDoubleClick(anEvent);
    }
  }


This is pretty ugly though. Is there a better way to use set a default command for double-click?

-Jason
Re: Commands and the Common Navigation Framework [message #513745 is a reply to message #512094] Thu, 11 February 2010 04:42 Go to previous messageGo to next message
Francis Upton IV is currently offline Francis Upton IVFriend
Messages: 472
Registered: July 2009
Location: Oakland, CA
Senior Member
I don't think there is a better way to do this; please file an enhancement report about this.

Francis


Re: Commands and the Common Navigation Framework [message #682181 is a reply to message #513745] Fri, 10 June 2011 15:04 Go to previous message
Philipp M. Fischer is currently offline Philipp M. FischerFriend
Messages: 67
Registered: November 2010
Location: Germany
Member
Hi there,

I was facing the smae issue. I takled it in the same way by deriving from CommonNavigator. But instead of doing all the fency work of identifying the Command by its ID, i am directly calling them, sicne they are part of my own navigator plugin.

In case someone knows a better way, please let me know. But for the moment i am quite happy with this approach.

Cheers

Phil
Previous Topic:how to add the external jar to the rcp application
Next Topic:Export to Multiple Platforms
Goto Forum:
  


Current Time: Fri Mar 29 09:52:36 GMT 2024

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

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

Back to the top