package scoutmgr.client.application.navbar;

import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.proxy.NavigationEvent;
import com.gwtplatform.mvp.client.proxy.NavigationHandler;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest;
import javax.inject.Inject;
import scoutmgr.client.entity.security.User;
import scoutmgr.client.event.security.UserLoadedEvent;
import scoutmgr.client.event.security.UserLoggedOutEvent;
import scoutmgr.client.ioc.FrontendContext;
import scoutmgr.client.security.PermissionUtil;

public class NavbarPresenter
  extends PresenterWidget<NavbarPresenter.View>
  implements NavigationHandler
{
  interface View
    extends com.gwtplatform.mvp.client.View
  {
    void setMenuItemActive( PlaceRequest nameToken );

    void disableAllAccess();

    void enablePersonalRecordAccess( boolean b );

    void enableSiteAdminFunctionality( boolean b );

    void enableUserManagement( boolean b );
  }

  @Inject
  private PlaceManager _placeManager;

  @Inject
  private FrontendContext _frontendContext;

  @Inject
  NavbarPresenter( final EventBus eventBus,
                   final View view )
  {
    super( eventBus, view );
    eventBus.addHandler( UserLoadedEvent.TYPE, event -> configureMenus() );
    eventBus.addHandler( UserLoggedOutEvent.TYPE, event -> configureMenus() );
  }

  private void configureMenus()
  {
    if ( !_frontendContext.isLoggedIn() )
    {
      getView().disableAllAccess();
    }
    else {
      final User user = _frontendContext.getUser();
      getView().disableAllAccess( );
      getView().enablePersonalRecordAccess( null != user.getPerson() );
      getView().enableSiteAdminFunctionality( PermissionUtil.isSiteAdmin( user ) );
      getView().enableUserManagement( PermissionUtil.isUserAdmin( user ) );
    }
  }

  @Override
  protected void onBind()
  {
    super.onBind();
    addRegisteredHandler( NavigationEvent.getType(), this );
    getView().setMenuItemActive( _placeManager.getCurrentPlaceRequest() );
  }

  @Override
  public void onNavigation( final NavigationEvent navigationEvent )
  {
    getView().setMenuItemActive( navigationEvent.getRequest() );
  }
}

@@ -1580,16 +1580,20 @@
     else
+%0A   
  %7B%0A     
@@ -1672,17 +1672,16 @@
 lAccess(
- 
 );%0A     
@@ -2037,24 +2037,46 @@
 (), this );%0A
+    configureMenus();%0A
     getView(

Configure menus on bind, as this may occur after broadcast of user loaded when user is resuming an old session