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 onAttach() {
    AdElementListModel model = (AdElementListModel) getWindow();

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

    if (model.getSelectedItems() == null) {
      cancel();
      return;
    }

    ArrayList<DbUser> items = new ArrayList<DbUser>();
    for (Object item : model.getItems()) {
      EntityModel entityModel = (EntityModel) item;
      if (entityModel.getIsSelected()) {
        items.add((DbUser) entityModel.getEntity());
      }
    }

    Role role = model.getRole().getSelectedItem();

    ArrayList<VdcActionParametersBase> list = new ArrayList<VdcActionParametersBase>();
    for (DbUser user : items) {
      Permission perm = new Permission(user.getId(), role.getId(), null, null);

      if (user.isGroup()) {
        DbGroup group = new DbGroup();
        group.setId(user.getId());
        group.setName(user.getFirstName());
        group.setDomain(user.getDomain());
        group.setExternalId(user.getExternalId());
        group.setNamespace(user.getNamespace());
        PermissionsOperationsParameters tempVar2 = new PermissionsOperationsParameters();
        tempVar2.setPermission(perm);
        tempVar2.setGroup(group);
        list.add(tempVar2);
      } else {
        PermissionsOperationsParameters tempVar3 = new PermissionsOperationsParameters();
        tempVar3.setPermission(perm);
        tempVar3.setUser(user);
        list.add(tempVar3);
      }
    }

    model.startProgress(null);

    Frontend.getInstance()
        .runMultipleAction(
            VdcActionType.AddSystemPermission,
            list,
            new IFrontendMultipleActionAsyncCallback() {
              @Override
              public void executed(FrontendMultipleActionAsyncResult result) {

                AdElementListModel localModel = (AdElementListModel) result.getState();
                localModel.stopProgress();
                cancel();
              }
            },
            model);
  }
  public void onAdd() {
    AdElementListModel model = (AdElementListModel) getWindow();

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

    if (model.getSelectedItems() == null) {
      cancel();
      return;
    }

    ArrayList<DbUser> items = new ArrayList<DbUser>();
    for (Object item : model.getItems()) {
      EntityModel entityModel = (EntityModel) item;
      if (entityModel.getIsSelected()) {
        items.add((DbUser) entityModel.getEntity());
      }
    }

    ArrayList<VdcActionType> actionsList = new ArrayList<VdcActionType>(items.size());
    ArrayList<VdcActionParametersBase> parametersList =
        new ArrayList<VdcActionParametersBase>(items.size());
    VdcActionParametersBase parameters = null;
    for (DbUser item : items) {
      if (item.isGroup()) {
        actionsList.add(VdcActionType.AddGroup);
        DbGroup grp = new DbGroup();
        grp.setExternalId(item.getExternalId());
        grp.setName(item.getFirstName());
        grp.setNamespace(item.getNamespace());
        grp.setId(item.getId());
        grp.setDomain(item.getDomain());
        grp.setActive(item.isActive());
        parameters = new AddGroupParameters(grp);
      } else {
        actionsList.add(VdcActionType.AddUser);
        parameters = new AddUserParameters(item);
      }
      parametersList.add(parameters);
    }

    model.startProgress(null);

    IFrontendActionAsyncCallback nopCallback =
        new IFrontendActionAsyncCallback() {
          @Override
          public void executed(FrontendActionAsyncResult result) {
            // Nothing.
          }
        };

    IFrontendActionAsyncCallback lastCallback =
        new IFrontendActionAsyncCallback() {
          @Override
          public void executed(FrontendActionAsyncResult result) {
            AdElementListModel localModel = (AdElementListModel) result.getState();
            localModel.stopProgress();
            cancel();
          }
        };

    ArrayList<IFrontendActionAsyncCallback> callbacksList =
        new ArrayList<IFrontendActionAsyncCallback>(items.size());
    for (int i = 1; i < items.size(); i++) {
      callbacksList.add(nopCallback);
    }
    callbacksList.add(lastCallback);

    Frontend.getInstance()
        .runMultipleActions(actionsList, parametersList, callbacksList, lastCallback, model);
  }
  private void onAdd() {
    AdElementListModel model = (AdElementListModel) getWindow();

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

    if (!model.getIsEveryoneSelected() && model.getSelectedItems() == null) {
      cancel();
      return;
    }

    ArrayList<DbUser> items = new ArrayList<DbUser>();
    if (model.getIsEveryoneSelected()) {
      DbUser tempVar = new DbUser();
      tempVar.setId(ApplicationGuids.everyone.asGuid());
      items.add(tempVar);
    } else {
      for (Object item : model.getItems()) {
        EntityModel entityModel = (EntityModel) item;
        if (entityModel.getIsSelected()) {
          items.add((DbUser) entityModel.getEntity());
        }
      }
    }

    Role role = (Role) model.getRole().getSelectedItem();
    // adGroup/user

    ArrayList<VdcActionParametersBase> list = new ArrayList<VdcActionParametersBase>();
    for (DbUser user : items) {
      Permissions tempVar2 = new Permissions();
      tempVar2.setad_element_id(user.getId());
      tempVar2.setrole_id(role.getId());
      Permissions perm = tempVar2;
      perm.setObjectId(getEntityGuid());
      perm.setObjectType(this.getObjectType());

      if (user.isGroup()) {
        DbGroup group = new DbGroup();
        group.setId(user.getId());
        group.setExternalId(user.getExternalId());
        group.setName(user.getFirstName());
        group.setDomain(user.getDomain());
        group.setNamespace(user.getNamespace());
        PermissionsOperationsParameters tempVar3 = new PermissionsOperationsParameters();
        tempVar3.setPermission(perm);
        tempVar3.setGroup(group);
        list.add(tempVar3);
      } else {
        PermissionsOperationsParameters tempVar4 = new PermissionsOperationsParameters();
        tempVar4.setPermission(perm);
        tempVar4.setUser(user);
        list.add(tempVar4);
      }
    }

    model.startProgress(null);

    Frontend.getInstance()
        .runMultipleAction(
            VdcActionType.AddPermission,
            list,
            new IFrontendMultipleActionAsyncCallback() {
              @Override
              public void executed(FrontendMultipleActionAsyncResult result) {

                AdElementListModel localModel = (AdElementListModel) result.getState();
                localModel.stopProgress();
                cancel();
              }
            },
            model);
  }