コード例 #1
0
  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);
    }
  }
コード例 #2
0
  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();
  }
コード例 #3
0
  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);
  }
コード例 #4
0
  public void OnSelectHost() {
    MoveHost model = (MoveHost) getWindow();

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

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

    model.setSelectedHosts(new java.util.ArrayList<VDS>());
    for (EntityModel a : Linq.<EntityModel>Cast(model.getItems())) {
      if (a.getIsSelected()) {
        model.getSelectedHosts().add((VDS) a.getEntity());
      }
    }

    VDSGroup cluster = (VDSGroup) model.getCluster().getSelectedItem();

    java.util.ArrayList<VdcActionParametersBase> paramerterList =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (VDS host : model.getSelectedHosts()) {
      // Try to change host's cluster as neccessary.
      if (host.getvds_group_id() != null && !host.getvds_group_id().equals(cluster.getId())) {
        paramerterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
      }
    }
    model.StartProgress(null);
    Frontend.RunMultipleAction(
        VdcActionType.ChangeVDSCluster,
        paramerterList,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ClusterGuideModel clusterGuideModel = (ClusterGuideModel) result.getState();
            java.util.ArrayList<VDS> hosts =
                ((MoveHost) clusterGuideModel.getWindow()).getSelectedHosts();
            java.util.ArrayList<VdcReturnValueBase> retVals =
                (java.util.ArrayList<VdcReturnValueBase>) result.getReturnValue();
            if (retVals != null && hosts.size() == retVals.size()) {
              int i = 0;
              for (VDS selectedHost : hosts) {
                if (selectedHost.getstatus() == VDSStatus.PendingApproval
                    && retVals.get(i) != null
                    && retVals.get(i).getSucceeded()) {
                  Frontend.RunAction(
                      VdcActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()));
                }
              }
              i++;
            }
            clusterGuideModel.getWindow().StopProgress();
            clusterGuideModel.Cancel();
            clusterGuideModel.PostAction();
          }
        },
        this);
  }