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

 * Author: Nikolay Gorodnov
 * Created: 15.12.2009 16:29:37
 *
 * $Id$
 */
package com.haulmont.cuba.web.gui.components;

import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.ButtonsPanel;
import com.haulmont.cuba.gui.components.Component;
import com.vaadin.incubator.dashlayout.client.ui.VDashLayout;
import com.vaadin.ui.ClientWidget;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;

import java.util.ArrayList;
import java.util.Collection;

@SuppressWarnings("serial")
@ClientWidget(VDashLayout.class)
public class WebButtonsPanel extends WebHBoxLayout
        implements ButtonsPanel {

    public WebButtonsPanel() {
        super();
        setSpacing(true);
        setMargin(false);
    }

    public void addButton(com.haulmont.cuba.gui.components.Button actionButton) {
        add(actionButton);
    }

    public void removeButton(com.haulmont.cuba.gui.components.Button actionButton) {
        remove(actionButton);
    }

    public Collection<com.haulmont.cuba.gui.components.Button> getButtons() {
        final Collection<Component> components = getComponents();
        final Collection<com.haulmont.cuba.gui.components.Button> buttons = new ArrayList<Button>(components.size());
        for (final Component component : components) {
            buttons.add((Button) component);
        }
        return buttons;
    }

    public com.haulmont.cuba.gui.components.Button getButton(String id) {
        return getComponent(id);
    }

    @Override
    public void add(Component component) {
        if (component instanceof com.haulmont.cuba.gui.components.Button) {
            super.add(component);
        } else {
            throw new IllegalArgumentException("Component is not a button");
        }
    }

    @Override
    public void remove(Component component) {
        if (component instanceof com.haulmont.cuba.gui.components.Button) {
            super.remove(component);
        } else {
            throw new IllegalArgumentException("Component is not a button");
        }
    }

    @Override
    public void paintContent(PaintTarget target) throws PaintException {
        target.addAttribute("horizontal", true);
        super.paintContent(target);
    }
}

@@ -1519,24 +1519,74 @@
 ponents) %7B%0D%0A
+            if (component instanceof Button)%0D%0A    
             
@@ -1747,22 +1747,37 @@
         
-return
+Component component =
  getComp
@@ -1784,24 +1784,146 @@
 onent(id);%0D%0A
+        if (component instanceof Button)%0D%0A            return (Button) component;%0D%0A        else%0D%0A            return null;%0D%0A
     %7D%0D%0A%0D%0A   
@@ -1970,32 +1970,34 @@
 t component) %7B%0D%0A
+//
         if (comp
@@ -2084,32 +2084,34 @@
 dd(component);%0D%0A
+//
         %7D else %7B
@@ -2104,32 +2104,34 @@
       %7D else %7B%0D%0A
+//
             thro
@@ -2184,32 +2184,34 @@
 ot a button%22);%0D%0A
+//
         %7D%0D%0A    %7D
@@ -2272,24 +2272,26 @@
 mponent) %7B%0D%0A
+//
         if (
@@ -2385,32 +2385,34 @@
 ve(component);%0D%0A
+//
         %7D else %7B
@@ -2409,24 +2409,26 @@
   %7D else %7B%0D%0A
+//
             
@@ -2489,24 +2489,26 @@
  button%22);%0D%0A
+//
         %7D%0D%0A 

Support for arbitrary component inside ButtonsPanel