Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » implementing global action in ApplicationWorkbench
implementing global action in ApplicationWorkbench [message #484309] Sun, 06 September 2009 03:43 Go to next message
Bonny Fog is currently offline Bonny FogFriend
Messages: 11
Registered: August 2009
Junior Member
hello
I have implemented the global actions in the controls of the Editors in the following way
final Action cutSelected = new Action() {
			public void run() {
				styledText.cut();
			}
		};
		//
		getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.CUT.getId(), cutSelected);



Now the problem is there is a control in ApplicationWorkbench. how can I implement the global actions in that control?

Thanks
Re: implementing global action in ApplicationWorkbench [message #484685 is a reply to message #484309] Tue, 08 September 2009 18:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The IFocusService allows you to specify handlers for commands like cut, copy, paste where you only need to specify the control that has focus.

See the javadoc for IFocusService for details.

PW


Re: implementing global action in ApplicationWorkbench [message #484978 is a reply to message #484685] Thu, 10 September 2009 05:50 Go to previous messageGo to next message
Bonny Fog is currently offline Bonny FogFriend
Messages: 11
Registered: August 2009
Junior Member
IFocusService service = (IFocusService) Application.APP_WINDOW.getService(IFocusService.class);


how can I activate the cut, copy, paste of the edit menu for the given control?
Re: implementing global action in ApplicationWorkbench [message #485085 is a reply to message #484978] Thu, 10 September 2009 13:57 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

So you've used the IFocusService to tag the control you care about and the IHandlerService to activate some handlers for it, right?

In 3.4 Edit>Copy did not correctly follow the CTRL+C copy. That was fixed in 3.5. In an RCP app you can fix it yourself if you want.

PW


Re: implementing global action in ApplicationWorkbench [message #485110 is a reply to message #485085] Thu, 10 September 2009 14:34 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
Paul Webster wrote:
> So you've used the IFocusService to tag the control you care about and
> the IHandlerService to activate some handlers for it, right?
>
> In 3.4 Edit>Copy did not correctly follow the CTRL+C copy. That was
> fixed in 3.5. In an RCP app you can fix it yourself if you want.

Interesting - what do I need to do to fix that?

Thanks,

Daniel
Re: implementing global action in ApplicationWorkbench [message #485156 is a reply to message #485110] Thu, 10 September 2009 16:26 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

In an RCP app, you just need to update your ApplicationActionBarAdvisor with a CommandContributionItem instead of ActionFactory.COPY, for example (I think).

ex:
menu.add(getCopyItem());

private IContributionItem getCopyItem() {
return getItem(
ActionFactory.COPY.getId(),
ActionFactory.COPY.getCommandId(),
ISharedImages.IMG_TOOL_COPY,
ISharedImages.IMG_TOOL_COPY_DISABLED,
WorkbenchMessages.Workbench_copy,
WorkbenchMessages.Workbench_copyToolTip, null);
}

private IContributionItem getItem(String actionId, String commandId,
String image, String disabledImage, String label, String tooltip, String helpContextId) {
ISharedImages sharedImages = getWindow().getWorkbench()
.getSharedImages();

IActionCommandMappingService acms = (IActionCommandMappingService) getWindow()
.getService(IActionCommandMappingService.class);
acms.map(actionId, commandId);

CommandContributionItemParameter commandParm = new CommandContributionItemParameter(
getWindow(), actionId, commandId, null, sharedImages
.getImageDescriptor(image), sharedImages
.getImageDescriptor(disabledImage), null, label, null,
tooltip, CommandContributionItem.STYLE_PUSH, null, false);
return new CommandContributionItem(commandParm);
}

This is the code from 3.5, it might need to be tweaked for 3.4 (ActionFactory.COPY.getCommandId() doesn't exist in 3.4, for example).

PW


Previous Topic:Update site categories missing / feature dependencies broken
Next Topic:Command Parameter and dynamic menu
Goto Forum:
  


Current Time: Wed Feb 05 21:50:49 GMT 2025

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

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

Back to the top