Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Close Part Listener
Close Part Listener [message #847713] Tue, 17 April 2012 15:25 Go to next message
Philippe Fry is currently offline Philippe Fry
Messages: 6
Registered: April 2012
Junior Member
Hi,

Can you tell me the best practice to be informed when user close a Part ? I thought add a PartListener on a EPartService, but I don't know where is the best place to do that. I tried to add and Addon to my E4 application model but the EPartService injected is an AplicationPartServiceImpl (not a PartServiceImpl), and the add of a PartListener throws new UnsupportedOperationException("Listeners should only be attached/removed from a window's part service");

Futhermore I would like to be notified when user close a certain kind of part (of type CompatibilityEditor)

I cannot annotate a method in my view with @PreDestroy (and do my stuff in this method) because I have not write the view's code myself is't a org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor

Because I use compatibility layer my views are opened like that :
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.openEditor(..., DiagramEditor.DIAGRAM_EDITOR_ID);


Thanks a lot
Re: Close Part Listener [message #847968 is a reply to message #847713] Tue, 17 April 2012 20:53 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

The framework sends events for a lot of event types and you can easily subscribe to those using the IEventBroker. Here is an addon that registers a listener like the one you require. I haven't tested it with compatibility layers but it should work.
public class TestAddon {
	
	private EventHandler testHandler;
	@PostConstruct
	public void pc(IEventBroker eventBroker)
	{
		testHandler = new EventHandler() {
			
			@Override
			public void handleEvent(Event event) {
				Object part = event.getProperty(UIEvents.EventTags.ELEMENT);
				boolean tbr =(Boolean) event.getProperty(UIEvents.EventTags.NEW_VALUE);
				if (part instanceof MPart){
					System.out.println("Part "+((MPart)part).getElementId()+" is "+(!tbr?"NOT":"")+" visible");
				}
			}
		};
		eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, testHandler);
	}
	
	//....................
}


So the idea is:
- implement an event handler, check that the ELEMENT event tag is instance of MPart, get the new value (NEW_VALUE event tag) and do what you wish with it.
- subscribe this handler to the TOBERENDERED topic
- unsubscribe when you're done.
Re: Close Part Listener [message #848560 is a reply to message #847713] Wed, 18 April 2012 10:55 Go to previous messageGo to next message
Philippe Fry is currently offline Philippe Fry
Messages: 6
Registered: April 2012
Junior Member
It works !

Thanks Sopot, your message has been very usefull.
Re: Close Part Listener [message #1217069 is a reply to message #848560] Thu, 28 November 2013 19:19 Go to previous message
Roman Dawydkin is currently offline Roman Dawydkin
Messages: 3
Registered: July 2009
Junior Member
Just a note, compatibility editor system in Eclipse IDE really is using UIEvents.UIElement.TOPIC_WIDGET for same purpose.
Previous Topic:JavaScript Explorer not showing project until refresh in eclipse 4 RCP application
Next Topic:Loading order of model fragment
Goto Forum:
  


Current Time: Fri Oct 31 18:45:28 GMT 2014

Powered by FUDForum. Page generated in 0.01681 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software