Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to deploy swt programs as a plugin(hlp needed)
How to deploy swt programs as a plugin(hlp needed) [message #436967] Thu, 27 May 2004 05:15
Eclipse UserFriend
Originally posted by: ssequeira.icope.com

Hi all,
I have 3 java classes that uses pure swt programmng using widgets
etc.Basically Iam displaying a window with userid,password.Now with these
3 classes i want to deploy it as a plugin.By creating a button in toolbar
and on pressing the login window shld b dispalyed.I have created a plugin
project called org.eclpse.login.
Details are:
1.Login class: Get and set methods for userid,passwrd,buttonresponse.
2.Logindialog class: that will display login window using swt commands
such
as label,shell,display etc.
3.A main class where it invokes all the related classes.
There is also a generated plugin.xml.I tried adding actionset to the
xml,by seeing the helloworld plugin's xml(using code generation wizard)
and also the toolbar path.But it didnt work.
Can anyone help me in doing this,with code.

The code for window is:
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(); }}
Previous Topic:perspective lifttime
Next Topic:Word wrap in Text?
Goto Forum:
  


Current Time: Fri Apr 26 04:21:45 GMT 2024

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

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

Back to the top