Hi all, I have a login window that has simple user
id and password field with corresponding text boxes implementesd in pure swt.Now
i want to put it as a plugin(toolbar button) so that on pressing it i will get
the login window.I just want to explore these things ,as iam new to eclipse
plugin progrraming
My code has 3
classes
1.Login class,that has get,set methods for fields
userid,password,button pressed
2.Logindialog class that will display a
window.
3.Main class.
1. public class Login {
String
id;
String
password;
boolean
buttonResponse;
public
Login(){}
public
boolean
getButtonResponse() {
return
buttonResponse;}
public
void
setButtonResponse(boolean
b){
buttonResponse = b;}
public
String getID()
{return
id;}
public
void setID(String
id){
this.id =
id;}
public
String getPassword(){
return
password;}
public
void setPassword(String
password){
this.password = password;}}
2.
import org.eclipse.swt.SWT;
import
org.eclipse.swt.widgets.*;i
import
org.eclipse.swt.graphics.*;
public class Logindialog extends Dialog {
private Text
idText;
private Text
passwordText;
private Button
btnOK;
private Button
btnCancel;
private Login
login;
Logindialog(Shell arg0) {super(arg0);}
public Login
open(){
login = new Login();
final Shell
shell = new
Shell(getParent(),SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setText(getText());shell.setSize(400,200);Label label1 =
new
Label(shell,SWT.NONE);
label1.setSize(400,50);label1.setLocation(0,0);
label1.setAlignment(SWT.CENTER);label1.setText("\nWelcome to my program. \n please login");
label1.setBackground(new Color(shell.getDisplay(),255,255,255));
Label label2 = new Label(shell,SWT.NONE);label2.setSize(70,10);
label2.setLocation(20,63);label2.setAlignment(SWT.RIGHT);
label2.setText("ID :");idText = new Text(shell,SWT.BORDER);
idText.setTextLimit(30);idText.setBounds(100,60,200,20);
Label label3 = new Label(shell,SWT.NONE);label3.setSize(70,10);
label3.setLocation(20,93);label3.setAlignment(SWT.RIGHT);
label3.setText("Password :");passwordText = new Text(shell,SWT.BORDER);
passwordText.setTextLimit(30);passwordText.setBounds(100,90,200,20);
passwordText.setEchoChar('*');btnOK = new Button(shell,SWT.PUSH);
btnOK.setText("Login");btnOK.setLocation(110,130);
btnOK.setSize(80,20);btnCancel = new Button(shell,SWT.PUSH);
btnCancel.setText("Cancel");btnCancel.setLocation(210,130);
btnCancel.setSize(80,20);
Listener listener = new Listener(){
public
void
handleEvent(Event event){
login.setButtonResponse(event.widget==btnOK);
login.setID(idText.getText());
login.setPassword(passwordText.getText());shell.close();}};
btnOK.addListener(SWT.Selection,listener);
btnCancel.addListener(SWT.Selection,listener);
Display display = getParent().getDisplay();
Rectangle rect = display.getBounds();
int mx =
rect.width/2;
int my =
rect.height/2;
shell.setLocation(mx-200,my-100);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()) display.sleep();
}
return
login;
}
}
3.Main class
import org.eclipse.swt.SWT;import
org.eclipse.swt.widgets.*;import
org.eclipse.swt.graphics.*;
public class Main {
public
static
void main(String
args[]){
Display display= new Display();
final Shell sh =
new
Shell(display);
Logindialog dialog = new Logindialog(sh);Login login = dialog.open();
MessageBox msg = new MessageBox(sh,SWT.OK);
if(login.getButtonResponse()) {
msg.setMessage("Your id is:"+login.getID()+"\nYour Password is
:"+login.getPassword());
msg.open();
while(!sh.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}}
display.dispose(); }}
Regards, Steven
Sequeira
|