Open PartDescriptor on Application Startup [message #1752237] |
Fri, 20 January 2017 03:24  |
Eclipse User |
|
|
|
Hi everyone,
I have a PartDescriptor in my e4 application and on start up of the application a specific Part using this PartDescriptor should be opened. The Part is opened using a Handler class which is called on UILifeCycle.APP_STARTUP_COMPLETE event using an AddOn.
Infrequently I could observe a "java.lang.IllegalStateException: Application does not have an active window" using this approach. It happens from time to time, without having clear steps to reproduce.
Caused by: java.lang.IllegalStateException: Application does not have an active window
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getActiveWindowService(ApplicationPartServiceImpl.java:43)
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.findPart(ApplicationPartServiceImpl.java:87)
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.findPart(ApplicationPartServiceImpl.java:87)
at com.my.package.Handler.execute(Handler.java:54)
My Handler#execute code for opening the part looks like (first line here is l. 54 that causes the exception)
MPart part = partService.findPart(PART_ID);
if (Objects.isNull(previewPart)) {
part = partService.createPart(PART_DESCRIPTOR_ID);
part.setElementId(PART_ID);
((MPartSashContainer) partSashContainer).getChildren().add(part);
partService.showPart(part, PartState.CREATE);
}
This handler is called by an AddOn with the following method
@Inject
@Optional
public void notifyApplicationStartUp(@UIEventTopic(UILifeCycle.APP_STARTUP_COMPLETE) Object obj, IEclipseContext context) {
//...
Handler handler = ContextInjectionFactory.make(Handler.class, context);
ContextInjectionFactory.invoke(handler, Execute.class, context);
}
The behavior could be observed on several Windows (7-10) clients.
Does anyone has an idea what causes the exception, something i possible currently miss in my code or another approach how to open the part using the descriptor on start-up?
Thanks and regards, Chris
|
|
|
|
Re: Open PartDescriptor on Application Startup [message #1752882 is a reply to message #1752237] |
Mon, 30 January 2017 04:56  |
Eclipse User |
|
|
|
Thanks a lot for the "Addons are created before the rendering engine actually renders the model" hint. This was useful.
Unfortunately the suggested approach don't work for me as i'm in a plug-in context and have no access to the e4 application to modify the Lifecycle Handler.
I now tested a different approach listening to the "creation" of the parent MPartSashContainer using the following code. This seems to works as far i can say for now (as i mentioned, unfortunately the original issue only occurs not clearly reproducible and only in a small number of starts...)
@PostConstruct
public void hookListner() {
eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, new EventHandler() {
@Override
public void handleEvent(Event event) {
Object elementProperty = event.getProperty(UIEvents.EventTags.ELEMENT);
if (elementProperty instanceof MPartSashContainer) {
MPartSashContainer container = (MPartSashContainer) elementProperty;
if (Objects.equals(container.getElementId(), CONTAINER_ELEMENT_ID) &&
Objects.equals(event.getProperty(UIEvents.EventTags.TYPE), UIEvents.EventTypes.SET)) {
openPart();
eventBroker.unsubscribe(this);
}
}
}
});
}
|
|
|
Powered by
FUDForum. Page generated in 0.05495 seconds