Home » Eclipse Projects » Eclipse 4 » Double invocation of a Login Dialog using LifeCyleHandler
Double invocation of a Login Dialog using LifeCyleHandler [message #741690] |
Wed, 19 October 2011 20:06 |
St Clair Clarke Messages: 118 Registered: March 2010 |
Senior Member |
|
|
Hello,
I am using e4 4.1.1.
I have a LoginTitleAreaDialog
package com.epimss.admin.ui.login;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import com.epimss.admin.data.login.Login;
public class LoginTitleAreaDialog extends TitleAreaDialog
{
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
private Composite formCmpst;
private Login login = new Login();
private Text passwordTxt;
private Text usernameTxt;
private Button okBtn;
private Button cancelBtn;
/**
* Create the dialog.
* @param parentShell
*/
public LoginTitleAreaDialog( Shell parentShell )
{
super( parentShell );
setShellStyle(SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL);
}
/**
* Create contents of the button bar.
* @param parent
*/
@Override
protected void createButtonsForButtonBar( Composite parent )
{
okBtn = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
cancelBtn = createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea( Composite parent )
{
setMessage( "Please enter your user name and password." );
setTitleImage(ResourceManager.getPluginImage("com.epimss.shared", "icons/aha-soft/network_large/gif/48x48/User login.gif"));
setTitle("ePIMSS Login");
Composite area = ( Composite ) super.createDialogArea( parent );
Composite container = new Composite( area, SWT.NONE );
container.setLayout(new FillLayout(SWT.HORIZONTAL));
container.setLayoutData( new GridData( GridData.FILL_BOTH ) );
{
formCmpst = formToolkit.createComposite(container, SWT.NONE);
formCmpst.setData("name", "formCmpst");
formToolkit.paintBordersFor(formCmpst);
formCmpst.setLayout(new GridLayout(2, false));
Label usernameLbl = formToolkit.createLabel(formCmpst, "User Name", SWT.NONE);
usernameLbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
usernameLbl.setData("name", "usernameLbl");
passwordTxt = formToolkit.createText(formCmpst, "New Text", SWT.NONE);
passwordTxt.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
login.setPassword( passwordTxt.getText() );
}
});
passwordTxt.setText("");
passwordTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
passwordTxt.setData("name", "passwordTxt");
Label passwordLbl = formToolkit.createLabel(formCmpst, "Password", SWT.NONE);
passwordLbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
passwordLbl.setData("name", "passwordLbl");
usernameTxt = formToolkit.createText(formCmpst, "New Text", SWT.NONE);
usernameTxt.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
{
login.setUsername( usernameTxt.getText() );
}
});
usernameTxt.setText("");
usernameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
usernameTxt.setData("name", "usernameTxt");
}
return area;
}
/**
* Return the initial size of the dialog.
*/
@Override
protected Point getInitialSize()
{
return new Point( 330, 309 );
}
public Login getLogin()
{
return login;
}
public Text getPasswordTxt()
{
return passwordTxt;
}
public Text getUsernameTxt() {
return usernameTxt;
}
public boolean isOKBtnEnabled()
{
if( !login.getUsername().isEmpty() && !login.getPassword().isEmpty() )
{
okBtn.setEnabled( true );
return true;
}
else
{
okBtn.setEnabled( false );
return false;
}
}
}
I use LoginLifeCycleHandler to open the LoginTitleAreaDialog
package com.epimss.admin.handlers.lifecycle;
import javax.inject.Inject;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.jface.window.Window;
import com.epimss.admin.data.login.Login;
import com.epimss.admin.ui.login.LoginTitleAreaDialog;
import com.gurock.smartinspect.SiAuto;
public class LoginLifeCycleHandler
{
private Login login = new Login();
@Inject
@PostContextCreate
public void loginLifeCycleHandler()
{
// SiAuto.si.setEnabled( true );
try
{
// parentShell.setText( "Electronic Patient management Systems" );
LoginTitleAreaDialog dialog = new LoginTitleAreaDialog( null );
int i = dialog.open();
if( i == Window.CANCEL )
{
System.exit( 0 );
}
if( i == Window.OK )
{
// System.out.println( dialog.getPasswordTxt().getText());
//
// System.out.println(login);
// check licence
// authentication/authorization
// configure application base on user - access to what perspective,
// actions etc
// open database
// context.set( "login", dialog.getLogin() );
// context.set("lfsDS", loginDao.getInitialDataSource());
// context.set("login", loginDialog.getLogin());
// System.out.println( dialog.getLogin());
// context.set( "login", dialog.getLogin() );
// System.out.println( context.get( "login" ));
System.out.println( dialog.getLogin() );
}
}
catch(Exception e)
{
// SiAuto.main.logException( "com.epimss.admin.handlers.lifecycle.LoginLifeCycleHandler.loginLifeCycleHandler(parentShell)", e );
}
finally
{
}
}
}
My model is Login.java
package com.epimss.admin.data.login;
public class Login
{
String username = ""
String password = ""
}
Whenever I launch my plugin the dialog is seen alright.
However, two problems develops afterwards:
1. With the above code, after entering inputs for both the username and passwords and pressing OK, the username and password are printed to the console correctly, but the dialog reappears a SECOND TIME - I EXPECT IT TO DISAPPEAR!
2. If I use JFace Databinding, binding occurs OK, but error occurs telling me that a Realm is not available.
I need some help corrrecting these two issues plase.
I use this http://marcteufel.wordpress.com/2011/05/05/231/ link to develop my source.
Thanks
|
|
| | |
Goto Forum:
Current Time: Fri Apr 19 15:36:56 GMT 2024
Powered by FUDForum. Page generated in 0.01751 seconds
|