Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Open PartDescriptor on Application Startup(java.lang.IllegalStateException: Application does not have an active window exception)
Open PartDescriptor on Application Startup [message #1752237] Fri, 20 January 2017 08:24 Go to next message
Chris Klinger is currently offline Chris KlingerFriend
Messages: 2
Registered: January 2017
Junior Member
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 #1752525 is a reply to message #1752237] Tue, 24 January 2017 17:47 Go to previous messageGo to next message
Patrik Suzzi is currently offline Patrik SuzziFriend
Messages: 2
Registered: February 2018
Junior Member
The Addons are created before the rendering engine actually renders the model, see: wiki.eclipse.org/Eclipse4/RCP/Modeled_UI/Addons

For an E4 Application, I would use a Lifecycle Handler, as follows:

1. Reference your ApplicationLifecycle handler class from plugin.xml

<property name="lifeCycleURI" value="platform:/plugin/<plug-in-id>/<path-to-handler-class>" />


2. write your lifecycle handler class

public class ApplicationLifecycleHandler {

    @PostContextCreate
    public void startup(IEclipseContext context) {
       // do initialization 
    }
}


3. Add an hook to handle events at Application Startup Complete

@PostContextCreate
public void postContextCreate(final IEventBroker eventBroker, etc .. ) {

    // 
    eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE,
            new EventHandler() {
                @Override
                public void handleEvent(Event event) {
                    // Your code executed at startup,
                    // after application startup is completed
                }
            });

}


Regards,

Ing. Patrik Suzzi
Consultant Software Engineer,
Eclipse Platform Committer
https://about.me/psuzzi
Re: Open PartDescriptor on Application Startup [message #1752882 is a reply to message #1752237] Mon, 30 January 2017 09:56 Go to previous message
Chris Klinger is currently offline Chris KlingerFriend
Messages: 2
Registered: January 2017
Junior Member
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);
                }
            }
        }
    });
}
Previous Topic:Inject values into fields when class instantiated in my code
Next Topic:Accessing ESelectionService From a Dialog
Goto Forum:
  


Current Time: Thu Apr 25 04:56:28 GMT 2024

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

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

Back to the top