public void actionPerformed()

in src/org/jetbrains/tfsIntegration/actions/LockAction.java [51:120]


  public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final VirtualFile[] files = VcsUtil.getVirtualFiles(e);

    final List<LockItemModel> items = new ArrayList<>();
    final List<VcsException> exceptions = new ArrayList<>();
    final Ref<Boolean> mappingFound = new Ref<>(false);

    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
      try {
        ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
        WorkstationHelper
          .processByWorkspaces(TfsFileUtil.getFilePaths(files), false, project, new WorkstationHelper.VoidProcessDelegate() {
            @Override
            public void executeRequest(final WorkspaceInfo workspace, final List<ItemPath> paths) throws TfsException {
              mappingFound.set(true);
              final Map<FilePath, ExtendedItem> itemsMap =
                workspace.getExtendedItems2(paths, project, TFSBundle.message("loading.items"));
              for (ExtendedItem item : itemsMap.values()) {
                if (item != null) {
                  items.add(new LockItemModel(item, workspace));
                }
              }
            }
          });
      }
      catch (TfsException e1) {
        exceptions.add(new VcsException(e1));
      }
    }, "Reading existing locks...", false, project);

    if (!exceptions.isEmpty()) {
      AbstractVcsHelper.getInstance(project).showErrors(exceptions, TFSVcs.TFS_NAME);
      return;
    }
    if (!mappingFound.get()) {
      Messages.showInfoMessage(project, "Team Foundation Server mappings not found.", e.getPresentation().getText());
      return;
    }

    if (items.isEmpty()) {
      Messages.showInfoMessage(project, "Server item not found.", e.getPresentation().getText());
      return;
    }

    performInitialSelection(items);

    final LockItemsDialog d = new LockItemsDialog(project, items);
    d.show();
    int exitCode = d.getExitCode();
    if (exitCode != LockItemsDialog.LOCK_EXIT_CODE && exitCode != LockItemsDialog.UNLOCK_EXIT_CODE) {
      return;
    }

    final List<LockItemModel> selectedItems = d.getSelectedItems();
    String title = d.getLockLevel() == LockLevel.None ? "Unlocking..." : "Locking...";
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
      ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
      exceptions.addAll(lockOrUnlockItems(selectedItems, d.getLockLevel(), project));
    }, title, false, project);

    if (exceptions.isEmpty()) {
      String message = MessageFormat.format("{0} {1} {2}", selectedItems.size(), selectedItems.size() == 1 ? "item" : "items",
                                            exitCode == LockItemsDialog.LOCK_EXIT_CODE ? "locked" : "unlocked");
      TfsUtil.showBalloon(project, MessageType.INFO, message);
    }
    else {
      AbstractVcsHelper.getInstance(project).showErrors(exceptions, TFSVcs.TFS_NAME);
    }
  }