[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Invoking SWT application from Eclipse

Hi Mark,
The Eclipse version I am using is Eclipse SDK 3.2.0.
My SWT application is an Eclipse plugin.

This is the code of plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>

  <extension
        point="org.eclipse.ui.actionSets">
     <actionSet
           label="%actionSet.label.0"
           visible="true"
           id="org.eclipseguide.trial.actionSet">
        <menu
              label="%menu.label.0"
              id="sampleMenu">
           <separator
                 name="buildGroup">
           </separator>
        </menu>
         <action
              label="%action.label.0"
              icon="icons/sample.gif"
              class="org.eclipseguide.trial.actions.BuildAction"
              tooltip="%action.tooltip.0"
              menubarPath="sampleMenu/buildGroup"
              toolbarPath="buildGroup"
              id="org.eclipseguide.trial.actions.BuildAction">
        </action>
        <action
              label="%action.label.1"
              icon="icons/sample2.gif"
              class="org.eclipseguide.trial.actions.HelloAction"
              tooltip="%action.tooltip.1"
              menubarPath="sampleMenu/helloGroup"
              toolbarPath="helloGroup"
              id="org.eclipseguide.trial.actions.HelloAction">
        </action>
        <action
              label="%action.label.2"
              icon="icons/sample1.gif"
              class="org.eclipseguide.trial.actions.ShowMessageBoxAction"
              tooltip="%action.tooltip.2"
              menubarPath="sampleMenu/byeGroup"
              toolbarPath="byeGroup"
              id="org.eclipseguide.trial.actions.ShowMessageBoxAction">
        </action>
     </actionSet>
  </extension>
</plugin>



In this first two applications 1.BuildAction 2. HelloAction are working fine. These are simple java applications.

______________________________________________________________________________

This is the code for ShowMessageBoxAction.java:

package org.eclipseguide.trial.actions;

import org.eclipseguide.trial.actions.ShowMessageBox;

/**
* This class demonstrates the MessageBox class
*/
public class ShowMessageBoxAction {

public static void main(String[] args) {
System.out.print("BP 1");
/**
* Application entry point
* * @param args the command line arguments
*/
new ShowMessageBox().run();
}
}


______________________________________________________________________________

This is the code for ShowMessageBox.java:

package org.eclipseguide.trial.actions;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
* This class demonstrates the MessageBox class
*/
public class ShowMessageBox {
 // Strings to show in the Icon dropdown
 public static final String[] ICONS = { "SWT.ICON_ERROR",
     "SWT.ICON_INFORMATION", "SWT.ICON_QUESTION", "SWT.ICON_WARNING",
     "SWT.ICON_WORKING"};

 // Strings to show in the Buttons dropdown
 public static final String[] BUTTONS = { "SWT.OK", "SWT.OK | SWT.CANCEL",
     "SWT.YES | SWT.NO", "SWT.YES | SWT.NO | SWT.CANCEL",
     "SWT.RETRY | SWT.CANCEL", "SWT.ABORT | SWT.RETRY | SWT.IGNORE"};

 /**
  * Runs the application
  */
 public void run() {
	  System.out.print("BP 2");
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setText("Show Message Box");
   createContents(shell);
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }

/**
* Creates the main window's contents
* * @param shell the parent shell
*/
public void createContents(final Shell shell) {
System.out.print("BP 3");
shell.setLayout(new GridLayout(2, false));


   // Create the dropdown to allow icon selection
   new Label(shell, SWT.NONE).setText("Icon:");
   final Combo icons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
   for (int i = 0, n = ICONS.length; i < n; i++)
     icons.add(ICONS[i]);
   icons.select(0);

   // Create the dropdown to allow button selection
   new Label(shell, SWT.NONE).setText("Buttons:");
   final Combo buttons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
   for (int i = 0, n = BUTTONS.length; i < n; i++)
     buttons.add(BUTTONS[i]);
   buttons.select(0);

   // Create the entry field for the message
   new Label(shell, SWT.NONE).setText("Message:");
   final Text message = new Text(shell, SWT.BORDER);
   message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

   // Create the label to show the return from the open call
   new Label(shell, SWT.NONE).setText("Return:");
   final Label returnVal = new Label(shell, SWT.NONE);
   returnVal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

   // Create the button and event handler
   // to display the message box
   Button button = new Button(shell, SWT.PUSH);
   button.setText("Show Message");
   button.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent event) {
       // Clear any previously returned value
       returnVal.setText("");

       // This will hold the style to pass to the MessageBox constructor
       int style = 0;

       // Determine which icon was selected and
       // add it to the style
       switch (icons.getSelectionIndex()) {
       case 0:
         style |= SWT.ICON_ERROR;
         break;
       case 1:
         style |= SWT.ICON_INFORMATION;
         break;
       case 2:
         style |= SWT.ICON_QUESTION;
         break;
       case 3:
         style |= SWT.ICON_WARNING;
         break;
       case 4:
         style |= SWT.ICON_WORKING;
         break;
       }

       // Determine which set of buttons was selected
       // and add it to the style
       switch (buttons.getSelectionIndex()) {
       case 0:
         style |= SWT.OK;
         break;
       case 1:
         style |= SWT.OK | SWT.CANCEL;
         break;
       case 2:
         style |= SWT.YES | SWT.NO;
         break;
       case 3:
         style |= SWT.YES | SWT.NO | SWT.CANCEL;
         break;
       case 4:
         style |= SWT.RETRY | SWT.CANCEL;
         break;
       case 5:
         style |= SWT.ABORT | SWT.RETRY | SWT.IGNORE;
         break;
       }

       // Display the message box
       MessageBox mb = new MessageBox(shell, style);
       mb.setText("Message from SWT");
       mb.setMessage(message.getText());
       int val = mb.open();
       String valString = "";
       switch (val) // val contains the constant of the selected button
       {
       case SWT.OK:
         valString = "SWT.OK";
         break;
       case SWT.CANCEL:
         valString = "SWT.CANCEL";
         break;
       case SWT.YES:
         valString = "SWT.YES";
         break;
       case SWT.NO:
         valString = "SWT.NO";
         break;
       case SWT.RETRY:
         valString = "SWT.RETRY";
         break;
       case SWT.ABORT:
         valString = "SWT.ABORT";
         break;
       case SWT.IGNORE:
         valString = "SWT.IGNORE";
         break;
       }
       returnVal.setText(valString);
     }
   });
 }

}

______________________________________________________________________________

When i run ShowMessageBoxAction.java as a "SWT Application" it is working fine.