Andrea Sindico
Andrea Sindico

Reputation: 7440

SWT not enabled shell

I am trying to open a DateTime shell when clicking on a button inside an Eclipse plugin which extends the platform's preferences.

This is the code of the Button SelectionAdapter

    @Override
    public void widgetSelected(SelectionEvent e) {
           super.widgetSelected(e);
          Display display = Display.getCurrent();
          Shell ns = new Shell(display);
          ns.setLayout (new RowLayout ());
          final DateTime calendar = new DateTime (ns, SWT.CALENDAR);
          ns.pack();
          ns.open();
          ns.forceActive();
          ns.setEnabled(true);
          while (!ns.isDisposed()) {
              if (!display.readAndDispatch())
                display.sleep();
           }
    }

As you can see in the following image the shell is depicted but seems to be not enabled. It is indeed not possible to select any date nor to close/resize it. As you can see the three bottons (red, yellow and green) appear gray. What am I doing wrong?

enter image description here

UPDATE

I tried to get the shell like this:

  Display display = new Display();
  IWorkbench workbench    = PlatformUI.getWorkbench();
  IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
  Shell shell             = window.getShell();

But now I get this enter image description here

which is actually quite far from my intentions. My aim is to show a new window with the DateTime widget

UPDATE

I followed the Gilbert advice and defined my own JFace Dialog. As described by Lars Vogel in http://www.vogella.com/articles/EclipseDialogs/article.html I created it as an extension of the TitleAreaDialog. It works now but there is still something I need to improve.

enter image description here

I would like to hide the big header for the title and to hide/remove the help button. Is there any way to do that? am I extending the wrong class?

Upvotes: 0

Views: 172

Answers (1)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

Since you say you're building an Eclipse plug-in, try the following to get Shell.

IWorkbench workbench    = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
Shell shell             = window.getShell();

Creating your own Shell is not a good idea, unless you're building an SWT application outside of Eclipse.

Creating your own Display is not a good idea, unless you're building an SWT applicaiton outside of Eclipse.

What you're looking for, I think, is a Dialog for the calendar. You'll have to extend the Eclipse Dialog class to make your own dialog.

Upvotes: 2

Related Questions