|
|
|
|
|
|
|
Re: How to forestall the window closing [message #922951 is a reply to message #922580] |
Tue, 25 September 2012 13:36 |
Christoph Keimel Messages: 482 Registered: December 2010 Location: Germany |
Senior Member |
|
|
Hi Guys
I spent some time with this today and as far as I can see now, it's not easy to set up your own IWindowCloseHandler.
The problem is that, in WBWRenderer the IEclipseContext is added to the element before the the default IWindowCloseHandler is set. That means, that listening to the Context-SET-Event doesn't work, since the IWindowCloseHandler will be overwritten.
(The same thing is true for the Widget-SET-event, so that doesn't work either.)
Does anyone have any suggestions, or should I open a bug for this?
Greetings
Christoph
[Updated on: Tue, 25 September 2012 13:51] Report message to a moderator
|
|
|
|
Re: How to forestall the window closing [message #922960 is a reply to message #922951] |
Tue, 25 September 2012 13:43 |
Christoph Keimel Messages: 482 Registered: December 2010 Location: Germany |
Senior Member |
|
|
Hello again
This workaround will probably work for most cases. This Addon will listen to the creation of a part and overwrite its Parent-Windows IWindowCloseHandler.
It isn't ideal, since it implies that:
1) A Part will be created
2) The Part is created after the Window
public class WindowCloseHandlerAddon {
private static final Logger logger = LoggerFactory.getLogger(WindowCloseHandlerAddon.class);
@Inject private IEventBroker eventBroker;
private EventHandler handler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (!UIEvents.isSET(event))
return;
Object origin = event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(origin instanceof MPart))
return;
MPart contextPart = (MPart) origin;
MWindow contextWindow = contextPart.getContext().get(MWindow.class);
IEclipseContext eclipseContext = contextWindow.getContext();
logger.info("Placing IWindowCloseHandler in window {}", contextWindow.getElementId()); //$NON-NLS-1$
eclipseContext.set(IWindowCloseHandler.class, new IWindowCloseHandler() {
@Override
public boolean close(MWindow windowParam) {
logger.info("My IWindowCloseHandler was called for window: {}", windowParam.getElementId()); //$NON-NLS-1$
return true;
}
});
eventBroker.unsubscribe(this);
}
};
@PostConstruct
public void init() {
//String topic = UIEvents.Context.TOPIC_CONTEXT;
String topic = UIEvents.UIElement.TOPIC_WIDGET;
eventBroker.subscribe(topic, handler);
}
}
Hope this helps.
Christoph
[Updated on: Tue, 25 September 2012 13:52] Report message to a moderator
|
|
|
|
Re: How to forestall the window closing [message #922990 is a reply to message #922969] |
Tue, 25 September 2012 14:19 |
Eclipse User |
|
|
|
Then we can fall back to the activation of the window.
@Inject
@Optional
public void test(@UIEventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event o ){
if (o!=null) {
Object mui = o.getProperty(UIEvents.EventTags.ELEMENT);
if ((mui instanceof MApplication))
{
MWindow win = (MWindow) o.getProperty(UIEvents.EventTags.NEW_VALUE);
System.err.println(win);
}
}
}
|
|
|
|
|
|
Re: How to forestall the window closing [message #923682 is a reply to message #923389] |
Wed, 26 September 2012 05:24 |
Gennady Gromov Messages: 24 Registered: May 2011 |
Junior Member |
|
|
Thanks for your replies with solutions of this problem. But why is it a problem? Why is it so complex?
I think It must be provided appropriate URI classes for application (or workbench) and for windows similar to URI class for Parts. These classes must support all theirs possible lifecycle events by using appropriate annotations such as:
@PostContextCreate
@Focus
@FocusLost
@CanClose (with boolean result)
@PreDestroy
... ets.
Incidentally, I think for Part classes should be feasible also and methods with @CanClose (boolean) and @FocusLost too.
These are not specific events which can be required very seldom. It is required for most applications and implementation of such events should be laconic.
Am I not right?
[Updated on: Wed, 26 September 2012 06:53] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06425 seconds