DanglingElse
DanglingElse

Reputation: 263

How to clear a JFace TreeViewer when the editor with the domain object being listened is closed?

I have implemented a view extending the ViewPart, in which a JFace tree viewer, a table viewer and a bunch of text boxes reside. I have registered a SelectionListener to this view, which listens to a special domain model in the workbench. This model is created as an EMF model, so if an Ecore editor is active and has any model instance in it, upon selection the data binding happens etc. and the tree viewer get filled with input.

But once the input is set into the tree viewer, if I close the active Ecore editor that has the domain object, the input in the tree viewer stays intact. What I need is, if the editor being listened upon selection is closed, so the input in the viewer has to be cleaned and the tree viewer is empty again.

I probably need a further listener mechanism for this, but I am not so sure about which one and how? Would be very glad, if anyone could help. Thanks!

Upvotes: 0

Views: 237

Answers (1)

greg-449
greg-449

Reputation: 111217

You can use IPartListener in your view to listen for changes to all parts in the workbench.

Get the IPartService in your view:

IPartService service = (IPartService)getSite().getService(IPartService.class);

add the listener:

service.addPartListener(listener);

don't forget to remove the listener in the view dispose.

You are probably going to be most interested in the partClosed and / or partDeactivated methods.

There is also IPartListener2 which has some additional events.

Upvotes: 1

Related Questions