Search in sources :

Example 1 with UnmergedBranchDialog

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;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) UnmergedBranchDialog(org.eclipse.egit.ui.internal.dialogs.UnmergedBranchDialog) BranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with UnmergedBranchDialog

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;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Ref(org.eclipse.jgit.lib.Ref) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) UnmergedBranchDialog(org.eclipse.egit.ui.internal.dialogs.UnmergedBranchDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 UnmergedBranchDialog (org.eclipse.egit.ui.internal.dialogs.UnmergedBranchDialog)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 Ref (org.eclipse.jgit.lib.Ref)2 Repository (org.eclipse.jgit.lib.Repository)2 Shell (org.eclipse.swt.widgets.Shell)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 BranchSelectionDialog (org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1