Vijay Kasina
Vijay Kasina

Reputation: 144

how to display a simple swt window with text fileld and a button when clicking on a menu item in eclipse plugins?

I know how to create a swt window with text box and other things . and i know how to create a plugin . but i could not create a plugin with a menu which generates event of generating window.

i tried this swt to generate window with textbox and button .

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
class demoMAIN {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    Display display = new Display();
    final Shell shell =new Shell(display);

    shell.setSize(1000,1000);

    shell.open();

    Label label =new Label(shell,SWT.BORDER);

    label.setText("Enter something and click on button");
    label.setLocation(10, 10);
    label.pack();

    final Text text = new Text(shell,SWT.NONE);
    text.setBounds(10, 30, 100, 30);


    Button button = new Button(shell,SWT.PUSH);
    button.setText("OK");
    button.setSize(50, 50);
    button.setLocation(10,75);


    button.addSelectionListener(new SelectionAdapter(){
        public void widgetSelected(SelectionEvent e) {
            System.out.println("your data is "+text.getText());
            shell.dispose();
            }
    });




    while(!shell.isDisposed()){
        if(!display.readAndDispatch())
        display.sleep();
        }
        display.dispose();

}

}

and it is working.

and pluggin project with file SampleHandler

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;

/**
  * Our sample handler extends AbstractHandler, an IHandler base class.
  * @see org.eclipse.core.commands.IHandler
  * @see org.eclipse.core.commands.AbstractHandler
*/
public class SampleHandler extends AbstractHandler {
/**
 * The constructor.
 */
public SampleHandler() {
}

/**
 * the command has been executed, so extract extract the needed information
 * from the application context.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    MessageDialog.openInformation(window.getShell(),"project","Hello, Eclipse world");




    return null;
}
}

please help me doing this .. thanks in advance ... And im referring all eclipse plugin development sites like

http://www.vogella.com/tutorials/Eclipse3RCP/article.html

Upvotes: 4

Views: 2360

Answers (1)

kasinavijay
kasinavijay

Reputation: 168

you can also done this using Eclipse Wizards ...

have a look at this site ..

http://www.vogella.com/tutorials/EclipseWizards/article.html#wizards

Upvotes: 1

Related Questions