/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: Konstantin Krivopustov
 * Created: 04.12.2008 12:02:22
 *
 * $Id$
 */
package com.haulmont.cuba.web;

import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Window;

public class AppWindow extends Window implements ConnectionListener
{
    private OrderedLayout currentLayout;

    public AppWindow(App app) {
        super();
        setCaption(getAppCaption());
        app.setMainWindow(this);

        currentLayout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
        initWelcomeLayout();
        addComponent(currentLayout);
    }

    protected String getAppCaption() {
        return "Cuba Application";
    }

    public App getApp() {
        return (App) getApplication();
    }

    protected void initWelcomeLayout() {
        Label label = new Label("Hello from Cuba!");
        currentLayout.addComponent(label);

        LoginDialog dialog = new LoginDialog(this, getApp().getConnection());
        dialog.show();
    }

    protected void initMainLayout() {
        Label label = new Label("Logged in as " + getApp().getConnection().getSession().getName());
        currentLayout.addComponent(label);

        Button logoutBtn = new Button("Logout",
                new Button.ClickListener() {
                    public void buttonClick(Button.ClickEvent event) {
                        getApp().getConnection().logout();
                    }
                }
        );
        currentLayout.addComponent(logoutBtn);
    }

    public void connectionStateChanged(Connection connection) {
        if (currentLayout != null)
            removeComponent(currentLayout);
        currentLayout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);

        if (connection.isConnected()) {
            initMainLayout();
        }
        else {
            initWelcomeLayout();
        }

        addComponent(currentLayout);
    }
}

@@ -537,22 +537,19 @@
 dLayout 
-curren
+roo
 tLayout;
@@ -677,38 +677,35 @@
 is);%0D%0A%0D%0A        
-curren
+roo
 tLayout = new Or
@@ -799,38 +799,35 @@
    addComponent(
-curren
+roo
 tLayout);%0D%0A    %7D
@@ -907,32 +907,116 @@
 ion%22;%0D%0A    %7D%0D%0A%0D%0A
+    protected OrderedLayout getRootLayout() %7B%0D%0A        return rootLayout;%0D%0A    %7D%0D%0A%0D%0A
     public App g
@@ -1171,38 +1171,35 @@
 ba!%22);%0D%0A        
-curren
+roo
 tLayout.addCompo
@@ -1466,38 +1466,35 @@
 me());%0D%0A        
-curren
+roo
 tLayout.addCompo
@@ -1794,30 +1794,27 @@
 );%0D%0A        
-curren
+roo
 tLayout.addC
@@ -1921,22 +1921,19 @@
     if (
-curren
+roo
 tLayout 
@@ -1962,38 +1962,35 @@
 removeComponent(
-curren
+roo
 tLayout);%0D%0A     
@@ -1992,22 +1992,19 @@
         
-curren
+roo
 tLayout 
@@ -2236,14 +2236,11 @@
 ent(
-curren
+roo
 tLay

Support simple DemoApp