Oak
Oak

Reputation: 26868

What is the proper way to display a complex dialog in an Eclipse plugin?

I want a complex dialog to appear when the user clicks some button my plugin adds, but I could not find any existing dialog type which supports adding arbitrary controls.

Instead, I was thinking about creating a wizard with just one page - that would probably look good enough but it doesn't feel right. Is there a better way to create a dialog with complex controls?

Upvotes: 3

Views: 367

Answers (1)

rancidfishbreath
rancidfishbreath

Reputation: 3994

You want to subclass org.eclipse.jface.dialogs.TrayDialog. This will give you a dialog with a button bar and the slide out tray that will appear when you click the help button. According to the Javadoc of TrayDialog:

It is recommended to subclass this class instead of Dialog in all cases except where the dialog should never show a tray

You put your complex code in the createDialogArea(Composite parent) method. If you want everything to look right make sure you use the composite returned from calling super instead of using the parent. This will make sure the margins are set to the default. For instance:

protected Control createDialogArea(Composite parent) {
  Composite parentWithMargins = (Composite) super.createDialogArea(parent);

  /*
   * Add your code here parenting off of parentWithMargins
   */

  return parentWithMargins;
}

Upvotes: 4

Related Questions