When I create my TableViewer in my dialog class. I am adding a ListChangeListener. This listener listens to a ObservableList in my Data Model Class.
This is my createTableViewer method in the dialog class.
private void createTableViewer(Composite parent) {
viewer = new AplotDataTableViewer(parent, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
IObservableList iob = AplotDataModel.getInstance().getObservableList();
viewer.setInput(iob);
iob.addListChangeListener(new IListChangeListener() {
@Override
public void handleListChange(ListChangeEvent event) {
updateTableViewer();
}
});
}
So what is happening. When a user Closes the dialog using the Window Close Button (Red X). That is disposing all the widgets and closing the window. When the Dialog is opened back. The ListChangeListener is looking to the updateTableViewer, but the widgets in the update is already disposed.
Right now there are 2 ways to close the dialog. 1. Red X - maybe doing a Window.close() 2. My close button on the form.
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, "Close Aplot",
true);
}
@Override
protected void okPressed() {
getShell().setVisible(false);
}
Which is using okPressed and hiding the shell.
What I would like is to have both methods of closing the dialog the same.
Is it possible to add a listener to the Shell and in the handleEvent method. Have a call to the okPressed method?
getShell().addListener(SWT.Close, new Listener() { @Override public void handleEvent(Event e) { okPressed(); } });
Instead of SWT.Close should I be using Window.Close?
Should I be using Close_ID instead of ok_ID
@Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.CLOSE_ID, "Close Aplot", true); }
@Override protected void closePressed() { getShell().setVisible(false); }
Is there a way to get my active ListChangeListener and remove it?
protected void closePressed() { AplotDataModel.getInstance().getObservableList().removeListChangeListener(this); }
I am not sure how to get active listeners?
I want to Close the Dialog either using the Windows Close Button (Red X) or the Close Button on the form. If possible I wish both actions would use the same code to remove the active Listener from my IObservableList and close the dialog.