Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [HowTo] re-use key-binding in wizard?
[HowTo] re-use key-binding in wizard? [message #451588] Mon, 26 June 2006 20:16 Go to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
R3.1.2, WinXP

So, I have an RCP app, and a bunch of key-bindings, including (no surprise) CTRL-C, and related items.

I use them in my (non-textual) editor to copy model-objects -- works fine; I create the actions in
my ActionBarAdvisor, using org.eclipse.ui.actions.ActionFactory, and also there add them to my main
menu; and I have registered an EditorActionBarContributor to retarget them to the current editor.

I also use them in Text-areas of in-place editors to copy Text (also works fine; I copied and reused
the org.eclipse.ui.actions.TextActionHandler, oddly not part of RCP).

Now, I would like to use CTRL-C within a wizard, that is wholly independent of any editor or view,
and can come into existance when all editors and views are closed, so it has no posibility of having
a reference to the editor-site or the view-site, AFAIK. Alas, that seems to mean that I cannot use
CTRL-C, since it is "still" bound to my editor even though the modal wizard-dialog is open.

Is there a work-around for this?

thanks,
Paul
Re: [HowTo] re-use key-binding in wizard? [message #451643 is a reply to message #451588] Tue, 27 June 2006 12:24 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Hmmm, in 3.1.2 you should still be able to create a context off of the
dialog context, or just use the dialog context. You can place your
keybinding for CTRL+C to your copy command in the dialog context (you
would use the child context to restrict your keybinding to your dialog
only).

Look at org.eclipse.ui.contexts and org.eclipse.ui.bindings (and
possibly org.eclipse.ui.commands).

Later,
PW


Re: [HowTo] re-use key-binding in wizard? [message #451689 is a reply to message #451643] Tue, 27 June 2006 20:33 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Hmm -- OK, I went to org.eclipse.ui's plugin.xml, and found there:
<key
commandId="org.eclipse.ui.edit.copy"
contextId="org.eclipse.ui.contexts.dialogAndWindow"
sequence="M1+C"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />

So I added to my plugin.xml what I thought would be a "deletion" (per the description of
org.eclipse.ui.bindings: "If a binding does not define a command identifier, then it is a deletion
marker. This means that if all the conditions are met, it will cancel any bindings with the same
trigger in the same context.") -- like this:

<key
contextId="org.eclipse.ui.contexts.dialog"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+C"/>

Made no difference - the CTRL-C is still not even being received by my Key-Listener in the wizard.

I turned on tracing for key-bindings, and saw this, when I hit CTRL-L (opens my wizard) and then
CTRL-C:

BINDINGS >> Clearing cache
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 620835924,
character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x6c, time = 620836145,
character = 0xc)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+L])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.mun.ist.my.commands.SelectCorpus',
parameters = {})
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 620839479,
character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x63, time = 620840140,
character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'org.eclipse.ui.edit.copy', parameters = {})
KEYS >>> not enabled

So, I'm confused -- there's no way (in wizard) for me to set the context, since there is no site
from which to get the IKeyBindingService, and the deletion does not "free up" the key-combo.

Paul
Re: [HowTo] re-use key-binding in wizard? [message #452010 is a reply to message #451689] Thu, 29 June 2006 17:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Paul Keyser wrote:
> Hmm -- OK, I went to org.eclipse.ui's plugin.xml, and found there:
> <key
> commandId="org.eclipse.ui.edit.copy"
> contextId="org.eclipse.ui.contexts.dialogAndWindow"
> sequence="M1+C"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
>

But I thought the deal was that you wanted CTRL+C to work, with your
command, within the dialog? Since dialog beats dialogAndWindow, why not
define the keybinding and just point to your command:

<key
commandId="com.mun.ist.my.commands.CopySomething"
contextId="org.eclipse.ui.contexts.dialog"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+C"/>

While the dialog is open CTRL+C will point to your CopySomething command
instead of the org.eclipse.ui.edit.copy command.

Option 2 ... the copy command is still valid while your dialog is open.
Why not just supply a handler for it? When you create your dialog,
you should be able to get the global handler service from the workbench
.... workbench.getAdapter(IHandlerService.class) (in 3.2 it's called
getService(*)).

Then activate a handler for the org.eclipse.ui.edit.copy command.
org.eclipse.core.commands.AbstractHandler is a base implementation of
IHandler. Save the IHandlerActivation, and then when your dialog closes
deactivate that handler.


If the stars are aligned, this should give you a dialog copy command
that responds to CTRL+C while your dialog is up :-)

Later,
PW


