Search in sources :

Example 1 with LockDialog

use of org.jetbrains.idea.svn.dialogs.LockDialog in project intellij-community by JetBrains.

the class SvnUtil method doLockFiles.

public static void doLockFiles(Project project, final SvnVcs activeVcs, @NotNull final File[] ioFiles) throws VcsException {
    final String lockMessage;
    final boolean force;
    // TODO[yole]: check for shift pressed
    if (activeVcs.getCheckoutOptions().getValue()) {
        LockDialog dialog = new LockDialog(project, true, ioFiles.length > 1);
        if (!dialog.showAndGet()) {
            return;
        }
        lockMessage = dialog.getComment();
        force = dialog.isForce();
    } else {
        lockMessage = "";
        force = false;
    }
    final VcsException[] exception = new VcsException[1];
    final Collection<String> failedLocks = new ArrayList<>();
    final int[] count = new int[] { ioFiles.length };
    final ProgressTracker eventHandler = new ProgressTracker() {

        public void consume(ProgressEvent event) {
            if (event.getAction() == EventAction.LOCK_FAILED) {
                failedLocks.add(event.getErrorMessage() != null ? event.getErrorMessage().getFullMessage() : event.getFile().getAbsolutePath());
                count[0]--;
            }
        }

        public void checkCancelled() {
        }
    };
    Runnable command = () -> {
        ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        try {
            if (progress != null) {
                progress.setText(SvnBundle.message("progress.text.locking.files"));
            }
            for (File ioFile : ioFiles) {
                if (progress != null) {
                    progress.checkCanceled();
                }
                if (progress != null) {
                    progress.setText2(SvnBundle.message("progress.text2.processing.file", ioFile.getName()));
                }
                activeVcs.getFactory(ioFile).createLockClient().lock(ioFile, force, lockMessage, eventHandler);
            }
        } catch (VcsException e) {
            exception[0] = e;
        }
    };
    ProgressManager.getInstance().runProcessWithProgressSynchronously(command, SvnBundle.message("progress.title.lock.files"), false, project);
    if (!failedLocks.isEmpty()) {
        String[] failedFiles = ArrayUtil.toStringArray(failedLocks);
        List<VcsException> exceptions = new ArrayList<>();
        for (String file : failedFiles) {
            exceptions.add(new VcsException(SvnBundle.message("exception.text.locking.file.failed", file)));
        }
        final StringBuilder sb = new StringBuilder(SvnBundle.message("message.text.files.lock.failed", failedFiles.length == 1 ? 0 : 1));
        for (VcsException vcsException : exceptions) {
            if (sb.length() > 0)
                sb.append('\n');
            sb.append(vcsException.getMessage());
        }
        //AbstractVcsHelper.getInstance(project).showErrors(exceptions, SvnBundle.message("message.title.lock.failures"));
        throw new VcsException(sb.toString());
    }
    StatusBarUtil.setStatusBarInfo(project, SvnBundle.message("message.text.files.locked", count[0]));
    if (exception[0] != null) {
        throw exception[0];
    }
}
Also used : ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) ArrayList(java.util.ArrayList) ProgressEvent(org.jetbrains.idea.svn.api.ProgressEvent) LockDialog(org.jetbrains.idea.svn.dialogs.LockDialog) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ProgressEvent (org.jetbrains.idea.svn.api.ProgressEvent)1 ProgressTracker (org.jetbrains.idea.svn.api.ProgressTracker)1 LockDialog (org.jetbrains.idea.svn.dialogs.LockDialog)1