Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 422720

Summary: [KeyBindings] Context based key Binding for commands not working after upgrading to eclipse 4.2.2
Product: [Eclipse Project] Platform Reporter: ALOK MANJREKAR <alokmanjrekar>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: RESOLVED WORKSFORME QA Contact: Paul Elder <pelder.eclipse>
Severity: critical    
Priority: P3 CC: daniel_megert, pwebster, tsundara, twhitmore.nz
Version: 4.2.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Context binding screenshots
none
Sample view with Canvas none

Description ALOK MANJREKAR CLA 2013-11-27 17:30:56 EST
Created attachment 237769 [details]
Context binding screenshots

Context Binding for commands not working after upgrading to eclipse 4.2.2

Hello,
We have an eclipse RCP Product where we use context binding for our canvas based editors.
In the current release we upgraded the eclipse version leveraged by our RCP product from 3.7.2 to 4.2.2
After upgrading, we have run into an issue where the context binding stops working intermittently. The keys registered in the bindings to associate a command with a sequence(shortcut) stops working all of a sudden, which has caused a lot of usability concern to our RCP Product.

Here is what we are doing

1)	We have a base context. Let’s call it “com.xyz.ui.canvaseditor”. 
It is registered as mentioned below.

<extension
                point=”org.eclipse.ui.contexts”>
             <context
                   description=”%CANVAS_EDITING_DESCRIPTION”
                   id=”com.xyz.ui.canvaseditor”
                   name=”%CANVAS_EDITING”
                   parentId=”org.eclipse.ui.contexts.window”>
             </context>
          </extension>


2)	We have a concrete context. Lets call it “com.xyz.ui.mapping.canvasEditor” . It is registered as follows. Please note that the parent id of this context is the one that is registered is point number 1.

<extension
		point=”org.eclipse.ui.contexts”>
      <context
            id=” com.xyz.ui.mapping.canvasEditor “
            name=”%MAPPING_CANVAS_CONTEXT_NAME”
            parentId=” com.xyz.ui.canvaseditor “>
      </context>
   </extension>

3)	The plugin which has the extension mentioned in point number 2 is dependent on the plugin which has the extension mentioned in point number 1/

4)	We have a bunch of bindings where we register sequences for commands against the contextId mentioned in point number 2.

5)	In the editor implementation which embeds the SWT Canvas, we have the following code – which adds a focus listener on the swt canvas.

We would like to activate the context when focus is gained and de-activate the context when the focus is lost from the SWT Canvas.

getCanvas().addFocusListener(new FocusListener() {
			public void focusGained(FocusEvent e) {
				setCanvasEditorContext(getPart(), true, “com.xyz.ui.mapping.canvasEditor”), 
			}
			public void focusLost(FocusEvent e) {
				setCanvasEditorContext(getPart(), false, “com.xyz.ui.mapping.canvasEditor”) 
}
		});

The implementation of setCanvasEditorContext(IeditorPart part, Boolean activate) looks like this

public static final void setCanvasEditorContextActive(IworkbenchPart part, Icanvas canvas,  oolean active, String contextID) {
		IcontextService service = (IcontextService)part.getSite().getService(IcontextService.class);
		if (active) {
			service.activateContext(contextID));	
		} else {
			service.deactivateContext(activation);
		}
	}

6)	After upgrading to eclipse 4.2.2, we have found that even though the SWT Canvas is in focus and it has activated the context, the binding sequence that were registered with that context are not appearing for the commands. 
I have attached a word document that shows the sequence bindings appearing for the commands in the menu, when it is working fine, and when it does not work fine.

None of the extensions or implementation code within our RCP Product has changed when we upgrade from eclipse 3.7.2 to eclipse 4.2.2. 

This appears to be some regression in eclipse 4.2.2 that seems to be causing this change in behavior.
Comment 1 Paul Webster CLA 2013-11-29 11:18:02 EST
The bindings don't show in the menu, but do they still work?

