package org.ovirt.engine.ui.common.widget.uicommon.template;

import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
import org.ovirt.engine.ui.common.CommonApplicationConstants;
import org.ovirt.engine.ui.common.system.ClientStorage;
import org.ovirt.engine.ui.common.uicommon.model.SearchableTableModelProvider;
import org.ovirt.engine.ui.common.widget.action.UiCommandButtonDefinition;
import org.ovirt.engine.ui.common.widget.table.column.EnumColumn;
import org.ovirt.engine.ui.common.widget.table.column.TextColumnWithTooltip;
import org.ovirt.engine.ui.common.widget.uicommon.AbstractModelBoundTableWidget;
import org.ovirt.engine.ui.uicommonweb.UICommand;
import org.ovirt.engine.ui.uicommonweb.models.templates.TemplateInterfaceListModel;

import com.google.gwt.event.shared.EventBus;

public class TemplateInterfaceListModelTable extends AbstractModelBoundTableWidget<VmNetworkInterface, TemplateInterfaceListModel> {

    public TemplateInterfaceListModelTable(
            SearchableTableModelProvider<VmNetworkInterface, TemplateInterfaceListModel> modelProvider,
            EventBus eventBus, ClientStorage clientStorage) {
        super(modelProvider, eventBus, clientStorage, false);
    }

    @Override
    public void initTable(CommonApplicationConstants constants) {
        TextColumnWithTooltip<VmNetworkInterface> nameColumn = new TextColumnWithTooltip<VmNetworkInterface>() {
            @Override
            public String getValue(VmNetworkInterface object) {
                return object.getName();
            }
        };
        getTable().addColumn(nameColumn, constants.nameInterface());

        TextColumnWithTooltip<VmNetworkInterface> networkNameColumn = new TextColumnWithTooltip<VmNetworkInterface>() {
            @Override
            public String getValue(VmNetworkInterface object) {
                return object.getNetworkName();
            }
        };
        getTable().addColumn(networkNameColumn, constants.networkNameInterface());

        TextColumnWithTooltip<VmNetworkInterface> typeColumn = new EnumColumn<VmNetworkInterface, VmInterfaceType>() {
            @Override
            protected VmInterfaceType getRawValue(VmNetworkInterface object) {
                return VmInterfaceType.forValue(object.getType());
            }
        };
        getTable().addColumn(typeColumn, constants.typeInterface());

        getTable().addActionButton(new UiCommandButtonDefinition<VmNetworkInterface>(getEventBus(), constants.newInterface()) {
            @Override
            protected UICommand resolveCommand() {
                return getModel().getNewCommand();
            }
        });

        getTable().addActionButton(new UiCommandButtonDefinition<VmNetworkInterface>(getEventBus(), constants.editInterface()) {
            @Override
            protected UICommand resolveCommand() {
                return getModel().getEditCommand();
            }
        });

        getTable().addActionButton(new UiCommandButtonDefinition<VmNetworkInterface>(getEventBus(), constants.removeInterface()) {
            @Override
            protected UICommand resolveCommand() {
                return getModel().getRemoveCommand();
            }
        });
    }

}


@@ -540,20 +540,238 @@
 .column.
-Enum
+BooleanColumn;%0Aimport org.ovirt.engine.ui.common.widget.table.column.CheckboxColumn;%0Aimport org.ovirt.engine.ui.common.widget.table.column.EnumColumn;%0Aimport org.ovirt.engine.ui.common.widget.table.column.NicActivateStatus
 Column;%0A
@@ -1598,24 +1598,147 @@
 onstants) %7B%0A
+        getTable().addColumn(new NicActivateStatusColumn%3CVmNetworkInterface%3E(), constants.empty(), %2230px%22); //$NON-NLS-1$%0A%0A
         Text
@@ -2072,361 +2072,1391 @@
     
-TextColumnWithTooltip%3CVmNetworkInterface%3E networkNameColumn = new TextColumnWithTooltip%3CVmNetworkInterface%3E() %7B%0A            @Override%0A            public String getValue(VmNetworkInterface object) %7B%0A                return object.getNetworkName();%0A            %7D%0A        %7D;%0A        getTable().addColumn(networkNameColumn, constants.networkNameInterface());
+CheckboxColumn%3CVmNetworkInterface%3E pluggedColumn = new CheckboxColumn%3CVmNetworkInterface%3E() %7B%0A            @Override%0A            public Boolean getValue(VmNetworkInterface object) %7B%0A                return object.isPlugged();%0A            %7D%0A%0A            @Override%0A            protected boolean canEdit(VmNetworkInterface object) %7B%0A                return false;%0A            %7D%0A        %7D;%0A%0A        getTable().addColumnWithHtmlHeader(pluggedColumn, constants.plugged(), %2260px%22); //$NON-NLS-1$%0A%0A        TextColumnWithTooltip%3CVmNetworkInterface%3E networkNameColumn = new TextColumnWithTooltip%3CVmNetworkInterface%3E() %7B%0A            @Override%0A            public String getValue(VmNetworkInterface object) %7B%0A                return object.getNetworkName();%0A            %7D%0A        %7D;%0A        getTable().addColumn(networkNameColumn, constants.networkNameInterface());%0A%0A        BooleanColumn%3CVmNetworkInterface%3E linkStateColumn =%0A                new BooleanColumn%3CVmNetworkInterface%3E(constants.linkedNetworkInteface(),%0A                        constants.unlinkedNetworkInteface()) %7B%0A                    @Override%0A                    protected Boolean getRawValue(VmNetworkInterface object) %7B%0A                        return object.isLinked();%0A                    %7D%0A                %7D;%0A%0A        getTable().addColumnWithHtmlHeader(linkStateColumn, constants.linkStateNetworkInteface(), %2265px%22); //$NON-NLS-1$
 %0A%0A  

add plugged and link state columns to template->nics sub tab