Search code examples
eclipsee4

How to get notification about window opened or created in e4


In AddOn we can get notification about application start completed by following method:

    @Optional
    @Inject
    public void appStartupComplete(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE)
                           org.osgi.service.event.Event event)

Can we get notification about aplication window was opened? I try to listen UIEvents.TrimmedWindow.TOPIC_ALL and UIEvents.Window.TOPIC_ALL but nothing happens...


Solution

  • When an addon is created the main application window has already been created so you can just find that using EModelService.

    The UIEvents.UIElement.TOPIC_TOBERENDERED event will tell you about all UI objects when they are rendered by calling MUIElement.setToBeRendered (made visible or hidden):

    @Inject
    @Optional
    void event(@UIEventTopic(UIEvents.UIElement.TOPIC_TOBERENDERED) Event event)
    {
      if (event == null)
        return;
    
      // The UI element
      Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
    
      // Rendered or hidden value
      Boolean toBeRendered = (Boolean)event.getProperty(UIEvents.EventTags.NEW_VALUE);
    

    However this event isn't generated for objects generated dynamically which don't call setToBeRendered

    The UIEvents.Context.TOPIC_CONTEXT event is fired for creation of all objects in which a context is set - biut it may be fired at other times as well.