PW
Comment 2 Thiagarajan Sundaramurthy CLA 2013-12-02 14:53:50 EST
(In reply to Paul Webster from comment #1)
> The bindings don't show in the menu, but do they still work?
> 
> PW

Yes, it works.
Comment 3 ALOK MANJREKAR CLA 2013-12-04 14:39:24 EST
No, The bindings stop working. 
The state reflected in the menu in the UI is accurate.
The shortcuts no longer work when the combination is tried via the keyboard.
Comment 4 Paul Webster CLA 2013-12-12 15:58:35 EST
Created attachment 238304 [details]
Sample view with Canvas

Alok, I can't reproduce the problem (setting the context on focus in activates the keybindings).

Can you please modify the attached sample project to reproduce the problem and re-attach?  Or debug through your system to see what's going on, is the context being activated, is it being processed, when deactivated is the correct IContextActivation used, etc?

PW
Comment 5 Thomas Whitmore CLA 2013-12-12 17:24:48 EST
I'm having problems with key-bindings repeatedly stopping working in 4.2 Kepler SR1 also, with my preferred bindings (Rename in File, Search Write References).

I've even found Ctrl-Left, Ctrl-Right word left/right & Ctrl-1 "quick fix" to stop working, after a while.. though 'plain' arrow keys & typing continued to work.

There's something badly broken in Kepler.
Comment 6 Paul Webster CLA 2013-12-12 17:44:00 EST
(In reply to Thomas Whitmore from comment #5)
> I'm having problems with key-bindings repeatedly stopping working in 4.2
> Kepler SR1 also, with my preferred bindings (Rename in File, Search Write
> References).

In a canvas?  I suspect you need to open a new bug against Kepler (4.3.1).  Please include a usecase of steps where you can see keybindings stop working.

PW
Comment 7 ALOK MANJREKAR CLA 2013-12-20 14:00:59 EST
(In reply to Paul Webster from comment #4)
> Created attachment 238304 [details]
> Sample view with Canvas
> 
> Alok, I can't reproduce the problem (setting the context on focus in
> activates the keybindings).
> 
> Can you please modify the attached sample project to reproduce the problem
> and re-attach?  Or debug through your system to see what's going on, is the
> context being activated, is it being processed, when deactivated is the
> correct IContextActivation used, etc?
> 
> PW

PW,
The problem does not happen soon after we activate the context when the canvas gets focus.
While the focus is in the canvas, if we keep trying to use the context-binding, or launch the context menu to see the available menu options (along with their key bindings), the context-bindings all of a sudden stop working somewhere down the line.
I confirmed that the canvas is still in focus, and that no call has been made from our product implementation to deactivate the context during this time.

Once this happens, and we focus out of the canvas and focus back in, the context binding starts working - but then it again stops working after one or two uses of it.

-Alok
Comment 8 Paul Webster CLA 2013-12-20 14:48:22 EST
(In reply to ALOK MANJREKAR from comment #7)
> Once this happens, and we focus out of the canvas and focus back in, the
> context binding starts working - but then it again stops working after one
> or two uses of it.

But you can't reproduce with my example,right?  Multiple calls to the keybinding when the canvas is in focus still work.

Is there anything else in your workflow to failure?  Do you open context menus?

PW
Comment 9 ALOK MANJREKAR CLA 2013-12-23 17:24:43 EST
(In reply to Paul Webster from comment #8)
> (In reply to ALOK MANJREKAR from comment #7)
> > Once this happens, and we focus out of the canvas and focus back in, the
> > context binding starts working - but then it again stops working after one
> > or two uses of it.
> 
> But you can't reproduce with my example,right?  Multiple calls to the
> keybinding when the canvas is in focus still work.
> 
> Is there anything else in your workflow to failure?  Do you open context
> menus?
> 
> PW

PW,
I haven't yet tried the sample that you had attached. I'll try it and send an update. 
To answer your 2nd question - Yes, I do open context menu. The pop-up context menu
on the canvas would show the binding initially. But then later the binding does not show up on the context menu, and the binding short-cut stops working as well..
Comment 10 Paul Webster CLA 2013-12-23 18:31:18 EST
(In reply to ALOK MANJREKAR from comment #9)
> I haven't yet tried the sample that you had attached. I'll try it and send
> an update. 

Thanks Alok.

> To answer your 2nd question - Yes, I do open context menu. The pop-up
> context menu
> on the canvas would show the binding initially. But then later the binding
> does not show up on the context menu, and the binding short-cut stops
> working as well..

How do you create the context menu on your canvas?  Do you have 2 registered for your view?

PW
Comment 11 Dani Megert CLA 2014-07-08 09:56:35 EDT
Please reopen if you can still reproduce using a latest Luna build, e.g.
http://download.eclipse.org/eclipse/downloads/drops4/R-4.4-201406061215/

If you reopen, please make sure to answer the questions from the previous comments. Thanks.