Search in sources :

Example 1 with BranchSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.

the class RenameBranchOnCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(event);
    if (repository == null)
        return null;
    List<Ref> branchesOfCommit = getBranchesOfCommit(getSelection(event));
    // this should have been checked by isEnabled()
    if (branchesOfCommit.isEmpty())
        return null;
    final Shell shell = getPart(event).getSite().getShell();
    final Ref branchToRename;
    if (branchesOfCommit.size() > 1) {
        BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, branchesOfCommit, UIText.RenameBranchOnCommitHandler_SelectBranchDialogTitle, UIText.RenameBranchOnCommitHandler_SelectBranchDialogMessage, SWT.SINGLE);
        if (dlg.open() != Window.OK)
            return null;
        branchToRename = dlg.getSelectedNode();
    } else
        branchToRename = branchesOfCommit.get(0);
    new BranchRenameDialog(shell, repository, branchToRename).open();
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) Shell(org.eclipse.swt.widgets.Shell) BranchRenameDialog(org.eclipse.egit.ui.internal.dialogs.BranchRenameDialog) BranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog)

Example 2 with BranchSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.

the class DeleteTagOnCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(event);
    if (repository == null)
        return null;
    final Shell shell = getPart(event).getSite().getShell();
    IStructuredSelection selection = getSelection(event);
    List<Ref> tags = getTagsOfCommit(selection);
    // this should have been checked by isEnabled()
    if (tags.isEmpty())
        return null;
    // show a dialog in case there are multiple tags on the selected commit
    final List<Ref> tagsToDelete;
    if (tags.size() > 1) {
        BranchSelectionDialog<Ref> dialog = new BranchSelectionDialog<>(shell, tags, UIText.DeleteTagOnCommitHandler_SelectTagDialogTitle, UIText.DeleteTagOnCommitHandler_SelectTagDialogMessage, SWT.MULTI);
        if (dialog.open() != Window.OK)
            return null;
        tagsToDelete = dialog.getSelectedNodes();
    } else {
        String tagName = Repository.shortenRefName(tags.get(0).getName());
        String message = MessageFormat.format(UIText.DeleteTagCommand_messageConfirmSingleTag, tagName);
        boolean confirmed = MessageDialog.openConfirm(shell, UIText.DeleteTagCommand_titleConfirm, message);
        if (!confirmed)
            return null;
        tagsToDelete = tags;
    }
    try {
        deleteTagsAsTask(shell, repository, tagsToDelete);
    } catch (InvocationTargetException e1) {
        Activator.handleError(UIText.RepositoriesView_TagDeletionFailureMessage, e1.getCause(), true);
    } catch (InterruptedException e1) {
    // ignore
    }
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) Ref(org.eclipse.jgit.lib.Ref) BranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with BranchSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.

the class MergeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ObjectId commitId = getSelectedCommitId(event);
    Repository repository = getRepository(event);
    if (repository == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShellChecked(event);
    if (!MergeActionHandler.checkMergeIsPossible(repository, shell) || LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
        return null;
    }
    List<Ref> nodes;
    try {
        nodes = getBranchesOfCommit(getSelection(event), repository, true);
    } catch (IOException e) {
        throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
    }
    String refName;
    if (nodes.isEmpty()) {
        refName = commitId.getName();
    } else if (nodes.size() == 1) {
        refName = nodes.get(0).getName();
    } else {
        BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(shell, nodes, UIText.MergeHandler_SelectBranchTitle, UIText.MergeHandler_SelectBranchMessage, SWT.SINGLE);
        if (dlg.open() == Window.OK) {
            refName = dlg.getSelectedNode().getName();
        } else {
            return null;
        }
    }
    MergeOperation op = new MergeOperation(repository, refName);
    MergeActionHandler.doMerge(repository, op, refName);
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) Ref(org.eclipse.jgit.lib.Ref) MergeOperation(org.eclipse.egit.core.op.MergeOperation) ObjectId(org.eclipse.jgit.lib.ObjectId) BranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with BranchSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog 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 5 with BranchSelectionDialog

use of org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog in project egit by eclipse.

the class CheckoutCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ObjectId commitId = getSelectedCommitId(event);
    Repository repo = getRepository(event);
    final BranchOperationUI op;
    List<Ref> nodes;
    try {
        nodes = getBranchesOfCommit(getSelection(event), repo, true);
    } catch (IOException e) {
        throw new ExecutionException(UIText.AbstractHistoryCommitHandler_cantGetBranches, e);
    }
    if (nodes.isEmpty()) {
        op = BranchOperationUI.checkout(repo, commitId.name());
    } else if (nodes.size() == 1) {
        op = BranchOperationUI.checkout(repo, nodes.get(0).getName());
    } else {
        BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<>(HandlerUtil.getActiveShellChecked(event), nodes, UIText.CheckoutHandler_SelectBranchTitle, UIText.CheckoutHandler_SelectBranchMessage, SWT.SINGLE);
        if (dlg.open() == Window.OK) {
            op = BranchOperationUI.checkout(repo, dlg.getSelectedNode().getName());
        } else {
            op = null;
        }
    }
    if (op == null)
        return null;
    op.start();
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) BranchOperationUI(org.eclipse.egit.ui.internal.branch.BranchOperationUI) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) BranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

BranchSelectionDialog (org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog)5 Ref (org.eclipse.jgit.lib.Ref)5 Repository (org.eclipse.jgit.lib.Repository)5 Shell (org.eclipse.swt.widgets.Shell)4 IOException (java.io.IOException)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 MergeOperation (org.eclipse.egit.core.op.MergeOperation)1 BranchOperationUI (org.eclipse.egit.ui.internal.branch.BranchOperationUI)1 BranchRenameDialog (org.eclipse.egit.ui.internal.dialogs.BranchRenameDialog)1 UnmergedBranchDialog (org.eclipse.egit.ui.internal.dialogs.UnmergedBranchDialog)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1