jkteater
jkteater

Reputation: 1391

org.eclipse.swt.SWTExecption: Widget is Disposed

My user selects data from a main application workspace. The data is stored in a Writeable list. The user then proceeds to open a dialog to display the selected data in a table. When my users opens the dialog the first time. Everything is fine and things work as planned. But when they close the dialog and then and reopens it. I am getting the following error.

enter image description here

They are allowed to close the dialog and select more data. Then open the dialog again to see the old and new data.

Order of steps the code is using up to the error.

  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);  
    Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    final GridLayout gridLayout = new GridLayout();

    gridLayout.marginWidth = 15;
    gridLayout.marginHeight = 10;
    composite.setLayout(gridLayout);

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    composite.setLayoutData(gridData);
    createTopButtons(composite);
    createTableViewer(composite);
    createRemoveButtons(composite);
    updateTableViewer();
    return composite;
 }

In the error, we can see it is coming from the updateTableViewer

public void updateTableViewer() {
  setRemoveButtonVisibility();
  setRemoveAllButtonVisibility();
  setPlotButtonVisibility();
  setPDFButtonVisibility();
}

In the error, we see that it is coming from the setRemoveButtonVisibility();

public void setRemoveButtonVisibility() {
  if (AplotDataModel.getInstance().getSize() > 0) {
     removeButton.setVisible(true);
  }
  else {
     removeButton.setVisible(false);
  }
}

This is the line it is pointing to:

removeButton.setVisible(true);

The if condition is checking the writable list that stores the data users select. If the list is empty the buttons don't show, if there is data, the buttons do show.

Here is the code for the closing of the dialog button:

protected void createButtonsForButtonBar(Composite parent) {
  Button okButton = createButton(parent, OK, "Close Aplot", true);
  okButton.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent e) {
        viewer = null;
        close();
     }
  });
}

Any thoughts?

Upvotes: 1

Views: 1027

Answers (2)

user2187507
user2187507

Reputation: 21

Make sure that you are not trying to read any information after you close out the shell. Example:

System.out.println(combo.getText())
shlUpload.close();
ImportGroup window = new ImportGroup();
window.open(combo.getText());

This will not work once you close shlUpload it no longer sees the object "combo". Austin

Upvotes: 0

Waqas Ilyas
Waqas Ilyas

Reputation: 3241

Instead of using close(), use getShell().setVisible(false) to hide the dialog. Because you are re-using the same dialog you should not close it. And if you close the dialog, which in turn disposes it off, you should create a new dialog every time you need to open it.

Upvotes: 5

Related Questions