/*
 * Copyright (c) 2012 Evolveum
 *
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 * http://www.opensource.org/licenses/cddl1 or
 * CDDLv1.0.txt file in the source code distribution.
 * See the License for the specific language governing
 * permission and limitations under the License.
 *
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 *
 * Portions Copyrighted 2012 [name of copyright owner]
 */

package com.evolveum.midpoint.web.component.data.column;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.model.Model;

import java.io.Serializable;

/**
 * @author lazyman
 */
public class CheckBoxHeaderColumn<T extends Serializable> extends CheckBoxColumn {

    public CheckBoxHeaderColumn() {
        super(null);
    }

    @Override
    public Component getHeader(String componentId) {
        return new CheckBoxPanel(componentId, new Model<Boolean>(), getEnabled()) {

            @Override
            public void onUpdate(AjaxRequestTarget target) {
                DataTable table = findParent(DataTable.class);
                onUpdateHeader(target, table);
            }
        };
    }

    @Override
    public String getCssClass() {
        return "tableCheckbox";
    }

    public void onUpdateHeader(AjaxRequestTarget target, DataTable table) {

    }
}

@@ -750,16 +750,255 @@
 olumn;%0A%0A
+import com.evolveum.midpoint.util.logging.Trace;%0Aimport com.evolveum.midpoint.util.logging.TraceManager;%0Aimport com.evolveum.midpoint.web.component.data.BaseSortableDataProvider;%0Aimport com.evolveum.midpoint.web.component.util.Selectable;%0A
 import o
@@ -1149,24 +1149,85 @@
 .DataTable;%0A
+import org.apache.wicket.markup.repeater.data.IDataProvider;%0A
 import org.a
@@ -1281,16 +1281,39 @@
 lizable;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1413,24 +1413,116 @@
 oxColumn %7B%0A%0A
+    private static final Trace LOGGER = TraceManager.getTrace(CheckBoxHeaderColumn.class);%0A%0A
     public C
@@ -1636,24 +1636,83 @@
 ponentId) %7B%0A
+        final Model%3CBoolean%3E model = new Model%3CBoolean%3E();%0A
         retu
@@ -1745,36 +1745,21 @@
 nentId, 
-new Model%3CBoolean%3E()
+model
 , getEna
@@ -1915,16 +1915,106 @@
 class);%0A
+                boolean selected = model.getObject() != null ? model.getObject() : false;%0A
         
@@ -2043,16 +2043,26 @@
 (target,
+ selected,
  table);
@@ -2237,16 +2237,34 @@
  target,
+ boolean selected,
  DataTab
@@ -2271,21 +2271,735 @@
 le table) %7B%0A
+        IDataProvider provider = table.getDataProvider();%0A        if (!(provider instanceof BaseSortableDataProvider)) %7B%0A            LOGGER.debug(%22Select all checkbox work only with %7B%7D provider type. Current provider is type of %7B%7D.%22,%0A                    new Object%5B%5D%7BBaseSortableDataProvider.class.getName(), provider.getClass().getName()%7D);%0A        %7D%0A%0A        BaseSortableDataProvider baseProvider = (BaseSortableDataProvider) provider;%0A        List%3CT%3E objects = baseProvider.getAvailableData();%0A        for (T object : objects) %7B%0A            if (object instanceof Selectable) %7B%0A                Selectable selectable = (Selectable) object;%0A                selectable.setSelected(selected);%0A            %7D%0A        %7D
 %0A    %7D%0A%7D%0A

fix for MID-675. select all check box header column.