Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Problem using StartupMonitor to show a login dialog
Problem using StartupMonitor to show a login dialog [message #798212] Tue, 14 February 2012 11:39 Go to next message
Markus Stier is currently offline Markus StierFriend
Messages: 11
Registered: July 2009
Junior Member
Hi!

I'm currently developing an application which requires a user login as very first action. I've registered a StartupMonitor which implements applicationRunning() as shown below.

    public void applicationRunning()
    {
        LoginDialog loginDlg = ContextInjectionFactory.make(LoginDialog.class, m_context);

        loginDlg.create();

        loginDlg.setBlockOnOpen(true);
        loginDlg.open();
    }


The LoginDialog consists of a name field, a password field and a login button.
This works nearly as expected. The LoginDialog pops up and the user is able to login. If the authentication was successful I fire an Login_Successful_Event which is handled by a @ProcessAdditions Method. The event handler uses EPartService.showPart() to initialize the UI.

The problem: If the LoginDialog is not the active window and you press the login button (assuming name and password are already filled) an exception is thrown in getActiveWindowService().

//org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl

private EPartService getActiveWindowService() {
   IEclipseContext activeWindowContext = application.getContext().getActiveChild();
   if (activeWindowContext == null) {
      throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$
    }
(...omitted...)


It seems that the active window is not set at this point of the application life cycle.

Is this behavior 'by design'? Should I use another way to implement my login requirement? How?

Or is this a bug? The JavaDoc of applicationRunning() states that the application is completely initialized...



best regards
Markus
Re: Problem using StartupMonitor to show a login dialog [message #798241 is a reply to message #798212] Tue, 14 February 2012 12:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
When you say you registered a start up monitor you mean you registered a
lifecycle handler in your plugin.xml, right?

Why are you calling EPartService.showPart()? There's no UI up when you
are in @ProcessAdditions hence no active window.

Can you explain why you call EPartService.showPart()?

Tom

Am 14.02.12 12:39, schrieb Markus Stier:
> Hi!
>
> I'm currently developing an application which requires a user login as
> very first action. I've registered a StartupMonitor which implements
> applicationRunning() as shown below.
>
>
> public void applicationRunning()
> {
> LoginDialog loginDlg =
> ContextInjectionFactory.make(LoginDialog.class, m_context);
>
> loginDlg.create();
>
> loginDlg.setBlockOnOpen(true);
> loginDlg.open();
> }
>
>
> The LoginDialog consists of a name field, a password field and a login
> button.
> This works nearly as expected. The LoginDialog pops up and the user is
> able to login. If the authentication was successful I fire an
> Login_Successful_Event which is handled by a @ProcessAdditions Method.
> The event handler uses EPartService.showPart() to initialize the UI.
>
> The problem: If the LoginDialog is not the active window and you press
> the login button (assuming name and password are already filled) an
> exception is thrown in getActiveWindowService().
>
>
> //org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl
>
> private EPartService getActiveWindowService() {
> IEclipseContext activeWindowContext =
> application.getContext().getActiveChild();
> if (activeWindowContext == null) {
> throw new IllegalStateException("Application does not have an
> active window"); //$NON-NLS-1$
> }
> (...omitted...)
>
>
> It seems that the active window is not set at this point of the
> application life cycle.
> Is this behavior 'by design'? Should I use another way to implement my
> login requirement? How?
>
> Or is this a bug? The JavaDoc of applicationRunning() states that the
> application is completely initialized...
>
>
>
> best regards
> Markus
Re: Problem using StartupMonitor to show a login dialog [message #798261 is a reply to message #798241] Tue, 14 February 2012 12:57 Go to previous messageGo to next message
Markus Stier is currently offline Markus StierFriend
Messages: 11
Registered: July 2009
Junior Member
I register my implementation of StartupMonitor as a service in the Activator of the containing bundle.

public void start(BundleContext context) throws Exception
{
(...)
   IEclipseContext eclipseCtx = EclipseContextFactory.getServiceContext(context);
   LoginStartupMonitor lsm = new LoginStartupMonitor(eclipseCtx);
   s_loginMonitorRegistration = context.registerService(StartupMonitor.class, lsm, monitorProps);
(...)
}


The handler, which handles the Login_Successful_Event, is registered during @ProcessAdditions but executed later:

@ProcessAdditions
public void processAddtions(IEclipseContext context, IEventBroker evtBroker, final EPartService partService,
            ISessionService sessionService, final ISystemUIService sysUIService)
    {
(...)

        evtBroker.subscribe(ISessionService.EVENT_LOGIN_SUCCESSFUL, new EventHandler()
        {

            @Override
            public void handleEvent(Event evt)
            {
                String strTopic = evt.getTopic();

                // Login-Event
                if (ISessionService.EVENT_LOGIN_SUCCESSFUL.equals(strTopic)) {
                    // NavigatorPart und ResultsPart anzeigen
                    partService.showPart(NavigatorPart.ID, PartState.CREATE);
                    partService.showPart(NavigatorPart.ID, PartState.VISIBLE);

                    sysUIService.startScreenMonitoring();
                }
            }
(...)


Maybe the place to register the handler is not the most adequate, but it will be executed at a later point of time.

What I want to achieve is, that the workbench is empty besides the login dialog. If authentication succeeded the workbench should be populated with some standard views. Later I'd like to restore the previous state of the workbench.

Markus

Re: Problem using StartupMonitor to show a login dialog [message #798282 is a reply to message #798261] Tue, 14 February 2012 13:33 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
So I get this right you want to show the workbench while the login
dialog is displayed? Why don't you block in @ProcessAdditions until the
user is logged in, modify the model directly afterwards and the let the
workbench start proceed?

Tom

Am 14.02.12 13:57, schrieb Markus Stier:
> I register my implementation of StartupMonitor as a service in the
> Activator of the containing bundle.
>
>
> public void start(BundleContext context) throws Exception
> {
> (...)
> IEclipseContext eclipseCtx =
> EclipseContextFactory.getServiceContext(context);
> LoginStartupMonitor lsm = new LoginStartupMonitor(eclipseCtx);
> s_loginMonitorRegistration =
> context.registerService(StartupMonitor.class, lsm, monitorProps);
> (...)
> }
>
>
> The handler, which handles the Login_Successful_Event, is registered
> during @ProcessAdditions but executed later:
>
>
> @ProcessAdditions
> public void processAddtions(IEclipseContext context, IEventBroker
> evtBroker, final EPartService partService,
> ISessionService sessionService, final ISystemUIService
> sysUIService)
> {
> (...)
>
> evtBroker.subscribe(ISessionService.EVENT_LOGIN_SUCCESSFUL, new
> EventHandler()
> {
>
> @Override
> public void handleEvent(Event evt)
> {
> String strTopic = evt.getTopic();
>
> // Login-Event
> if
> (ISessionService.EVENT_LOGIN_SUCCESSFUL.equals(strTopic)) {
> // NavigatorPart und ResultsPart anzeigen
> partService.showPart(NavigatorPart.ID,
> PartState.CREATE);
> partService.showPart(NavigatorPart.ID,
> PartState.VISIBLE);
>
> sysUIService.startScreenMonitoring();
> }
> }
> (...)
>
>
> Maybe the place to register the handler is not the most adequate, but it
> will be executed at a later point of time.
>
> What I want to achieve is, that the workbench is empty besides the login
> dialog. If authentication succeeded the workbench should be populated
> with some standard views. Later I'd like to restore the previous state
> of the workbench.
>
> Markus
>
>
Re: Problem using StartupMonitor to show a login dialog [message #798311 is a reply to message #798282] Tue, 14 February 2012 14:19 Go to previous message
Markus Stier is currently offline Markus StierFriend
Messages: 11
Registered: July 2009
Junior Member
Yes, I want to show an empty workbench window as 'background' and the login dialog in front of it.
To my understanding @ProcessAdditions is executed right before model elements are rendered. Which counts for the workbench window too.
Blocking in @ProcessAdditions won't give me the required UI feeling.

Markus
Previous Topic:ModelService.find cannot find part stacks
Next Topic:Problems creating a Part Toolbar
Goto Forum:
  


Current Time: Mon Dec 22 05:11:55 GMT 2014

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

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