Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » JFace Dialog...carriage return in Text widget...Button event sent from Display.readAndDispatch() on
JFace Dialog...carriage return in Text widget...Button event sent from Display.readAndDispatch() on [message #334687] Tue, 24 February 2009 19:37
Eclipse UserFriend
Originally posted by: james.towers.siemens.com

This is a multi-part message in MIME format.
--------------060607080607080408050907
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

This is an AIX only issue...windows works fine...we have no reports of
issues on Linux, HP, or Solaris.

We have a RCP application and our Application class displays a login
dialog to gather credentials. This login dialog extends JFace Dialog.
We have several Text widgets and three Button widgets. We create all
these controls in our createDialogArea() method. The password Text
widget has a KeyListener that attempts a login. If we have an invalid
password in the password widget and hit enter...the password KeyListener
attempts a login...the login fails and we place the focus into the useid
text. We can enter another password into the password text and hit
enter. This time the cancel button gets the event instead of the
password text...and we do a buttonPressed().

I searched for this and similar issues on the message board and bugzilla
but didn't find any. Are there any thoughts on the cause or a
workaround? I have attached a test dialog class that shows the problem.

Thanks and regards,
Jim

--------------060607080607080408050907
Content-Type: text/plain;
name="MyLoginDialog.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MyLoginDialog.java"

package com.towers.myrcp;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class MyLoginDialog extends Dialog {
private Text userId;
private Text password;
private Button loginButton;
private Button cancelButton;
KeyListener keyL;

@Override
protected void createButtonsForButtonBar(Composite parent) {
// TODO Auto-generated method stub
}

@Override
protected Control createDialogArea(Composite parent) {
// TODO Auto-generated method stub
Composite dcomp = new Composite( parent, SWT.NONE );
FormLayout layout = new FormLayout();
dcomp.setLayout( layout );
Label l = new Label (dcomp, SWT.NONE);
l.setText("userId:");
FormData fd = new FormData();
fd.left = new FormAttachment( 0, 1000, 10 );
fd.top = new FormAttachment( 0, 1000, 10 );
l.setLayoutData( fd );
userId = new Text(dcomp, SWT.BORDER);
FormData fd2 = new FormData();
fd2.left = new FormAttachment( 0, 1000, 80 );
fd2.top = new FormAttachment( 0, 1000, 10 );
userId.setLayoutData( fd2 );
keyL = new IC_KeyListener();
userId.addKeyListener(keyL);
userId.setEnabled(true);
Label l2 = new Label (dcomp, SWT.NONE);
l2.setText("password:");
FormData fd3 = new FormData();
fd3.left = new FormAttachment( 0, 1000, 10 );
fd3.top = new FormAttachment( 0, 1000, 50 );
l2.setLayoutData(fd3);
password = new Text(dcomp, SWT.PASSWORD | SWT.BORDER);
FormData fd4 = new FormData();
fd4.left = new FormAttachment( 0, 1000, 80 );
fd4.top = new FormAttachment( 0, 1000, 50 );
password.setLayoutData(fd4);
password.addKeyListener(keyL);
password.setEnabled(true);
loginButton = new Button( dcomp, SWT.PUSH | SWT.CENTER );
FormData fd5 = new FormData();
fd5.left = new FormAttachment( 0, 1000, 10 );
fd5.top = new FormAttachment( 0, 1000, 100 );
loginButton.setLayoutData(fd5);
loginButton.setText( "loginButton" );
loginButton.setEnabled( false );
loginButton.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
doLogin();
}
} );
cancelButton = new Button( dcomp, SWT.PUSH | SWT.CENTER );
FormData fd6 = new FormData();
fd6.left = new FormAttachment( 0, 1000, 80 );
fd6.top = new FormAttachment( 0, 1000, 100 );
cancelButton.setLayoutData(fd6);
cancelButton.setText( "cancelButton" );
cancelButton.setEnabled( true );
cancelButton.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
buttonPressed( IDialogConstants.CANCEL_ID );
}
} );
return dcomp;
}

@Override
protected void configureShell(Shell newShell) {
// TODO Auto-generated method stub
super.configureShell(newShell);
newShell.setText("MyLoginDialog");
}

public int open()
{
int ret = super.open();

Display display = getShell().getDisplay();
while( getShell() != null && !getShell().isDisposed() )
{
try
{
if( !display.readAndDispatch() )
{
display.sleep();
}
}
catch( Throwable e )
{
e.printStackTrace();
}
}
display.update();

return ret;
}

public MyLoginDialog(Shell parentShell) {
super(parentShell);
setBlockOnOpen( false );
// TODO Auto-generated constructor stub
}

public MyLoginDialog() {
this (null);
// TODO Auto-generated constructor stub
}

private void doLogin()
{
userId.setEnabled(false);
loginButton.setEnabled(false);
password.setEnabled(false);
cancelButton.setEnabled(false);
if (password.getText().equalsIgnoreCase("jim"))
{
this.close();
return;
}
userId.setEnabled(true);
userId.selectAll();
userId.setFocus();
password.setEnabled(true);
loginButton.setEnabled(true);
cancelButton.setEnabled(true);
}
private class IC_KeyListener
extends KeyAdapter
{
@Override
public void keyReleased( KeyEvent e )
{
if (userId.getText().equalsIgnoreCase(""))
{
loginButton.setEnabled(false);
}
else
{
loginButton.setEnabled(true);
}
if( loginButton.isEnabled() && e.character == SWT.CR )
{
doLogin();
}
}
}

}

--------------060607080607080408050907--
Previous Topic:A cycle was detected when generating the classpath
Next Topic:How to present files to a user in a plug-in
Goto Forum:
  


Current Time: Thu Jul 25 21:02:09 GMT 2024

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

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

Back to the top