private void onDisableHook() {
    if (getConfirmWindow() == null) {
      return;
    }

    ConfirmationModel model = (ConfirmationModel) getConfirmWindow();

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

    ArrayList<VdcActionParametersBase> list = new ArrayList<VdcActionParametersBase>();

    for (Object item : getSelectedItems()) {
      GlusterHookEntity hook = (GlusterHookEntity) item;
      list.add(new GlusterHookParameters(hook.getId()));
    }

    model.startProgress();

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

                ConfirmationModel localModel = (ConfirmationModel) result.getState();
                localModel.stopProgress();
                cancelConfirmation();
              }
            },
            model);
  }
  private void viewHook() {
    if (getWindow() != null) {
      return;
    }

    GlusterHookEntity hookEntity = getSelectedItem();

    if (hookEntity == null) {
      return;
    }

    GlusterHookContentModel contentModel = new GlusterHookContentModel();
    contentModel.setTitle(
        ConstantsManager.getInstance().getConstants().viewContentGlusterHookTitle());
    contentModel.setHelpTag(HelpTag.view_gluster_hook);
    contentModel.setHashName("view_gluster_hook"); // $NON-NLS-1$
    setWindow(contentModel);

    contentModel.startProgress();

    AsyncDataProvider.getInstance()
        .getGlusterHookContent(
            new AsyncQuery(
                contentModel,
                new INewAsyncCallback() {
                  @Override
                  public void onSuccess(Object model, Object returnValue) {
                    String content = (String) returnValue;
                    GlusterHookContentModel localModel = (GlusterHookContentModel) model;
                    localModel.getContent().setEntity(content);
                    if (content == null) {
                      localModel.getContent().setIsAvailable(false);
                      localModel.setMessage(
                          ConstantsManager.getInstance()
                              .getConstants()
                              .viewContentErrorGlusterHook());
                    } else if (content.length() == 0) {
                      localModel.getContent().setIsAvailable(false);
                      localModel.setMessage(
                          ConstantsManager.getInstance()
                              .getConstants()
                              .viewContentEmptyGlusterHook());
                    }
                    localModel.stopProgress();
                  }
                }),
            hookEntity.getId(),
            null);

    UICommand command = new UICommand("Cancel", this); // $NON-NLS-1$
    command.setTitle(ConstantsManager.getInstance().getConstants().close());
    command.setIsCancel(true);
    contentModel.getCommands().add(command);
  }
  private void enableHook() {
    if (getEntity() == null || getSelectedItems() == null || getSelectedItems().size() == 0) {
      return;
    }

    ArrayList<VdcActionParametersBase> list = new ArrayList<VdcActionParametersBase>();
    for (GlusterHookEntity hook : getSelectedItems()) {
      list.add(new GlusterHookParameters(hook.getId()));
    }
    Frontend.getInstance().runMultipleAction(VdcActionType.EnableGlusterHook, list, null, null);
  }
  private void onResolveConflicts() {

    final GlusterHookResolveConflictsModel resolveConflictsModel =
        (GlusterHookResolveConflictsModel) getWindow();

    if (resolveConflictsModel == null) {
      return;
    }

    if (!resolveConflictsModel.isAnyResolveActionSelected()) {
      resolveConflictsModel.setMessage(
          ConstantsManager.getInstance().getConstants().noResolveActionSelectedGlusterHook());
      return;
    }

    resolveConflictsModel.startProgress();

    GlusterHookEntity hookEntity = resolveConflictsModel.getGlusterHookEntity();

    ArrayList<VdcActionType> actionTypes = new ArrayList<VdcActionType>();
    ArrayList<VdcActionParametersBase> parameters = new ArrayList<VdcActionParametersBase>();
    ArrayList<IFrontendActionAsyncCallback> callbacks =
        new ArrayList<IFrontendActionAsyncCallback>();

    if (resolveConflictsModel.getResolveContentConflict().getEntity()) {
      actionTypes.add(VdcActionType.UpdateGlusterHook);
      GlusterServerHook serverHook = resolveConflictsModel.getServerHooksList().getSelectedItem();
      Guid serverId = (serverHook == null) ? null : serverHook.getServerId();
      parameters.add(new GlusterHookManageParameters(hookEntity.getId(), serverId));
      IFrontendActionAsyncCallback callback =
          new IFrontendActionAsyncCallback() {
            @Override
            public void executed(FrontendActionAsyncResult result) {
              if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveContentConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveContentConflict().setIsChangeable(Boolean.FALSE);
              }
            }
          };
      callbacks.add(callback);
    }

    if (resolveConflictsModel.getResolveStatusConflict().getEntity()) {
      boolean isEnable = resolveConflictsModel.getResolveStatusConflictEnable().getEntity();
      actionTypes.add(
          isEnable ? VdcActionType.EnableGlusterHook : VdcActionType.DisableGlusterHook);
      parameters.add(new GlusterHookParameters(hookEntity.getId()));
      IFrontendActionAsyncCallback callback =
          new IFrontendActionAsyncCallback() {
            @Override
            public void executed(FrontendActionAsyncResult result) {
              if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveStatusConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveStatusConflict().setIsChangeable(Boolean.FALSE);
              }
            }
          };
      callbacks.add(callback);
    }

    if (resolveConflictsModel.getResolveMissingConflict().getEntity()) {
      boolean isAdd = resolveConflictsModel.getResolveMissingConflictCopy().getEntity();
      actionTypes.add(isAdd ? VdcActionType.AddGlusterHook : VdcActionType.RemoveGlusterHook);
      parameters.add(new GlusterHookManageParameters(hookEntity.getId()));
      IFrontendActionAsyncCallback callback =
          new IFrontendActionAsyncCallback() {
            @Override
            public void executed(FrontendActionAsyncResult result) {
              if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveMissingConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveMissingConflict().setIsChangeable(Boolean.FALSE);
              }
            }
          };
      callbacks.add(callback);
    }

    IFrontendActionAsyncCallback onFinishCallback =
        new IFrontendActionAsyncCallback() {
          @Override
          public void executed(FrontendActionAsyncResult result) {
            if (result.getReturnValue().getSucceeded()) {
              resolveConflictsModel.stopProgress();
              cancel();
              syncSearch();
            }
          }
        };

    IFrontendActionAsyncCallback failureCallback =
        new IFrontendActionAsyncCallback() {
          @Override
          public void executed(FrontendActionAsyncResult result) {
            resolveConflictsModel.stopProgress();
          }
        };

    // Replacing the last callback with onFinishCallback, as we just want to close the dialog and
    // execute the search
    if (callbacks.size() > 0) {
      callbacks.remove(callbacks.size() - 1);
      callbacks.add(onFinishCallback);
      Frontend.getInstance()
          .runMultipleActions(actionTypes, parameters, callbacks, failureCallback, null);
    }
  }
  private void resolveConflicts() {
    if (getWindow() != null) {
      return;
    }

    final GlusterHookEntity hookEntity = getSelectedItem();

    if (hookEntity == null) {
      return;
    }

    GlusterHookResolveConflictsModel conflictsModel = new GlusterHookResolveConflictsModel();
    conflictsModel.setTitle(
        ConstantsManager.getInstance().getConstants().resolveConflictsGlusterHookTitle());
    conflictsModel.setHelpTag(HelpTag.gluster_hook_resolve_conflicts);
    conflictsModel.setHashName("gluster_hook_resolve_conflicts"); // $NON-NLS-1$
    hookEntity.setServerHooks(new ArrayList<GlusterServerHook>());
    conflictsModel.setGlusterHookEntity(hookEntity);
    setWindow(conflictsModel);
    conflictsModel.startProgress();

    AsyncDataProvider.getInstance()
        .getGlusterHook(
            new AsyncQuery(
                conflictsModel,
                new INewAsyncCallback() {
                  @Override
                  public void onSuccess(Object model, Object returnValue) {

                    GlusterHookResolveConflictsModel innerConflictsModel =
                        (GlusterHookResolveConflictsModel) model;
                    List<GlusterServerHook> serverHooks =
                        ((GlusterHookEntity) returnValue).getServerHooks();
                    hookEntity.setServerHooks(serverHooks);

                    ArrayList<EntityModel<GlusterServerHook>> serverHookModels =
                        new ArrayList<EntityModel<GlusterServerHook>>();
                    GlusterServerHook engineCopy = new GlusterServerHook();
                    engineCopy.setHookId(hookEntity.getId());
                    engineCopy.setServerName("Engine (Master)"); // $NON-NLS-1$
                    engineCopy.setStatus(hookEntity.getStatus());
                    engineCopy.setContentType(hookEntity.getContentType());
                    engineCopy.setChecksum(hookEntity.getChecksum());
                    EntityModel<GlusterServerHook> engineCopyModel =
                        new EntityModel<GlusterServerHook>(engineCopy);
                    serverHookModels.add(engineCopyModel);

                    for (GlusterServerHook serverHook : serverHooks) {
                      serverHookModels.add(new EntityModel<GlusterServerHook>(serverHook));
                    }

                    innerConflictsModel.getHookSources().setItems(serverHookModels);
                    innerConflictsModel.getHookSources().setSelectedItem(engineCopyModel);

                    ArrayList<GlusterServerHook> serverHooksWithEngine =
                        new ArrayList<GlusterServerHook>(serverHooks);
                    serverHooksWithEngine.add(0, engineCopy);
                    innerConflictsModel.getServerHooksList().setItems(serverHooksWithEngine);
                    innerConflictsModel.getServerHooksList().setSelectedItem(engineCopy);

                    innerConflictsModel.stopProgress();

                    UICommand command =
                        UICommand.createDefaultOkUiCommand(
                            "OnResolveConflicts", ClusterGlusterHookListModel.this); // $NON-NLS-1$
                    innerConflictsModel.getCommands().add(command);

                    command =
                        new UICommand("Cancel", ClusterGlusterHookListModel.this); // $NON-NLS-1$
                    command.setTitle(ConstantsManager.getInstance().getConstants().close());
                    command.setIsCancel(true);
                    innerConflictsModel.getCommands().add(command);
                  }
                }),
            hookEntity.getId(),
            true);
  }