Commands and the Common Navigation Framework [message #512094] |
Wed, 03 February 2010 21:27 |
Jason Walton 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 #682181 is a reply to message #513745] |
Fri, 10 June 2011 15:04 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03183 seconds