Just because I’ve been running into this today. I thought it might be interesting to others as well. The following is a shortened version of a code I’ve been using in an RCP-Application.
public class CreateItemsHandler { @Execute public void execute(IObservableList companies, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) { DialogImpl i = new DialogImpl(shell,companies); i.open(); } class DialogImpl extends TitleAreaDialog { private final IObservableList companies; // .... public Composite createDialogArea(Composite parent) { // .... TreeViewer v; // .... v.setContentProvider( new ObservableListTreeContentProvider(new ObservableFactoryImpl(), new StructureAdvisorImpl()) ); v.setInput(companies); } }; }
Does someone spot the error? I guess not because from it is not visible at all without looking into the implementation of ObservableListTreeContentProvider. The problem in there is that when the viewer is disposed it disposes also the IObservableList passed into it so when the handler is executed the second time you’ll run into problems.
The solution to the problem though is quite simple by making the input call look like this:
v.setInput(new DecoratingObservableList(companies,false));
This way your original IObservableList is not disposed but only the decorator.