JDialog is not getting focussed - focus

I have done code below but some how I am not able to set focus on JDialog :(
loginDialog.requestFocusInWindow() returns false. Is there is any way to get focus on JDialog?
LoginDialog.this.txt_PASSWORD.requestFocusInWindow() also returns false.
Esc button press event is also not working
this.loginDialog = new JDialog();
this.loginDialog.setTitle(applicationName+Keys.BLANK+Keys.DASH+Keys.BLANK+Messages.getMessage(IMessageKeys.LOGIN));
this.loginDialog.setModal(true);
this.loginDialog.setLayout(new BorderLayout());
this.loginPanel=getLoginPane();
this.buttonPanel=getButtonPanel();
this.infoLabel.setText(Keys.BLANK);
this.loginDialog.add(this.infoLabel,BorderLayout.NORTH);
this.loginDialog.add(this.loginPanel,BorderLayout.CENTER);
this.loginDialog.add(this.buttonPanel,BorderLayout.SOUTH);
this.loginDialog.setSize(370, 236);
this.loginDialog.setResizable(false);
this.loginDialog.setLocationRelativeTo(null);
objLogger.debug("Login dialog init method call end"); //$NON-NLS-1$
this.loginDialog.addWindowListener(new WindowAdapter() {
#Override
public void windowOpened(WindowEvent e) {
LoginDialog.this.loginDialog.requestFocus();
LoginDialog.this.loginDialog.requestFocusInWindow();
LoginDialog.this.txt_PASSWORD.addNotify();
LoginDialog.this.txt_PASSWORD.requestFocusInWindow();
LoginDialog.this.txt_PASSWORD.requestFocus();
}
#Override
public void windowClosing(WindowEvent e) {
close();
}
});
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
this.loginDialog.getRootPane().getInputMap().put(ks, GenePanelConstants.CLOSE_ACTION);
this.loginDialog.getRootPane().getActionMap().put( GenePanelConstants.CLOSE_ACTION, new AbstractAction() {
private static final long serialVersionUID = 2871751669355251894L;
#Override
public void actionPerformed(ActionEvent ae) {
close();
}
});
this.txt_PASSWORD.requestFocusInWindow();
this.txt_PASSWORD.requestFocus();
this.loginDialog.setAlwaysOnTop(true);
this.loginDialog.setVisible(true);

I got the some idea of it. As the focus management is managed by the system. You can get the focus on your dialog if and only if, it is the only one editable active window present in system.
For example, Keep the eclipse open which has cursor blinking on its editable window then start your application, text-box present in your application will not get focus( Even after you launch the application, the cursor will be blinking on editable window of eclipse). In same scenario if there is no blinking cursor on editable window of eclipse, your application text-box will get focused.

Related

Forcing a Vaadin Tabsheet to use the CloseHandler

I have a Vaadin Tabsheet. All tabs are closable. I have defined a custom CloseHandler. When a Tab is closed via the small x button, the the CloseHadler executes; however, if I close the tab programmatically
TabSheet parent = (TabSheet) this.getParent();
parent.removeTab(parent.getTab(this));
The close handler does not execute. Is there a way to force the CloseHandler to execute before the Tab is removed.
Thanks,
Oliver
A solution would be to extend the TabSheet class and override removeTab() to force it to execute the closeHandler. As the TabSheet.closeHandler is private you'll need to override this field and its setter too. Vaadin could make things simpler (changing the closeHandler to protected or providing a getter) but I don't see it as a "dirty" solution.
public class MyTabSheet extends TabSheet {
private static final long serialVersionUID = 1L;
private CloseHandler closeHandler;
#Override
public void removeTab(Tab tab) {
if (closeHandler != null) {
closeHandler.onTabClose(this, tab.getComponent());
}
super.removeTab(tab);
}
#Override
public void setCloseHandler(CloseHandler handler) {
closeHandler = handler;
// needed for TabSheet.TabsheetServerRpcImpl
super.setCloseHandler(handler);
}
}
If you want you could create a feature request at Vaadin (vaadin.com/bug), maybe the closeHandler should be called by default. There's already the #10555 but it's 3 years old...

Handling Touch EventListener in presence of navigationClick()

In application, Whenever i move bewteen tabs a full menu, copy, switch application pop up open.
To prevent this i override navigationClick method.
Now pop is not shown. In my second tab i have implemented drop down list. Because i have override navigationClick method when i click on drop down list it is not showing me list of items.
Any idea will be apperciated.
Update:
Here is navigationClick implementation:
public boolean navigationClick(int status, int time) {
return true;
}
Make sure while selecting a tab, no errors occur which probably could be the reason for the menu options to pop up. if this is fixed i guess the subsequent problem will be dissolved!
Out of my experience i have observed the menu pops up in blackberry when a NullPointerException event occurs.
Just check the logs or debug to make sure no exception occurs when you navigate between tabs
If you want to click the labelfield then:
LabelField labelField=new LabelField("Click")
{
protected boolean navigationClick(int status, int time)
{
doLabelFieldClicked();
return true;
}
}
and if Menu option is highlighted then override this:
public boolean onMenu(int instance)
{
return true; //It doesn't show the Menu option.
}
If I am thinking wrong let me know.
I solved this problem by implementing navigationClick() while creating lablelField
tab5 = new LabelField("News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
{
public boolean navigationClick(int status, int time)
{
return true;
}
};

Add field manager to application Main screen in BlackBerry

I am working with a BlackBerry application for OS 5.0 and later. The application has one screen which displays at the top of screen a Next and a Previous button. and list field also display in this screen at bottom of these both button
When i click on NEXT Button and Previous Button my List will be updated display data..
When i click on NEXT/PREVIOUS Button i have to display small VerticalfieldManager at the center of the screen with Label "Please wait ..." so after design this screen how can we add more field manager in over the another manager ?
Is there any way to display that Field at the application MainScreen like iPhone AppDelegate screen?
btnState.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{ vfm_Middle.add(lblPleasewait);
popup = new PopupScreen(manager);
Thread thread = new Thread()
{
public void run()
{
try
{
Updatelistfield();
stop();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
super.run();
}
public synchronized void stop()
{
// TODO Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// TODO Auto-generated method stub
//popup.delete(vfm_Main);
//popup.deleteAll();
//vfm_Main.delete(lblPleasewait);
//lblPleasewait.setText(null);
}
});
}
};
thread.start();
}
});
The proper way of doing that is with a blocking dialog. In BB API this can be done as follows:
VerticalFieldManager manager = new VerticalFieldManager();
manager.add(new LabelField("Please Wait..."));
Screen popup = new PopupScreen(manager);
//Show the pop-up the same way you push a regular screen
This has the advantage of blocking the GUI: if the user pushes the menu or esc key it doesn't have any effect.
If you want to do it in your screen without dialogs, then you can add an empty VerticalFieldManager which you can fill with a label when the message has to be shown. This way, instead of updating the entire screen, only the Manager is refreshed. But then you should write the logic to not letting the user push any button or menu key (or ignoring key press).

