package org.jboss.as.console.client;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.proxy.PlaceManagerImpl;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import com.gwtplatform.mvp.client.proxy.TokenFormatter;
import org.jboss.as.console.client.util.message.Message;
import org.jboss.as.console.client.util.message.MessageCenter;

/**
 * @author Heiko Braun
 * @date 2/4/11
 */
public class DefaultPlaceManager extends PlaceManagerImpl {

    private MessageCenter messageCenter;

    @Inject
    public DefaultPlaceManager(
            EventBus eventBus,
            TokenFormatter tokenFormatter, MessageCenter messageCenter ) {
        super(eventBus, tokenFormatter);
        this.messageCenter = messageCenter;
    }

    @Override
    public void revealErrorPlace(String invalidHistoryToken) {
        messageCenter.notify(
                new Message("Could not reveal: "+invalidHistoryToken,
                        Message.Severity.Fatal)
        );
    }

    public void revealDefaultPlace() {
        revealPlace( new PlaceRequest(NameTokens.mainLayout) );
    }

    @Override
    public void revealUnauthorizedPlace(String unauthorizedHistoryToken) {
        revealPlace( new PlaceRequest(NameTokens.signInPage) );
    }
}

@@ -31,16 +31,59 @@
 lient;%0A%0A
+import com.allen_sauer.gwt.log.client.Log;%0A
 import c
@@ -119,16 +119,16 @@
 entBus;%0A
-
 import c
@@ -589,16 +589,64 @@
 eCenter;
+%0A    private boolean discardPlaceRequest = true;
 %0A%0A    @I
@@ -1106,16 +1106,16 @@
 .Fatal)%0A
-
         
@@ -1113,24 +1113,252 @@
 %0A        );%0A
+%0A        if(discardPlaceRequest)%0A        %7B%0A            Log.debug(%22Discard %5C%22%22+ invalidHistoryToken+%22%5C%22. Fallback to default place%22);%0A            discardPlaceRequest = false;%0A            revealUnauthorizedPlace(null);%0A        %7D%0A%0A
     %7D%0A%0A    p

discard errornous place request when application is loaded