package org.ovirt.engine.ui.webadmin.section.main.view.tab.network;

import org.ovirt.engine.core.common.businessentities.network.NetworkView;
import org.ovirt.engine.core.common.businessentities.network.ExternalSubnet;
import org.ovirt.engine.core.common.businessentities.network.ExternalSubnet.IpVersion;
import org.ovirt.engine.ui.common.uicommon.model.SearchableDetailModelProvider;
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.uicommonweb.UICommand;
import org.ovirt.engine.ui.uicommonweb.models.networks.NetworkListModel;
import org.ovirt.engine.ui.uicommonweb.models.networks.NetworkExternalSubnetListModel;
import org.ovirt.engine.ui.webadmin.ApplicationConstants;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.network.SubTabNetworkExternalSubnetPresenter;
import org.ovirt.engine.ui.webadmin.section.main.view.AbstractSubTabTableView;
import org.ovirt.engine.ui.webadmin.widget.action.WebAdminButtonDefinition;

import com.google.inject.Inject;

public class SubTabNetworkExternalSubnetView extends AbstractSubTabTableView<NetworkView, ExternalSubnet, NetworkListModel, NetworkExternalSubnetListModel>
        implements SubTabNetworkExternalSubnetPresenter.ViewDef {

    @Inject
    public SubTabNetworkExternalSubnetView(SearchableDetailModelProvider<ExternalSubnet, NetworkListModel, NetworkExternalSubnetListModel> modelProvider,
            ApplicationConstants constants) {
        super(modelProvider);
        initTable(constants);
        initWidget(getTable());
    }

    void initTable(ApplicationConstants constants) {
        getTable().enableColumnResizing();

        TextColumnWithTooltip<ExternalSubnet> nameColumn =
                new TextColumnWithTooltip<ExternalSubnet>() {
                    @Override
                    public String getValue(ExternalSubnet object) {
                        return object.getName();
                    }
                };
        getTable().addColumn(nameColumn, constants.nameExternalSubnet(), "300px"); //$NON-NLS-1$

        TextColumnWithTooltip<ExternalSubnet> cidrColumn =
                new TextColumnWithTooltip<ExternalSubnet>() {
            @Override
            public String getValue(ExternalSubnet object) {
                return object.getCidr();
            }
        };
        getTable().addColumn(cidrColumn, constants.cidrExternalSubnet(), "200px"); //$NON-NLS-1$

        TextColumnWithTooltip<ExternalSubnet> ipVersionColumn =
                new EnumColumn<ExternalSubnet, IpVersion>() {
            @Override
            protected IpVersion getRawValue(ExternalSubnet object) {
                return object.getIpVersion();
            }
        };
        getTable().addColumn(ipVersionColumn, constants.ipVersionExternalSubnet(), "100px"); //$NON-NLS-1$

        TextColumnWithTooltip<ExternalSubnet> externalIdColumn =
                new TextColumnWithTooltip<ExternalSubnet>() {
            @Override
            public String getValue(ExternalSubnet object) {
                return object.getId();
            }
        };

        getTable().addColumn(externalIdColumn, constants.externalIdExternalSubnet(), "300px"); //$NON-NLS-1$

        getTable().addActionButton(new WebAdminButtonDefinition<ExternalSubnet>(constants.newNetworkExternalSubnet()) {
            @Override
            protected UICommand resolveCommand() {
                return getDetailModel().getNewCommand();
            }
        });
        getTable().addActionButton(new WebAdminButtonDefinition<ExternalSubnet>(constants.removeNetworkExternalSubnet()) {
            @Override
            protected UICommand resolveCommand() {
                return getDetailModel().getRemoveCommand();
            }
        });
    }
}

@@ -66,82 +66,8 @@
 k;%0A%0A
-import org.ovirt.engine.core.common.businessentities.network.NetworkView;%0A
 impo
@@ -226,16 +226,90 @@
 ersion;%0A
+import org.ovirt.engine.core.common.businessentities.network.NetworkView;%0A
 import o
@@ -631,24 +631,38 @@
 orks.Network
+ExternalSubnet
 ListModel;%0Ai
@@ -722,39 +722,83 @@
 .Network
-ExternalSubnetListModel
+ListModel;%0Aimport org.ovirt.engine.ui.uicompat.external.StringUtils
 ;%0Aimport
@@ -2154,33 +2154,33 @@
 ernalSubnet(), %22
-3
+2
 00px%22); //$NON-N
@@ -2521,33 +2521,33 @@
 ernalSubnet(), %22
-2
+1
 00px%22); //$NON-N
@@ -2917,33 +2917,922 @@
 ernalSubnet(), %22
-1
+80px%22); //$NON-NLS-1$%0A%0A        TextColumnWithTooltip%3CExternalSubnet%3E gatewayColumn =%0A                new TextColumnWithTooltip%3CExternalSubnet%3E() %7B%0A                    @Override%0A                    public String getValue(ExternalSubnet object) %7B%0A                        return object.getGateway();%0A                    %7D%0A                %7D;%0A%0A        getTable().addColumn(gatewayColumn, constants.gatewayExternalSubnet(), %22100px%22); //$NON-NLS-1$%0A%0A        TextColumnWithTooltip%3CExternalSubnet%3E dnsServersColumn =%0A                new TextColumnWithTooltip%3CExternalSubnet%3E() %7B%0A                    @Override%0A                    public String getValue(ExternalSubnet object) %7B%0A                        return StringUtils.join(object.getDnsServers(), %22, %22); //$NON-NLS-1$%0A                    %7D%0A                %7D;%0A%0A        getTable().addColumn(dnsServersColumn, constants.dnsServersExternalSubnet(), %222
 00px%22); //$NON-N

Add gateway & DNS servers columns