package org.apache.karaf.webconsole.osgi.internal.bundle;

import java.util.ArrayList;
import java.util.List;

import org.apache.karaf.webconsole.core.table.PropertyColumnExt;
import org.apache.karaf.webconsole.osgi.bundle.IActionProvider;
import org.apache.karaf.webconsole.osgi.bundle.IColumnProvider;
import org.apache.karaf.webconsole.osgi.bundle.IDecorationProvider;
import org.apache.karaf.webconsole.osgi.internal.OsgiPage;
import org.apache.karaf.webconsole.osgi.internal.bundle.view.BundlesDataTable;
import org.apache.karaf.webconsole.osgi.internal.bundle.view.DecorationPanel;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.ops4j.pax.wicket.api.PaxWicketBean;
import org.ops4j.pax.wicket.api.PaxWicketMountPoint;
import org.osgi.framework.Bundle;

@PaxWicketMountPoint(mountPoint = "/osgi/bundles")
public class BundlesPage extends OsgiPage {

    @PaxWicketBean(name = "columnProviders")
    private List<IColumnProvider> columnProviders;

    @PaxWicketBean(name = "actionProviders")
    private List<IActionProvider> actionProviders;

    @PaxWicketBean(name = "decorationProviders")
    private List<IDecorationProvider> decorationProviders;

    public BundlesPage() {
        List<IColumn<Bundle>> columns = new ArrayList<IColumn<Bundle>>();
        columns.add(new AbstractColumn<Bundle>(Model.of("")) {
            public void populateItem(Item<ICellPopulator<Bundle>> cellItem, final String componentId, final IModel<Bundle> rowModel) {
                cellItem.add(new DecorationPanel(componentId, rowModel, decorationProviders));
            }
        });
        columns.add(new PropertyColumnExt<Bundle>("Bundle Id", "bundleId"));

        for (IColumnProvider provider : columnProviders) {
            columns.add(provider.getColumn());
        }

        columns.add(new PropertyColumnExt<Bundle>("Name", "symbolicName"));
        columns.add(new PropertyColumnExt<Bundle>("Version", "version.toString"));
//        columns.add(new AbstractColumn<Bundle>(Model.of("Operations")) {
//            public void populateItem(Item<ICellPopulator<Bundle>> cellItem, final String componentId, final IModel<Bundle> rowModel) {
//                cellItem.add(new BundleActionsPanel(componentId, rowModel, actionProviders));
//            }
//        });

        add(new BundlesDataTable("bundles", columns, new BundlesDataProvider(context), 100));
    }

}

@@ -52,16 +52,65 @@
 undle;%0A%0A
+import static org.apache.wicket.model.Model.of;%0A%0A
 import j
@@ -129,16 +129,16 @@
 ayList;%0A
-
 import j
@@ -866,32 +866,82 @@
 .table.IColumn;%0A
+import org.apache.wicket.markup.html.basic.Label;%0A
 import org.apach
@@ -1014,46 +1014,8 @@
 el;%0A
-import org.apache.wicket.model.Model;%0A
 impo
@@ -1143,16 +1143,63 @@
 .Bundle;
+%0Aimport org.osgi.service.startlevel.StartLevel;
 %0A%0A@PaxWi
@@ -1587,24 +1587,100 @@
 Providers;%0A%0A
+    @PaxWicketBean(name = %22startLevel%22)%0A    private StartLevel startLevel;%0A%0A
     public B
@@ -1811,30 +1811,24 @@
 umn%3CBundle%3E(
-Model.
 of(%22%22)) %7B%0A  
@@ -2081,16 +2081,16 @@
     %7D);%0A
-
         
@@ -2157,16 +2157,370 @@
 leId%22));
+%0A        columns.add(new AbstractColumn%3CBundle%3E(of(%22Start level%22)) %7B%0A            public void populateItem(Item%3CICellPopulator%3CBundle%3E%3E cellItem, final String componentId, final IModel%3CBundle%3E rowModel) %7B%0A                cellItem.add(new Label(componentId, of(startLevel.getBundleStartLevel(rowModel.getObject()))));%0A            %7D%0A            %0A        %7D);
 %0A%0A      

Introduce 'Start level' column for bundles view