use of org.eclipse.egit.ui.internal.dialogs.UnmergedBranchDialog in project egit by eclipse.
the class DeleteBranchOnCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Repository repository = getRepository(event);
if (repository == null)
return null;
IStructuredSelection selection = getSelection(event);
int totalBranchCount;
List<Ref> branchesOfCommit;
try {
totalBranchCount = getBranchesOfCommit(selection, repository, false).size();
branchesOfCommit = getBranchesOfCommit(selection, repository, true);
} catch (IOException e) {
throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
}
// this should have been checked by isEnabled()
if (branchesOfCommit.isEmpty())
return null;
final List<Ref> unmergedBranches = new ArrayList<>();
final Shell shell = getPart(event).getSite().getShell();
final List<Ref> branchesToDelete;
// tracking branch
if (totalBranchCount > 1) {
BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, branchesOfCommit, UIText.DeleteBranchOnCommitHandler_SelectBranchDialogTitle, UIText.DeleteBranchOnCommitHandler_SelectBranchDialogMessage, SWT.MULTI);
if (dlg.open() != Window.OK)
return null;
branchesToDelete = dlg.getSelectedNodes();
} else
branchesToDelete = branchesOfCommit;
try {
new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask(UIText.DeleteBranchCommand_DeletingBranchesProgress, branchesToDelete.size());
for (Ref refNode : branchesToDelete) {
int result = deleteBranch(repository, refNode, false);
if (result == DeleteBranchOperation.REJECTED_CURRENT) {
throw new CoreException(Activator.createErrorStatus(UIText.DeleteBranchCommand_CannotDeleteCheckedOutBranch, null));
} else if (result == DeleteBranchOperation.REJECTED_UNMERGED) {
unmergedBranches.add(refNode);
} else
monitor.worked(1);
}
} catch (CoreException ex) {
throw new InvocationTargetException(ex);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_BranchDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
if (!unmergedBranches.isEmpty()) {
MessageDialog messageDialog = new UnmergedBranchDialog<>(shell, unmergedBranches);
if (messageDialog.open() == Window.OK) {
try {
new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask(UIText.DeleteBranchCommand_DeletingBranchesProgress, unmergedBranches.size());
for (Ref node : unmergedBranches) {
deleteBranch(repository, node, true);
monitor.worked(1);
}
} catch (CoreException ex) {
throw new InvocationTargetException(ex);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_BranchDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
}
}
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.UnmergedBranchDialog in project egit by eclipse.
the class DeleteBranchCommand method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final List<RepositoryTreeNode> nodes = getSelectedNodes(event);
final Map<Ref, Repository> refs = getRefsToDelete(nodes);
final AtomicReference<Map<Ref, Repository>> unmergedNodesRef = new AtomicReference<>();
final Shell shell = getShell(event);
try {
new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Map<Ref, Repository> unmergedNodes = deleteBranches(refs, false, monitor);
unmergedNodesRef.set(unmergedNodes);
}
});
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_BranchDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
if (unmergedNodesRef.get().isEmpty())
return null;
MessageDialog messageDialog = new UnmergedBranchDialog<>(shell, new ArrayList<>(unmergedNodesRef.get().keySet()));
if (messageDialog.open() != Window.OK)
return null;
try {
new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
deleteBranches(unmergedNodesRef.get(), true, monitor);
}
});
} catch (InvocationTargetException e1) {
Activator.handleError(UIText.RepositoriesView_BranchDeletionFailureMessage, e1.getCause(), true);
} catch (InterruptedException e1) {
// ignore
}
return null;
}
Aggregations