BlackBerry java detecting screen foreground event

In my BlackBerry application, I have a home screen. The user can then navigate to a settings screen. When the user goes back to the home screen, is there no method that is called on the home screen indicating that the screen has come to the foreground?
I have tried onFocus() with no avail.
Thanks!
Unfortunately, hooking on the onExposed is not enough. I found that in Blackberry dialogs are also screens and even context menus are screens too. They are pushed on top of your screen so you receive onExposed callback when they are dismissed.
Though it's OK in many cases, in other cases it poses a problem - e.g. if I must refresh the screen's content only when the user returns to it, but not after menus/dialogs, then how do I do that? My case is, unfortunately, one of those.
I found no documented way of detecting "covered"/"uncovered" events. Here is my approach. onCovered/onUncovered callbacks are called when the current screen is covered/uncovered by another screen of the app, but not by dialogs/menus/virtual keyboard:
public class MyAppScreen extends MainScreen {
private boolean isCovered;
protected void onExposed() {
Log.d("onExposed");
super.onExposed();
if (isCovered) {
onUncovered();
isCovered = false;
}
}
protected void onObscured() {
Log.d("onObscured");
super.onObscured();
final Screen above = getScreenAbove();
if (above != null) {
if (isMyAppScreen(above)) {
isCovered = true;
onCovered();
}
}
}
private boolean isMyAppScreen(final Screen above) {
return (above instanceof MyAppScreen);
}
protected void onUncovered() {
Log.d("onUncovered");
}
protected void onCovered() {
Log.d("onCovered");
}
protected void onUiEngineAttached(final boolean attached) {
if (attached) {
Log.d("UI Engine ATTACHED");
} else {
Log.d("UI Engine DETACHED");
}
super.onUiEngineAttached(attached);
}
protected void onFocusNotify(final boolean focus) {
if(focus){
Log.d("focus GAINED");
} else {
Log.d("focus LOST");
}
super.onFocusNotify(focus);
}
}
And a test. Try various combinations and see what events you receive in the log.
public class TestLifecycle extends MyAppScreen implements FieldChangeListener {
private final ABNTextEdit txt1;
private final ButtonField btn1;
private final ButtonField btn2;
public TestLifecycle() {
final Manager manager = getMainManager();
txt1 = new ABNTextEdit();
manager.add(txt1);
btn1 = new ButtonField("Dialog", ButtonField.CONSUME_CLICK);
btn1.setChangeListener(this);
manager.add(btn1);
btn2 = new ButtonField("Screen", ButtonField.CONSUME_CLICK);
btn2.setChangeListener(this);
manager.add(btn2);
}
public void fieldChanged(final Field field, final int context) {
if (field == btn1) {
Dialog.alert("Example alert");
} else if (field == btn2) {
UiApplication.getUiApplication().pushScreen(new TestLifecycle());
}
}
}
Update:
This method has a limitation: if a new screen is pushed when a dialog or the soft keyboard has focus your current screen will not receive onCovered/onUncovered notification.
Example A: if you have an input field of fixed size and you push a new screen when the user completes it, your current screen will not receive the notification if the user types very quickly. This happens because in the moment between you call push(newScreen) and it is actually pushed the user clicks on a letter on soft KB and it grabs the focus. So only onObscured is called, but not onCovered.
Solution: explicitly hide the soft keyboard before the push(newScreen).
Example B: if you have a customized dialog which pushes new screen and then dismisses itself, your current screen will not receive the notification. This happens because your customized dialog is not recognized as a screen, so only onObscured is called, but not onCovered.
Solution: dismiss the dialog in the first place returning a result value, and let your screen push the new screen based on that value. -OR- override isMyAppScreen() to return true also for your customized dialog.
You should be able to use protected void onExposed() to detect when it is displayed again.

Blackberry screen navigation

I want to know how to go from one screen to another by clicking a button that I have added to a MainScreen. I mean just like we do in the Android onClick event for a button - start another startActivity.
In the event handler for the button click, just "push" the screen that you want to appear next, and it will be pushed to the top of the screen stack. For example:
UiApplication.getUiApplication().pushScreen(nextScreen);
This will be better, using FieldChangeListener
button.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
UiApplication.getUiApplication().pushScreen(new NextScreen());
}
});
This is the alternative way than using,
UiApplication.getUiApplication.involeLater()
{};

Resources