Re: [HowTo] re-use key-binding in wizard? [message #452037 is a reply to message #452010] Thu, 29 June 2006 18:44 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Thanks -- but ...

Since both options require that I write an IHandler, but the first opetion also required a bit of
plugin.xml, I decided to try Option 2 first (an option I hadn't been able to think of, since I had
never known about IHandlerService). I can get the IHandlerService, create what I think is a suitable
IHandler -- by extending the AbstractHandler you mention and implementing its execute() method by
simply running the action in question (have done this elsewhere, to handle F2 in the main app) --
save the IHandlerActivation returned by handlerService. activateHandler (id, handler), & call
handlerService. deactivateHandlers (Collection<IHandlerActivation>) in my perform{Cancel, Finish}
methods. But the handler.execute() is never called. I'm sure I've got the id right (I just copied it
from your email) and I also tried with F2, for which I have (as mentioned) a working handler in the
main app (so that id must be the right one), and it also fails, same way: handler.execute() is never
called.

I'll try the option 1, but am not sanguine ...

Any ideas?

thanks
Paul

Paul Webster wrote:

> But I thought the deal was that you wanted CTRL+C to work, with your
> command, within the dialog? Since dialog beats dialogAndWindow, why not
> define the keybinding and just point to your command:
>
> <key
> commandId="com.mun.ist.my.commands.CopySomething"
> contextId="org.eclipse.ui.contexts.dialog"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
> sequence="M1+C"/>
>
> While the dialog is open CTRL+C will point to your CopySomething command
> instead of the org.eclipse.ui.edit.copy command.
>
> Option 2 ... the copy command is still valid while your dialog is open.
> Why not just supply a handler for it? When you create your dialog, you
> should be able to get the global handler service from the workbench ...
> workbench.getAdapter(IHandlerService.class) (in 3.2 it's called
> getService(*)).
>
> Then activate a handler for the org.eclipse.ui.edit.copy command.
> org.eclipse.core.commands.AbstractHandler is a base implementation of
> IHandler. Save the IHandlerActivation, and then when your dialog closes
> deactivate that handler.
>
>
> If the stars are aligned, this should give you a dialog copy command
> that responds to CTRL+C while your dialog is up :-)
>
> Later,
> PW
Re: [HowTo] re-use key-binding in wizard? [message #452437 is a reply to message #452037] Wed, 05 July 2006 16:17 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Paul Keyser wrote:
> id must be the right one), and it also fails, same way:
> handler.execute() is never called.

I looked into this. There is a default global handler for
org.eclipse.ui.edit.copy,
org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy. When your
dialog contributes a global handler for copy, there are 2 global
handlers active at the same time, and the command framework disables
both of them.

The command framework looks at all handlers that say they are active,
and then picks one based on priority. The more specific the expression,
the higher the priority, and the one with the highest priority wins.

ex:
global handlers are 0
a handler tied to the active window is higher
a handler tied to the active part is higher

So an expression can get your handler for org.eclipse.ui.edit.copy
working in your dialog.

ex - I'm launching my dialog from an action (which has fWindow):

protected Control createDialogArea(Composite parent) {
handlerService = (IHandlerService) fWindow.getWorkbench()
.getService(IHandlerService.class);
AbstractHandler handler = new AbstractHandler() {
public Object execute(ExecutionEvent event)
throws ExecutionException {
System.out.println("Run my copy handler, or get fish-slapped");
return null;
}
};
activeHandler = handlerService.activateHandler(
"org.eclipse.ui.edit.copy", handler,
new ActiveShellExpression(getShell()));
return super.createDialogArea(parent);
}

public boolean close() {
handlerService.deactivateHandler(activeHandler);
activeHandler.getHandler().dispose();
return super.close();
}

Obviously, make sure your code is robust. But the ActiveShellExpression
(which is tied to my dialog shell) bumps my handler priority above 0.

Also, since the shell is disposed on a close, don't forget to deactivate
your handler.

Later,
PW


Re: [HowTo] re-use key-binding in wizard? [message #452629 is a reply to message #452437] Mon, 10 July 2006 21:08 Go to previous message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Paul Webster wrote:
>
> The command framework looks at all handlers that say they are active,
> and then picks one based on priority. The more specific the expression,
> the higher the priority, and the one with the highest priority wins.
>
> ex:
> global handlers are 0
> a handler tied to the active window is higher
> a handler tied to the active part is higher
>
> So an expression can get your handler for org.eclipse.ui.edit.copy
> working in your dialog.
>
Ah -- I did not think of that at all, thanks.

> ex - I'm launching my dialog from an action (which has fWindow):
>
> protected Control createDialogArea(Composite parent) {
> handlerService = (IHandlerService) fWindow.getWorkbench()
> .getService(IHandlerService.class);
> AbstractHandler handler = new AbstractHandler() {
> public Object execute(ExecutionEvent event)
> throws ExecutionException {
> System.out.println("Run my copy handler, or get fish-slapped");
> return null;
> }
> };
> activeHandler = handlerService.activateHandler(
> "org.eclipse.ui.edit.copy", handler,
> new ActiveShellExpression(getShell()));
> return super.createDialogArea(parent);
> }
>
Hmm -- are you in Eclipse 3.2? I ask, b/c in 3.1.2 (where I am), IHandlerService.activateHandler(,,
Expression) requires a fourth parameter, an int. (The javadocs to IHandlerService.activateHandler()
and IHandlerActivation.getSourcePriority() do not explain how values of that int will be
interpreted, but I guessed from your email that the more positive int is the higher priority.)

Logarithmic search through positive int's showed that 1000 (and smaller) fail, but that 10000 (and
larger) work, at least for "org.eclipse.ui.edit.copy" -- even Integer.MAX_VALUE fails for
"org.eclipse.ui.edit.delete", "org.eclipse.ui.edit.rename", and "org.eclipse.ui.newWizard". But in
the three cases for which the handler-mechanism fails, at least my key-listener works ('DEL', 'F2',
'CTRL-n').

thanks,
Paul
Previous Topic:Adding help and more product export issues
Next Topic:how to put a toolbar item to the right of the toolbar line
Goto Forum:
  


Current Time: Tue Mar 19 10:52:43 GMT 2024

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

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

Back to the top