/*
 * Copyright 2008-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.broadleafcommerce.admin.client.view.customer;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;
import org.broadleafcommerce.openadmin.client.BLCMain;
import org.broadleafcommerce.openadmin.client.reflection.Instantiable;
import org.broadleafcommerce.openadmin.client.view.dynamic.DynamicEntityListDisplay;
import org.broadleafcommerce.openadmin.client.view.dynamic.DynamicEntityListView;
import org.broadleafcommerce.openadmin.client.view.dynamic.form.DynamicFormDisplay;
import org.broadleafcommerce.openadmin.client.view.dynamic.form.DynamicFormView;
import org.broadleafcommerce.openadmin.client.view.dynamic.form.FormOnlyView;
import org.broadleafcommerce.openadmin.client.view.dynamic.grid.GridStructureView;

/**
 * 
 * @author jfischer
 *
 */
public class CustomerView extends HLayout implements Instantiable, CustomerDisplay {
    
    protected DynamicFormView dynamicFormDisplay;
    protected DynamicEntityListView listDisplay;
    protected ToolStripButton updateLoginButton;
    protected GridStructureView customerAddressDisplay;
    
    public CustomerView() {
        setHeight100();
        setWidth100();
    }
    
    @Override
    public void build(DataSource entityDataSource, DataSource... additionalDataSources) {
        VLayout leftVerticalLayout = new VLayout();
        leftVerticalLayout.setID("customerLeftVerticalLayout");
        leftVerticalLayout.setHeight100();
        leftVerticalLayout.setWidth("50%");
        leftVerticalLayout.setShowResizeBar(true);
        
        listDisplay = new DynamicEntityListView(BLCMain.getMessageManager().getString("customerListTitle"), entityDataSource, false);
        leftVerticalLayout.addMember(listDisplay);
       
        dynamicFormDisplay = new DynamicFormView(BLCMain.getMessageManager().getString("customerDetailsTitle"), entityDataSource);
        dynamicFormDisplay.setWidth("50%");
        ToolStrip toolbar = dynamicFormDisplay.getToolbar();
        toolbar.addFill();

        customerAddressDisplay = new GridStructureView(BLCMain.getMessageManager().getString("customerAddressListTitle"), false, false);
        ((FormOnlyView) dynamicFormDisplay.getFormOnlyDisplay()).addMember(customerAddressDisplay);
        
        updateLoginButton = new ToolStripButton();  
        updateLoginButton.setIcon(GWT.getModuleBaseURL()+"sc/skins/Broadleaf/images/headerIcons/settings.png");
        updateLoginButton.setDisabled(true);
        updateLoginButton.setTitle(BLCMain.getMessageManager().getString("resetPasswordPrompt"));
        updateLoginButton.setOverflow(Overflow.VISIBLE);

        toolbar.addButton(updateLoginButton);
        toolbar.addSpacer(6);
        leftVerticalLayout.setParentElement(this);
        addMember(leftVerticalLayout);
        addMember(dynamicFormDisplay);
    }

    @Override
    public Canvas asCanvas() {
        return this;
    }

    @Override
    public DynamicFormDisplay getDynamicFormDisplay() {
        return dynamicFormDisplay;
    }
    
    @Override
    public DynamicEntityListDisplay getListDisplay() {
        return listDisplay;
    }

    @Override
    public ToolStripButton getUpdateLoginButton() {
        return updateLoginButton;
    }

    @Override
    public GridStructureView getCustomerAddressDisplay() {
        return customerAddressDisplay;
    }
    
}

@@ -679,393 +679,8 @@
 r;%0A%0A
-import com.google.gwt.core.client.GWT;%0Aimport com.smartgwt.client.data.DataSource;%0Aimport com.smartgwt.client.types.Overflow;%0Aimport com.smartgwt.client.widgets.Canvas;%0Aimport com.smartgwt.client.widgets.layout.HLayout;%0Aimport com.smartgwt.client.widgets.layout.VLayout;%0Aimport com.smartgwt.client.widgets.toolbar.ToolStrip;%0Aimport com.smartgwt.client.widgets.toolbar.ToolStripButton;%0A
 impo
@@ -730,16 +730,16 @@
 LCMain;%0A
+
 import o
@@ -801,16 +801,75 @@
 tiable;%0A
+import org.broadleafcommerce.openadmin.client.view.TabSet;%0A
 import o
@@ -1354,16 +1354,485 @@
 eView;%0A%0A
+import com.google.gwt.core.client.GWT;%0Aimport com.smartgwt.client.data.DataSource;%0Aimport com.smartgwt.client.types.Overflow;%0Aimport com.smartgwt.client.types.Side;%0Aimport com.smartgwt.client.widgets.Canvas;%0Aimport com.smartgwt.client.widgets.layout.HLayout;%0Aimport com.smartgwt.client.widgets.layout.VLayout;%0Aimport com.smartgwt.client.widgets.tab.Tab;%0Aimport com.smartgwt.client.widgets.toolbar.ToolStrip;%0Aimport com.smartgwt.client.widgets.toolbar.ToolStripButton;%0A%0A
 /**%0A * %0A
@@ -2795,32 +2795,472 @@
 splay);%0A       %0A
+        TabSet topTabSet = new TabSet();%0A        topTabSet.setID(%22customerTopTabSet%22);%0A        topTabSet.setTabBarPosition(Side.TOP);%0A        topTabSet.setPaneContainerOverflow(Overflow.HIDDEN);%0A        topTabSet.setWidth100();%0A        topTabSet.setHeight100();%0A        topTabSet.setPaneMargin(0);%0A%0A        Tab detailsTab = new Tab(BLCMain.getMessageManager().getString(%22detailsTabTitle%22));%0A        detailsTab.setID(%22customerDetailsTab%22);%0A%0A
         dynamicF
@@ -3376,24 +3376,28 @@
 rce);%0A      
+  //
   dynamicFor
@@ -4199,16 +4199,105 @@
 cer(6);%0A
+%0A        detailsTab.setPane(dynamicFormDisplay);%0A%0A        topTabSet.addTab(detailsTab);%0A%0A
         
@@ -4396,37 +4396,29 @@
 dMember(
-dynamicFormDisplay
+topTabSet
 );%0A
+%0A
     %7D%0A%0A 

add tabbing to customer so modules can add additional tabs as needed