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];
}
}
Aggregations