/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */

package org.jboss.as.console.client.core;

import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.auth.CurrentUser;
import org.jboss.ballroom.client.widgets.window.Feedback;

/**
 * @author Heiko Braun
 * @date 1/28/11
 */
public class Footer {

    private Label userName;
    private PlaceManager placeManager;

    @Inject
    public Footer(EventBus bus, CurrentUser user, PlaceManager placeManager) {
        this.userName = new Label();
        this.userName.setText(user.getUserName());
        this.placeManager = placeManager;
    }

    public Widget asWidget() {

        LayoutPanel layout = new LayoutPanel();
        layout.setStyleName("footer-panel");

        HTML dmrBrowser = new HTML("Browser");
        dmrBrowser.addStyleName("footer-link");
        dmrBrowser.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                placeManager.revealPlace(
                        new PlaceRequest(NameTokens.ToolsPresenter).with("name","browser")
                );
            }
        });


        HTML settings = new HTML(Console.CONSTANTS.common_label_settings());
        settings.addStyleName("footer-link");
        settings.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                placeManager.revealPlace(
                        new PlaceRequest(NameTokens.SettingsPresenter)
                );
            }
        });


        HTML logout = new HTML(Console.CONSTANTS.common_label_logout());
        logout.addStyleName("footer-link");
        logout.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Feedback.confirm(
                        Console.CONSTANTS.common_label_logout(),
                        Console.CONSTANTS.logout_confirm(),
                        new Feedback.ConfirmationHandler() {
                            @Override
                            public void onConfirmation(boolean isConfirmed) {
                                if(isConfirmed)
                                {
                                    new LogoutCmd().execute();
                                }
                            }
                        }
                );

            }
        });

        layout.add(logout);
        layout.add(settings);
        layout.add(dmrBrowser);

        HTML version = new HTML(org.jboss.as.console.client.Build.VERSION);
        version.getElement().setAttribute("style", "color:#ffffff;font-size:10px; align:left");
        layout.add(version);

        layout.setWidgetLeftWidth(version, 20, Style.Unit.PX, 200, Style.Unit.PX);
        layout.setWidgetTopHeight(version, 3, Style.Unit.PX, 16, Style.Unit.PX);

        layout.setWidgetRightWidth(logout, 5, Style.Unit.PX, 60, Style.Unit.PX);
        layout.setWidgetTopHeight(logout, 2, Style.Unit.PX, 28, Style.Unit.PX);

        layout.setWidgetRightWidth(settings, 65, Style.Unit.PX, 120, Style.Unit.PX);
        layout.setWidgetTopHeight(settings, 2, Style.Unit.PX, 28, Style.Unit.PX);

        layout.setWidgetRightWidth(dmrBrowser, 125, Style.Unit.PX, 185, Style.Unit.PX);
        layout.setWidgetTopHeight(dmrBrowser, 2, Style.Unit.PX, 28, Style.Unit.PX);


        layout.getElement().setAttribute("role", "complementary");

        return layout;
    }
}

@@ -1191,16 +1191,60 @@
 entBus;%0A
+import com.google.gwt.layout.client.Layout;%0A
 import c
@@ -1319,58 +1319,164 @@
 .ui.
-Label;%0Aimport com.google.gwt.user.client.ui.Layout
+HorizontalPanel;%0Aimport com.google.gwt.user.client.ui.Label;%0Aimport com.google.gwt.user.client.ui.LayoutPanel;%0Aimport com.google.gwt.user.client.ui.Vertical
 Pane
@@ -4002,57 +4002,142 @@
     
-layout.add(logout);%0A        layout.add(settings);
+HorizontalPanel tools = new HorizontalPanel();%0A        tools.add(dmrBrowser);%0A        tools.add(settings);%0A        tools.add(logout);%0A
 %0A   
@@ -4152,26 +4152,21 @@
 out.add(
-dmrBrowser
+tools
 );%0A%0A    
@@ -4563,22 +4563,21 @@
 htWidth(
-logout
+tools
 , 5, Sty
@@ -4588,17 +4588,18 @@
 nit.PX, 
-6
+50
 0, Style
@@ -4643,22 +4643,21 @@
 pHeight(
-logout
+tools
 , 2, Sty
@@ -4717,326 +4717,58 @@
 dget
-RightWidth(settings, 65, Style.Unit.PX, 120, Style.Unit.PX);%0A        layout.setWidgetTopHeight(settings, 2, Style.Unit.PX, 28, Style.Unit.PX);%0A%0A        layout.setWidgetRightWidth(dmrBrowser, 125, Style.Unit.PX, 185, Style.Unit.PX);%0A        layout.setWidgetTopHeight(dmrBrowser, 2, Style.Unit.PX, 28, Style.Unit.PX
+HorizontalPosition(tools, Layout.Alignment.END
 );%0A%0A
-%0A
     

Fix AS7-5447