You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Tomas Stenlund <to...@telia.com> on 2012/08/23 08:30:02 UTC
Dialog opened from menu loses focus
Hi,
I haven't actually thought about this until recently. But when a dialog
is opened from a menu selection it first gets the focus, but then looses
it when the menu redraws itself. It works as expected when the dialog is
started from a button. I have made a simple example attached here. I'm
using Pivot 2.0.2. Anybody noticed the same behaviour ?
It seems related to PIVOT-213.
Cheers,
Tomas
RE: Dialog opened from menu loses focus
Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
We have been able to live without the blocking dialog by using a queue of events that can get triggered when the preceding dialogs finish. But, in general, I'd say life would be easier with blocking dialogs.
~Roger Whitcomb
-----Original Message-----
From: Josh R [mailto:tripanonyr@gmail.com]
Sent: Thursday, August 23, 2012 8:46 AM
To: user@pivot.apache.org
Subject: Re: Dialog opened from menu loses focus
On Thu, Aug 23, 2012 at 11:37 AM, Sandro Martini <sa...@gmail.com> wrote:
> Hi all,
> yes probably the best solution for now is what suggested by Josh,
> because focus management (and focus inside components) is a complex
> part inside Pivot.
>
> For mid/long term we could think on how to solve the problem, but for 2.1 .
>
>
> Note:
> I still have to ask to Thomas (the author of blockingdialog etc
> features under pivot-contrib) if he is interested to become a Pivot
> Committer, and then maybe move that part in core Pivot (maybe for 2.1)
> ...
Hi - Irrespective of how it's implemented, a blocking window should be a must-have feature. Otherwise without this component it will be impossible to enforce certain workflow-restrictions in the GUI. Agreed that for now we can just use the external-jar.
thanks
Re: Dialog opened from menu loses focus
Posted by Josh R <tr...@gmail.com>.
On Thu, Aug 23, 2012 at 11:37 AM, Sandro Martini
<sa...@gmail.com> wrote:
> Hi all,
> yes probably the best solution for now is what suggested by Josh,
> because focus management (and focus inside components) is a complex
> part inside Pivot.
>
> For mid/long term we could think on how to solve the problem, but for 2.1 .
>
>
> Note:
> I still have to ask to Thomas (the author of blockingdialog etc
> features under pivot-contrib) if he is interested to become a Pivot
> Committer, and then maybe move that part in core Pivot (maybe for 2.1)
> ...
Hi - Irrespective of how it's implemented, a blocking window should
be a must-have feature. Otherwise without this component it will be
impossible to enforce certain workflow-restrictions in the GUI. Agreed
that for now we can just use the external-jar.
thanks
Re: Dialog opened from menu loses focus
Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
so I think that it would be better to open a JIRA issue for 2.1 ...
Josh, if you can, would be great.
Thank you.
Bye
RE: Dialog opened from menu loses focus
Posted by Jumbo <p_...@yahoo.com>.
Thanks a lot Oliver for sharing your solution.
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Dialog-opened-from-menu-loses-focus-tp4022067p4022449.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
RE: Dialog opened from menu loses focus
Posted by Oliver Oyston <Ol...@actian.com>.
I worked around the problem using a custom skin - perhaps not the most
elegant solution but it works...
The custom skin is registered at an appropriate place (application
startup / constructor / etc).
// Use a customized skin for menu items
theme.set(Menu.Item.class, CustomMenuItemSkin.class);
Our main class exposes the mainWindow like this:
/**
* The main application window (top-level Pivot object).
*/
@BXML public static Window mainWindow;
I renamed our main class to "MainClass" in the snippet below - you will
need to implement this as appropriate for your application or alter the
skin to make it more generic
package your.package.name.here;
import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.Menu;
import org.apache.pivot.wtk.MenuPopup;
import org.apache.pivot.wtk.MenuPopupStateListener;
import org.apache.pivot.wtk.Mouse;
import org.apache.pivot.wtk.skin.terra.TerraMenuItemSkin;
/**
* Custom skin to ensure that the transition effects of the context menu
does not cause the stealing of focus from dialogs.
*/
public class CustomMenuItemSkin extends TerraMenuItemSkin {
@Override
public boolean mouseUp(Component component, Mouse.Button button, int
x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
Menu.Item menuItem = (Menu.Item)getComponent();
if (menuItem.isActive()) {
MenuPopup popup;
// Find the first MenuPopup container for the component.
Container container = component.getParent();
do {
if (container.getClass() == MenuPopup.class){
// We found a menu popup
popup = (MenuPopup)container;
// Disable the main window.
MainClass.mainWindow.setEnabled(false);
popup.getMenuPopupStateListeners().add(new
MenuPopupStateListener() {
@Override
public Vote previewMenuPopupClose(MenuPopup
components, boolean b) {
return Vote.APPROVE;
}
@Override
public void menuPopupCloseVetoed(MenuPopup
components, Vote vote) {
}
@Override
public void menuPopupClosed(MenuPopup
components) {
// Enable the main window.
MainClass.mainWindow.setEnabled(true);
// Remove listener.
components.getMenuPopupStateListeners().remove(this);
}
});
// Break out of the loop.
break;
}
}
while ((container = container.getParent()) != null);
// Execute the menu press
menuItem.press();
}
return consumed;
}
}
Hope this helps.
Oli
-----Original Message-----
From: Jumbo [mailto:p_kowshik@yahoo.com]
Sent: Friday, February 15, 2013 2:35 AM
To: user@pivot.apache.org
Subject: RE: Dialog opened from menu loses focus
Hi Roger,
Is it possible for you to share how you have resolved this issue by
sub-classing the menu and disabling the transition animations?
Thanks.
--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/Dialog-opened-from-menu-l
oses-focus-tp4022067p4022441.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
RE: Dialog opened from menu loses focus
Posted by Jumbo <p_...@yahoo.com>.
Hi Roger,
Is it possible for you to share how you have resolved this issue by
sub-classing the menu and disabling the transition animations?
Thanks.
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Dialog-opened-from-menu-loses-focus-tp4022067p4022441.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
Re: Dialog opened from menu loses focus
Posted by Tomas Stenlund <to...@telia.com>.
Thanks Roger,
I'm not really sure I understand what you are saying. If I try to
set the focus after I open the dialog (in the menu action) it does
not alter the behavior, i.e. the focus still ends up in the main window
with the menu bar.
I have debugged pivot while running this and (not unexpected) the
GUI behaves as i should during the debug session, i.e. when I step
through the code. But as soon as I run it full speed the dialog
looses focus. So for sure a timing issue. I have also tried to
experiment a little with the transitions in the skin but to no avail. As
one of you said earlier a complex thing this with focus and I have not
been able to wrap my brain around it yet. So if you could explain a bit
more what you have done I am all ear :-)
In addition to this what I have seen is if I disable "enable(false)" the
window
that contains the menu bar the focus stays with the dialog I open in the
menu action. i.e. the GUI behaves as expected.
Cheers,
Tomas
On 08/23/2012 06:13 PM, Roger L. Whitcomb wrote:
> So, we have seen this too. The first manifestation was what you saw,
> and we solved that one by just putting focus on the first component (or
> the Window) after the "open" call of the dialog. But, the second
> instance of the problem was when we tried to open some dialogs in a
> second host window. That one we had to work around by disabling the
> transition animations of the menus. Something in the event handling of
> the animation timer was stealing focus from the secondary host window.
> Haven't had time yet to figure that one out. But, subclassing the menu
> and disabling the transition was a reasonable workaround for us.
>
> ~Roger
>
> -----Original Message-----
> From: Sandro Martini [mailto:sandro.martini@gmail.com]
> Sent: Thursday, August 23, 2012 8:38 AM
> To: user@pivot.apache.org
> Subject: Re: Dialog opened from menu loses focus
>
> Hi all,
> yes probably the best solution for now is what suggested by Josh,
> because focus management (and focus inside components) is a complex part
> inside Pivot.
>
> For mid/long term we could think on how to solve the problem, but for
> 2.1 .
>
>
> Note:
> I still have to ask to Thomas (the author of blockingdialog etc features
> under pivot-contrib) if he is interested to become a Pivot Committer,
> and then maybe move that part in core Pivot (maybe for 2.1) ...
>
>
> Bye,
> Sandro
>
RE: Dialog opened from menu loses focus
Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
So, we have seen this too. The first manifestation was what you saw,
and we solved that one by just putting focus on the first component (or
the Window) after the "open" call of the dialog. But, the second
instance of the problem was when we tried to open some dialogs in a
second host window. That one we had to work around by disabling the
transition animations of the menus. Something in the event handling of
the animation timer was stealing focus from the secondary host window.
Haven't had time yet to figure that one out. But, subclassing the menu
and disabling the transition was a reasonable workaround for us.
~Roger
-----Original Message-----
From: Sandro Martini [mailto:sandro.martini@gmail.com]
Sent: Thursday, August 23, 2012 8:38 AM
To: user@pivot.apache.org
Subject: Re: Dialog opened from menu loses focus
Hi all,
yes probably the best solution for now is what suggested by Josh,
because focus management (and focus inside components) is a complex part
inside Pivot.
For mid/long term we could think on how to solve the problem, but for
2.1 .
Note:
I still have to ask to Thomas (the author of blockingdialog etc features
under pivot-contrib) if he is interested to become a Pivot Committer,
and then maybe move that part in core Pivot (maybe for 2.1) ...
Bye,
Sandro
Re: Dialog opened from menu loses focus
Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
yes probably the best solution for now is what suggested by Josh,
because focus management (and focus inside components) is a complex
part inside Pivot.
For mid/long term we could think on how to solve the problem, but for 2.1 .
Note:
I still have to ask to Thomas (the author of blockingdialog etc
features under pivot-contrib) if he is interested to become a Pivot
Committer, and then maybe move that part in core Pivot (maybe for 2.1)
...
Bye,
Sandro
Re: Dialog opened from menu loses focus
Posted by Tomas Stenlund <to...@telia.com>.
Thanks for the suggestion,
the problem with that solution is that the menu will then stay expanded.
Which I guess for the user would be kind of an odd behaviour, probably
more odd than the dialog not getting the focus. Unless I did something
wrong when I tested this of course.
Cheers,
Tomas
On 08/23/2012 05:19 PM, Josh R wrote:
> On Thu, Aug 23, 2012 at 2:30 AM, Tomas Stenlund
> <to...@telia.com> wrote:
>> Hi,
>>
>> I haven't actually thought about this until recently. But when a dialog is
>> opened from a menu selection it first gets the focus, but then looses it
>> when the menu redraws itself. It works as expected when the dialog is
> Have you looked at the blockingdialog :
> http://code.google.com/a/apache-extras.org/p/pivot-contrib/wiki/GuretzkiFeatures
> If you want to block the user then this is the dialog you can use. I
> spent an entire day and then found a solution on this list.
>
> Download the contrib jar from the above link(I just add it to
> external-jars on my eclipse build-path). Add this code in your
> Main.java
>
>
> //dialog.setModal(false);
> //dialog.open(Main.this);
>
> Dialog d = new Dialog("my-dialog", true);
> BlockingDialog bd = new BlockingDialog();
> bd.setContent(d);
> bd.open(Main.this.getDisplay());
>
>
> Let us know how it goes....
>
>
>> Cheers,
>> Tomas
> thanks
>
Re: Dialog opened from menu loses focus
Posted by Josh R <tr...@gmail.com>.
> Download the contrib jar from the above link(I just add it to
> external-jars on my eclipse build-path). Add this code in your
> Main.java
>
>
> //dialog.setModal(false);
> //dialog.open(Main.this);
>
> Dialog d = new Dialog("my-dialog", true);
> BlockingDialog bd = new BlockingDialog();
> bd.setContent(d);
> bd.open(Main.this.getDisplay());
>
>
Once you get the above working then try this:
Add the following in Main.java
public class MyForm {
Form form;
TextInput ti1;
Form.Section section;
public MyForm() {
form = new Form();
ti1 = new TextInput();
section = new Form.Section();
section.add(ti1);
section.add(new Label()); /* to create empty space */
form.getSections().add(section);
Form.setFlag(ti1, "{messageType:'info', message:'Enter chars only.'}");
}
}
.....
//dialog.setModal(false);
//dialog.open(Main.this);
Dialog d = new Dialog("my-dialog", true);
BlockingDialog bd = new BlockingDialog();
MyForm ahf = new MyForm();
d.setContent(ahf.form);
bd.setContent(d);
bd.open(Main.this.getDisplay());
Run the app, click the button and then point the mouse at the
text-field and watch the tool-tip pop-up .... Pivot's awesome, isn't
it ;) ?
thanks
Re: Dialog opened from menu loses focus
Posted by Josh R <tr...@gmail.com>.
On Thu, Aug 23, 2012 at 2:30 AM, Tomas Stenlund
<to...@telia.com> wrote:
> Hi,
>
> I haven't actually thought about this until recently. But when a dialog is
> opened from a menu selection it first gets the focus, but then looses it
> when the menu redraws itself. It works as expected when the dialog is
Have you looked at the blockingdialog :
http://code.google.com/a/apache-extras.org/p/pivot-contrib/wiki/GuretzkiFeatures
If you want to block the user then this is the dialog you can use. I
spent an entire day and then found a solution on this list.
Download the contrib jar from the above link(I just add it to
external-jars on my eclipse build-path). Add this code in your
Main.java
//dialog.setModal(false);
//dialog.open(Main.this);
Dialog d = new Dialog("my-dialog", true);
BlockingDialog bd = new BlockingDialog();
bd.setContent(d);
bd.open(Main.this.getDisplay());
Let us know how it goes....
> Cheers,
> Tomas
thanks