Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Handling focus change in a FormPage
Handling focus change in a FormPage [message #334979] Fri, 13 March 2009 10:57 Go to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

In order to enable/disable the global cut/copy/paste actions, I need to
be able to detect when any Text gains focus in any FormPage in any of my
FormEditor classes.
I looked at the PDEFormEditor and its associated classes for a hint on
how to accomplish this, and it looks like they use a special wrapper
around all Text widgets that registers a FocusListner. That is not a
good option for me because a) our editors are already written and
retro-fitting them like that would be a pretty big piece of work, and b)
I find that to be too error-prone; if someone adds a new Text and
doesn't realize they should have used the wrapper, it won't contribute
correctly.
My first attempt at a solution was to add a hook in my
BaseFormPage.createPartControl() that registers a FocusListener on all
Text children after they've been created. That works for most cases, but
if a FormPage has a MasterDetailsBlock [or any other situation where
nested Controls are created dynamically after createPartControl()], it
fails to include the dynamically-created Texts.
My only other idea is to add a Display-level filter Listener on
SWT.FocusIn and SWT.FocusOut events. I'm not sure if that is going to be
a performance problem since, for each event, I have to determine if the
widget gaining focus is in one of my FormPage instances or not.

Any thoughts on those solutions or some alternative way of
enabling/disabling the cut/copy/paste actions in a custom FormEditor?

Thanks in advance,
Eric
Re: Handling focus change in a FormPage [message #335013 is a reply to message #334979] Mon, 16 March 2009 12:35 Go to previous messageGo to next message
Eclipse UserFriend
The FocusListener you have seen in PDEFormEditor is to remember the
control that had the focus when the page lost focus. FormPage.setFocus()
is called when a page is activated and lastFocusControl is used to set
the focus again. This is smart. I followed the logic for my editor pages
and found it to work in the same way, but I have not figured out how
they remember controls of DetailsPage. We should give a thumbs up to PDE
folks for this good usability.

As far as implementing global actions, look at its
EditorActionContributor. Do not forget to register the actions. There is
also a FAQ -
http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_action s%2C_such_as_Copy_and_Delete%3F.

Post back your results. My team struggled to make the global actions
work because of simple mistakes.
Re: Handling focus change in a FormPage [message #335023 is a reply to message #334979] Mon, 16 March 2009 22:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bvitale.alumni.unh.edu

You may be able to define a command handler for those commands, which is
only active when your controls have focus.

See:

http://help.eclipse.org/ganymede/topic/org.eclipse.platform. doc.isv/guide/workbench_cmd_handlers.htm

ISources#ACTIVE_FOCUS_CONTROL_ID_NAME
IFocusService#addFocusTracker(Control control, String id)

Hope that helps
Ben

Eric Rizzo wrote:
> In order to enable/disable the global cut/copy/paste actions, I need to
> be able to detect when any Text gains focus in any FormPage in any of my
> FormEditor classes.
> I looked at the PDEFormEditor and its associated classes for a hint on
> how to accomplish this, and it looks like they use a special wrapper
> around all Text widgets that registers a FocusListner. That is not a
> good option for me because a) our editors are already written and
> retro-fitting them like that would be a pretty big piece of work, and b)
> I find that to be too error-prone; if someone adds a new Text and
> doesn't realize they should have used the wrapper, it won't contribute
> correctly.
> My first attempt at a solution was to add a hook in my
> BaseFormPage.createPartControl() that registers a FocusListener on all
> Text children after they've been created. That works for most cases, but
> if a FormPage has a MasterDetailsBlock [or any other situation where
> nested Controls are created dynamically after createPartControl()], it
> fails to include the dynamically-created Texts.
> My only other idea is to add a Display-level filter Listener on
> SWT.FocusIn and SWT.FocusOut events. I'm not sure if that is going to be
> a performance problem since, for each event, I have to determine if the
> widget gaining focus is in one of my FormPage instances or not.
>
> Any thoughts on those solutions or some alternative way of
> enabling/disabling the cut/copy/paste actions in a custom FormEditor?
>
> Thanks in advance,
> Eric
Re: Handling focus change in a FormPage [message #335243 is a reply to message #335013] Fri, 27 March 2009 10:40 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 3/16/2009 12:35 PM, Vel wrote:
> The FocusListener you have seen in PDEFormEditor is to remember the
> control that had the focus when the page lost focus. FormPage.setFocus()
> is called when a page is activated and lastFocusControl is used to set
> the focus again. This is smart. I followed the logic for my editor pages
> and found it to work in the same way, but I have not figured out how
> they remember controls of DetailsPage. We should give a thumbs up to PDE
> folks for this good usability.

I would, except it does not always work very well. When I swtich away
from a plugin editor Extensions tab, for example, and then switch back,
it usually does not correctly remember which node in the tree I had
selected. It is actually quite irritating.

>
> As far as implementing global actions, look at its
> EditorActionContributor. Do not forget to register the actions. There is
> also a FAQ -
> http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_action s%2C_such_as_Copy_and_Delete%3F.
>
>
> Post back your results. My team struggled to make the global actions
> work because of simple mistakes.

I'm already there; the problem I have now is enabling and disabling my
actions at the right time, based on what widget has focus.
Previous Topic:Context menu for vertical ruler?
Next Topic:eclipse-Automated-Tests-3.4.zip produces compile errors
Goto Forum:
  


Current Time: Sat May 03 10:35:35 EDT 2025

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

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

Back to the top