Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Focus problem with ViewPart and Editor
Focus problem with ViewPart and Editor [message #647919] Mon, 10 January 2011 13:20 Go to next message
Christian Stellwag is currently offline Christian StellwagFriend
Messages: 48
Registered: July 2009
Location: Munich
Member
Hi,

we encountered the following focus issue / problem in a RCP application (3.6):

We have a ViewPart with command handlers in Toolbar and ContextMenu that work perfectly at the beginning when this ViewPart has focus.
E.g. the command 'Edit' opens an Editor for a given selected item. Thereafter Editor has got the Focus.
Now i click back into ViewPart to do some other action. But now Focus (imho erratically) stays in Editor and won't switch to ViewPart, thus all command (handlers) not shown or active.

Only clicking on 'Tab' on top will give focus to this ViewPart but no clicks on content (e.g. list, tree, ..) will do so.

This occurs frequently but not always!

Anybody having the same problem or does anybody know how to solve this?

Thank you for your help,
chris
Re: Focus problem with ViewPart and Editor [message #647927 is a reply to message #647919] Mon, 10 January 2011 13:44 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Did you implement your view part setFocus(*) method?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Focus problem with ViewPart and Editor [message #648169 is a reply to message #647927] Tue, 11 January 2011 15:23 Go to previous messageGo to next message
Christian Stellwag is currently offline Christian StellwagFriend
Messages: 48
Registered: July 2009
Location: Munich
Member
Hi Paul,

we implemented the setFocus() method and set the focus to the content, i.e. JFace Viewer (tree or table) control.

Is that the correct way?

The setFocus() method is not called then, even though ViewPart doesn't have focus.

IWorkbenchPart javadoc says that after setFocus() is called a partActivated event is triggered. I'll have a look if s.o. used that.

chris

[Updated on: Tue, 11 January 2011 15:34]

Report message to a moderator

Re: Focus problem with ViewPart and Editor [message #648218 is a reply to message #648169] Tue, 11 January 2011 20:21 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 01/11/2011 10:23 AM, chris wrote:
> we implemented the setFocus() method and set the focus to the content,
> i.e. JFace Viewer (tree or table) control.
>
> Is that the correct way?

Yes, that's it. I've seen a lot of viewer.getControl().setFocus()

When the workbench window activates a part (when a user clicks on a tab,
for example) the WW calls part.setFocus() to make sure the cursor is
somewhere useful in the part. Otherwise focus might end up on the text
in the tab :-)

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Focus problem with ViewPart and Editor [message #648266 is a reply to message #648218] Wed, 12 January 2011 08:08 Go to previous messageGo to next message
Christian Stellwag is currently offline Christian StellwagFriend
Messages: 48
Registered: July 2009
Location: Munich
Member
Hi Paul,

unfortunately we sometimes observe the already described behavior that ViewPart doesn't have the focus (Editor has) and a click on the content area (list viewer) of the ViewPart doesn't trigger the setFocus method.

I logg setFocus and can see that it isn't called sometimes.

I guess this shouldn't happen - but well, i observe it. Any additional idea is appreciated. Do I have to implement anything within the ViewPart children (some setFocus method there; but yes, it's only a ListViewer component)?

One idea I had was that the ViewPart doesn't lose focus correctly, i.e. for example I forget to implement setFocus in EditorPart?

Just a more general question for my understanding:
EditorPart has void setFocus() method, each control has it's own boolean setFocus() method which (must) return true if it accepts focus.

When user clicks on some part of the editor, which setFocus is called?
- The one from the control under mouse cursor or the one in EditorPart? or both? in which sequence?
What happens if i delegate focus from EditorPart to another control?

To me it seems that
first EditorPart.setFocus is called which might delegate to some control and after that ControlUnderMouseCursor.setFocus is called. So in the end the control under mouse cursor receives the focus.

Sometimes you can observe the cursor jump into the delegated control (from EditorPart) for a very short time.

Chris
Re: Focus problem with ViewPart and Editor [message #648411 is a reply to message #648266] Wed, 12 January 2011 19:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It's the EditorPart or ViewPart setFocus() that the framework calls.
It's up to each editor/view to call control.setFocus() on something
appropriate. The framework won't call the SWT setfocus. set focus in
this case is a result of either programmatically activating a part of of
clicking on a tab.

clicking in a control in a view has a slightly different path, since
you've already determined what control has the focus. The workbench
gets an SWT.Activate event which allows it to update the active part ...
we won't go back and call EditorPart.setFocus() because that would
potentially move the focus widget within the part the user has already
clicked.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Focus problem with ViewPart and Editor [message #648481 is a reply to message #648411] Thu, 13 January 2011 06:22 Go to previous messageGo to next message
Christian Stellwag is currently offline Christian StellwagFriend
Messages: 48
Registered: July 2009
Location: Munich
Member
Hi Paul,

thanks for you explanations.
It helps understanding this focus mechanism.

chris
Re: Focus problem with ViewPart and Editor [message #648505 is a reply to message #648481] Thu, 13 January 2011 09:59 Go to previous message
Christian Stellwag is currently offline Christian StellwagFriend
Messages: 48
Registered: July 2009
Location: Munich
Member
Hi all,

I think i know the reason for that behavior now:

Remember: ViewPart opens Editor via some command.

In some cases our Editor's setFocus method tried to delegate focus to a SWT control which was disabled thus not taking focus (false returned).
Editor ignored that return value resulting in following state:
- Editor has focus but no control within has focus
- ViewPart had lost focus
(Probably SWT's and WorkbenchPart's focus are now out-of-sync)

Now clicking back into ViewPart doesn't give focus back to Viewpart, setFocus is not called by framework.

Remedy: Always assure that you delegate focus to a control that takes it (returns true).
If that isn't possible (all controls disabled) I don't have an idea what to do.

Maybe it's also possible from Eclipse's side to call ViewParts setFocus method in this special case?!

Best regards,
Chris
Previous Topic:Hide "External Tools" action set
Next Topic:Widget <-> View (ID)
Goto Forum:
  


Current Time: Fri Nov 28 07:20:53 GMT 2014

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

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