private void OnSave() {
    VmInterfaceModel model = (VmInterfaceModel) getWindow();
    VmNetworkInterface nic =
        model.getIsNew()
            ? new VmNetworkInterface()
            : (VmNetworkInterface) Cloner.clone((VmNetworkInterface) getSelectedItem());

    if (!model.Validate()) {
      return;
    }

    // Save changes.
    nic.setName((String) model.getName().getEntity());
    nic.setNetworkName(((network) model.getNetwork().getSelectedItem()).getname());
    if (model.getNicType().getSelectedItem() == null) {
      nic.setType(null);
    } else {
      nic.setType(((VmInterfaceType) model.getNicType().getSelectedItem()).getValue());
    }
    nic.setMacAddress(
        model.getMAC().getIsChangable()
            ? (model.getMAC().getEntity() == null
                ? null
                : ((String) (model.getMAC().getEntity())).toLowerCase())
            : model.getIsNew() ? "" : nic.getMacAddress());

    if (model.getIsNew()) {
      Frontend.RunMultipleAction(
          VdcActionType.AddVmTemplateInterface,
          new java.util.ArrayList<VdcActionParametersBase>(
              java.util.Arrays.asList(
                  new VdcActionParametersBase[] {
                    new AddVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), nic)
                  })),
          new IFrontendMultipleActionAsyncCallback() {
            @Override
            public void Executed(FrontendMultipleActionAsyncResult result) {

              Cancel();
            }
          },
          null);
    } else {
      Frontend.RunMultipleAction(
          VdcActionType.UpdateVmTemplateInterface,
          new java.util.ArrayList<VdcActionParametersBase>(
              java.util.Arrays.asList(
                  new VdcActionParametersBase[] {
                    new AddVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), nic)
                  })),
          new IFrontendMultipleActionAsyncCallback() {
            @Override
            public void Executed(FrontendMultipleActionAsyncResult result) {

              Cancel();
            }
          },
          null);
    }
  }
  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();
  }
  private void OnRemove() {
    ConfirmationModel model = (ConfirmationModel) getWindow();

    if (model.getProgress() != null) {
      return;
    }

    java.util.ArrayList<VdcActionParametersBase> list =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (Object item : getSelectedItems()) {
      VmNetworkInterface a = (VmNetworkInterface) item;
      list.add(
          new RemoveVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), a.getId()));
    }

    model.StartProgress(null);

    Frontend.RunMultipleAction(
        VdcActionType.RemoveVmTemplateInterface,
        list,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ConfirmationModel localModel = (ConfirmationModel) result.getState();
            localModel.StopProgress();
            Cancel();
          }
        },
        model);
  }
  public void SetAsDisplay() {
    network network = (network) getSelectedItem();

    Frontend.RunAction(
        VdcActionType.UpdateDisplayToVdsGroup,
        new DisplayNetworkToVdsGroupParameters(getEntity(), network, true));
  }
  @Override
  protected void AsyncSearch() {
    super.AsyncSearch();

    setAsyncResult(
        Frontend.RegisterQuery(
            VdcQueryType.GetTemplateInterfacesByTemplateId,
            new GetVmTemplateParameters(getEntityStronglyTyped().getId())));
    setItems(getAsyncResult().getData());
  }
  @Override
  protected void AsyncSearch() {
    super.AsyncSearch();

    setAsyncResult(
        Frontend.RegisterQuery(
            VdcQueryType.GetAllNetworksByClusterId,
            new VdsGroupQueryParamenters(getEntity().getID())));
    setItems(getAsyncResult().getData());
  }
  private void ChangePassword() {
    VdcReturnValueBase returnValue =
        Frontend.RunAction(
            VdcActionType.ChangeUserPassword,
            new ChangeUserPasswordParameters(
                (String) getUserName().getEntity(),
                (String) getPassword().getEntity(),
                (String) getNewPassword().getEntity(),
                (String) getDomain().getSelectedItem()));

    if (returnValue != null && returnValue.getSucceeded()) {
      // TODO:
    }
  }
  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});
  }
  @Override
  public void Login() {
    // Completely override the base class functionality.

    if (!Validate()) {
      return;
    }

    // Clear config cache on login (to make sure we don't use old config in a new session)
    DataProvider.ClearConfigCache();

    Frontend.RunAction(
        VdcActionType.LoginUser,
        new LoginUserParameters(
            (String) getUserName().getEntity(),
            (String) getPassword().getEntity(),
            (String) getDomain().getSelectedItem(),
            "",
            "",
            ""),
        new IFrontendActionAsyncCallback() {
          @Override
          public void Executed(FrontendActionAsyncResult result) {

            UserPortalLoginModel model = (UserPortalLoginModel) result.getState();
            VdcReturnValueBase returnValue = result.getReturnValue();
            boolean success = returnValue != null && returnValue.getSucceeded();
            if (success) {
              model.setLoggedUser((VdcUser) returnValue.getActionReturnValue());
              model.getLoggedInEvent().raise(this, EventArgs.Empty);
            } else {
              model.getPassword().setEntity("");
              if (returnValue != null) {
                model.setMessage(Linq.FirstOrDefault(returnValue.getCanDoActionMessages()));
              }
              model.getLoginFailedEvent().raise(this, EventArgs.Empty);
            }
          }
        },
        this);
  }
  @Override
  protected void SyncSearch() {
    if (getEntity() == null) {
      return;
    }

    super.SyncSearch();

    AsyncQuery _asyncQuery = new AsyncQuery();
    _asyncQuery.setModel(this);
    _asyncQuery.asyncCallback =
        new INewAsyncCallback() {
          public void OnSuccess(Object model, Object ReturnValue) {
            SearchableListModel searchableListModel = (SearchableListModel) model;
            searchableListModel.setItems(
                (java.util.ArrayList<network>)
                    ((VdcQueryReturnValue) ReturnValue).getReturnValue());
          }
        };

    VdsGroupQueryParamenters tempVar = new VdsGroupQueryParamenters(getEntity().getID());
    tempVar.setRefresh(getIsQueryFirstTime());
    Frontend.RunQuery(VdcQueryType.GetAllNetworksByClusterId, tempVar, _asyncQuery);
  }