| Where should ISaveHandler be registered? [message #903559] |
Fri, 24 August 2012 06:42  |
Markus Wiederkehr Messages: 17 Registered: August 2012 |
Junior Member |
|
|
I am working on a e4-based RCP application and I am not very happy with the default dialog for saving parts.
I understand that I have to put a custom ISaveHandler (and/or IWindowCloseHandler) in the context of the MWindow. Lars Vogel gave an example where he registered a IWindowCloseHandler from within a handler method (annotated with @Execute), see [1].
The questions is where or how should I trigger that handler so that the IWindowCloseHandler get registered automatically when the application starts up?
Other things I tried is set the IWindowCloseHandler from a life cycle handler (@PostContextCreate) and from an Addon that listens for new windows being created. Form what I can say both seems to happen too soon, i.e. the IWindowCloseHandler seems to get overwritten later by the framework.
[1] (I am not allowed to link to H T T P : //) www.vogella.com/articles/EclipseRCP/article.html#context_who
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Where should ISaveHandler be registered? [message #966231 is a reply to message #922724] |
Wed, 31 October 2012 17:29  |
René Brandstetter Messages: 8 Registered: July 2012 |
Junior Member |
|
|
Hi Markus,
it's still a hack put with this processor you should be able to replace the default IWindowCloseHandler from WBWRenderer with your own impl.
package com.test.application.addons;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
@SuppressWarnings("restriction")
public class QuitProcessor {
private final MWindow window;
private final IEventBroker eventBroker;
@Inject
public QuitProcessor(@Named("at.renbrand.sentinel.mainWindow")MWindow window, IEventBroker eventBroker){
this.window = window;
this.eventBroker = eventBroker;
}
@Execute
void installIntoContext(){
eventBroker.subscribe(UIEvents.Context.TOPIC_CONTEXT, new EventHandler(){
@Override
public void handleEvent(Event event) {
if( UIEvents.isSET(event) ){
if( window.equals( event.getProperty("ChangedElement") ) && window.getContext() != null ){
// use RunAndTrack to get notified after the IWindowCloseHanlder was changed in the IEclipseContext
window.getContext().runAndTrack(new RunAndTrack(){
private final IWindowCloseHandler quitHandler = new QuitHandler();
@Override
public boolean changed(IEclipseContext context) {
Object value = context.get(IWindowCloseHandler.class); // access the context value to be reevaluated on every future change of the value
if(!quitHandler.equals(value)){ // prevents endless loop
context.set(IWindowCloseHandler.class, quitHandler);
}
return true; // ture keeps tracking and the quitHandler as the only opportunity
}
});
}
}
}
});
}
}
[Updated on: Thu, 01 November 2012 06:14] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.12037 seconds