tags:

views:

589

answers:

2

I am writing an Eclipse plugin, and in response to some action I am interesting in starting a series of operations (within a separate job). One of these operations is to request the user to provide a filename, which I'm trying to do with the JFace JDialog.

However, I'm not clear how to do this in a modeless way; for example, where do I obtain a display and shell? How do I ensure the UI continues to work while the developer can edit stuff in the dialog?

+3  A: 

May be you could see how Eclipse itself does it:

FindAndReplaceDialog.java

 /**
  * Creates a new dialog with the given shell as parent.
  * @param parentShell the parent shell
  */
 public FindReplaceDialog(Shell parentShell) {
     super(parentShell);

     fParentShell= null;

     [...]

     readConfiguration();

     setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE | SWT.RESIZE);
     setBlockOnOpen(false);
 }

 /**
  * Returns this dialog's parent shell.
  * @return the dialog's parent shell
  */
 public Shell getParentShell() {
     return super.getParentShell();
 }

/**
 * Sets the parent shell of this dialog to be the given shell.
 *
 * @param shell the new parent shell
 */
public void setParentShell(Shell shell) {
    if (shell != fParentShell) {

        if (fParentShell != null)
            fParentShell.removeShellListener(fActivationListener);

        fParentShell= shell;
        fParentShell.addShellListener(fActivationListener);
    }

    fActiveShell= shell;
}

It does manage its parent shell depending on the focus of the Dialog.

 /**
  * Updates the find replace dialog on activation changes.
  */
 class ActivationListener extends ShellAdapter {
     /*
      * @see ShellListener#shellActivated(ShellEvent)
      */
     public void shellActivated(ShellEvent e) {
         fActiveShell= (Shell)e.widget;
         updateButtonState();

         if (fGiveFocusToFindField && getShell() == fActiveShell && 
               okToUse(fFindField))
             fFindField.setFocus();

     }

     /*
      * @see ShellListener#shellDeactivated(ShellEvent)
      */
     public void shellDeactivated(ShellEvent e) {
         fGiveFocusToFindField= false;

         storeSettings();

         [...]

         fActiveShell= null;
         updateButtonState();
     }
 }

A ShellAdapter is provides default implementations for the methods described by the ShellListener interface, which provides methods that deal with changes in state of Shell.

VonC
A: 

The importent thing is that the style value should include SWT.MODELESS.

The style is one of the most important things in SWT you should look at, because you can control and initialize a lot only because of the styel value.

Markus Lausberg