public void PostGetClusterNetworkList_New(java.util.ArrayList<network> network_list) {
    java.util.ArrayList<network> networks = new java.util.ArrayList<network>();
    for (network a : network_list) {
      if (a.getStatus() == NetworkStatus.Operational) {
        networks.add(a);
      }
    }

    java.util.ArrayList<VmNetworkInterface> nics = Linq.<VmNetworkInterface>Cast(getItems());
    int nicCount = nics.size();
    String newNicName = DataProvider.GetNewNicName(nics);

    VmInterfaceModel model = (VmInterfaceModel) getWindow();
    model.getNetwork().setItems(networks);
    model.getNetwork().setSelectedItem(networks.size() > 0 ? networks.get(0) : null);
    model
        .getNicType()
        .setItems(DataProvider.GetNicTypeList(getEntityStronglyTyped().getos(), false));
    model
        .getNicType()
        .setSelectedItem(DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos()));
    model.getName().setEntity(newNicName);
    model.getMAC().setIsAvailable(false);

    UICommand tempVar = new UICommand("OnSave", this);
    tempVar.setTitle("OK");
    tempVar.setIsDefault(true);
    model.getCommands().add(tempVar);
    UICommand tempVar2 = new UICommand("Cancel", this);
    tempVar2.setTitle("Cancel");
    tempVar2.setIsCancel(true);
    model.getCommands().add(tempVar2);
  }
  private void UpdateActionAvailability() {
    network network = (network) getSelectedItem();

    // CanRemove = SelectedItems != null && SelectedItems.Count > 0;
    getSetAsDisplayCommand()
        .setIsExecutionAllowed(
            getSelectedItems() != null
                && getSelectedItems().size() == 1
                && network != null
                && !(network.getis_display() == null ? false : network.getis_display())
                && network.getStatus() != NetworkStatus.NonOperational);
  }
  public void OnManage() {
    ListModel model = (ListModel) getWindow();

    java.util.ArrayList<EntityModel> items = Linq.<EntityModel>Cast(model.getItems());
    java.util.ArrayList<network> networks = Linq.<network>Cast(getItems());

    if (getEntity() == null) {
      Cancel();
      return;
    }

    java.util.ArrayList<VdcActionParametersBase> prms1 =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (EntityModel a : items) {
      boolean value = false;
      for (network b : networks) {
        if (b.getId().equals(((network) a.getEntity()).getId())) {
          value = true;
          break;
        }
      }
      if (a.getIsSelected() && !value) {
        prms1.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity()));
      }
    }

    // Call the command only if necessary (i.e. only if there are paramters):
    if (prms1.size() > 0) {
      Frontend.RunMultipleAction(VdcActionType.AttachNetworkToVdsGroup, prms1);
    }

    java.util.ArrayList<VdcActionParametersBase> prms2 =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (EntityModel a : items) {
      boolean value = true;
      for (network b : networks) {
        if (b.getId().equals(((network) a.getEntity()).getId())) {
          value = false;
          break;
        }
      }
      if (!a.getIsSelected() && !value) {
        prms2.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity()));
      }
    }

    // Call the command only if necessary (i.e. only if there are paramters):
    if (prms2.size() > 0) {
      Frontend.RunMultipleAction(VdcActionType.DetachNetworkToVdsGroup, prms2);
    }

    Cancel();
  }
  public void PostGetClusterNetworkList_Edit(java.util.ArrayList<network> network_list) {
    VmNetworkInterface nic = (VmNetworkInterface) getSelectedItem();
    int nicCount = Linq.<VmNetworkInterface>Cast(getItems()).size();
    java.util.ArrayList<network> networks = new java.util.ArrayList<network>();
    for (network a : network_list) {
      if (a.getStatus() == NetworkStatus.Operational) {
        networks.add(a);
      }
    }

    VmInterfaceModel model = (VmInterfaceModel) getWindow();
    model.getNetwork().setItems(networks);
    network network = null;
    for (network a : networks) {
      if (StringHelper.stringsEqual(a.getname(), nic.getNetworkName())) {
        network = a;
        break;
      }
    }
    model.getNetwork().setSelectedItem(network);

    Integer selectedNicType = nic.getType();
    java.util.ArrayList<VmInterfaceType> nicTypes =
        DataProvider.GetNicTypeList(
            getEntityStronglyTyped().getos(),
            VmInterfaceType.forValue(selectedNicType) == VmInterfaceType.rtl8139_pv);
    model.getNicType().setItems(nicTypes);

    if (selectedNicType == null || !nicTypes.contains(VmInterfaceType.forValue(selectedNicType))) {
      selectedNicType = DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos()).getValue();
    }

    model.getNicType().setSelectedItem(VmInterfaceType.forValue(selectedNicType));

    model.getName().setEntity(nic.getName());
    model.getMAC().setIsAvailable(false);

    UICommand tempVar = new UICommand("OnSave", this);
    tempVar.setTitle("OK");
    tempVar.setIsDefault(true);
    model.getCommands().add(tempVar);
    UICommand tempVar2 = new UICommand("Cancel", this);
    tempVar2.setTitle("Cancel");
    tempVar2.setIsCancel(true);
    model.getCommands().add(tempVar2);
  }
  public void OnSave() {
    ClusterNetworkModel model = (ClusterNetworkModel) getWindow();
    network network = new network(null);

    if (getEntity() == null) {
      Cancel();
      return;
    }

    if (!model.Validate() || getEntity().getstorage_pool_id() == null) {
      return;
    }

    network.setstorage_pool_id(getEntity().getstorage_pool_id());
    network.setname((String) model.getName().getEntity());
    network.setstp((Boolean) model.getIsStpEnabled().getEntity());
    network.setdescription((String) model.getDescription().getEntity());
    network.setvlan_id(null);
    if ((Boolean) model.getHasVLanTag().getEntity()) {
      network.setvlan_id(Integer.parseInt(model.getVLanTag().getEntity().toString()));
    }

    Frontend.RunAction(
        VdcActionType.AddNetwork,
        new AddNetworkStoragePoolParameters(network.getstorage_pool_id().getValue(), network),
        new IFrontendActionAsyncCallback() {
          @Override
          public void Executed(FrontendActionAsyncResult result) {

            Object[] data = (Object[]) result.getState();
            ClusterNetworkListModel networkListModel = (ClusterNetworkListModel) data[0];
            VdcReturnValueBase retVal = result.getReturnValue();
            if (retVal != null && retVal.getSucceeded()) {
              network tempVar = new network(null);
              tempVar.setId((Guid) retVal.getActionReturnValue());
              tempVar.setname(((network) data[1]).getname());
              Frontend.RunAction(
                  VdcActionType.AttachNetworkToVdsGroup,
                  new AttachNetworkToVdsGroupParameter(networkListModel.getEntity(), tempVar));
            }
            networkListModel.Cancel();
          }
        },
        new Object[] {this, network});
  }
  public void PostManage(java.util.ArrayList<network> networkList, ListModel model) {
    Collections.sort(networkList, new Linq.NetworkByNameComparer());

    java.util.ArrayList<EntityModel> items = new java.util.ArrayList<EntityModel>();
    for (network a : networkList) {
      if (!a.getname().equals("engine")) {
        EntityModel tempVar = new EntityModel();
        tempVar.setEntity(a);
        tempVar.setTitle(a.getname());
        items.add(tempVar);
      }
    }
    model.setItems(items);

    boolean noItems = items.isEmpty();

    java.util.ArrayList<network> networks = Linq.<network>Cast(getItems());
    java.util.ArrayList<EntityModel> selectedItems = new java.util.ArrayList<EntityModel>();
    for (EntityModel item : items) {
      network net = (network) item.getEntity();
      boolean value = false;
      for (network a : networks) {
        if (a.getId().equals(net.getId())) {
          value = true;
          break;
        }
      }
      item.setIsSelected(value);
      if (value) {
        selectedItems.add(item);
      }
    }

    model.setSelectedItems(selectedItems);

    UICommand tempVar2 = new UICommand("Cancel", this);
    tempVar2.setTitle("Cancel");
    tempVar2.setIsDefault(noItems);
    tempVar2.setIsCancel(true);
    model.getCommands().add(tempVar2);

    if (!noItems) {
      UICommand tempVar3 = new UICommand("OnManage", this);
      tempVar3.setTitle("OK");
      tempVar3.setIsDefault(true);
      model.getCommands().add(0, tempVar3);
    }
  }