Search in sources :

Example 36 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class RepositoriesViewCommandHandler method getSelectedFileAndFolderPaths.

protected Collection<IPath> getSelectedFileAndFolderPaths(ExecutionEvent event) throws ExecutionException {
    Collection<IPath> paths = new ArrayList<>();
    for (Object selectedNode : getSelectedNodes(event)) {
        RepositoryTreeNode treeNode = (RepositoryTreeNode) selectedNode;
        IPath path = treeNode.getPath();
        paths.add(path);
    }
    return paths;
}
Also used : IPath(org.eclipse.core.runtime.IPath) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ArrayList(java.util.ArrayList)

Example 37 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class CopyPathCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode node = getSelectedNodes(event).get(0);
    String path;
    switch(node.getType()) {
        case REPO:
            path = node.getRepository().getDirectory().toString();
            break;
        case WORKINGDIR:
            if (node.getRepository().isBare())
                return null;
            path = node.getRepository().getWorkTree().toString();
            break;
        case FILE:
            path = ((FileNode) node).getObject().getPath().toString();
            break;
        case FOLDER:
            path = ((FolderNode) node).getObject().getPath().toString();
            break;
        default:
            return null;
    }
    Clipboard clipboard = new Clipboard(null);
    try {
        TextTransfer textTransfer = TextTransfer.getInstance();
        Transfer[] transfers = new Transfer[] { textTransfer };
        Object[] data = new Object[] { path };
        clipboard.setContents(data, transfers);
    } finally {
        clipboard.dispose();
    }
    return null;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 38 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class CreateBranchCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final RepositoryTreeNode node = getSelectedNodes(event).get(0);
    if (node.getType() == RepositoryTreeNodeType.ADDITIONALREF) {
        Ref ref = (Ref) node.getObject();
        try (RevWalk rw = new RevWalk(node.getRepository())) {
            RevCommit baseCommit = rw.parseCommit(ref.getLeaf().getObjectId());
            WizardDialog dlg = new WizardDialog(getShell(event), new CreateBranchWizard(node.getRepository(), baseCommit.name()));
            dlg.setHelpAvailable(false);
            dlg.open();
        } catch (IOException e) {
            Activator.handleError(e.getMessage(), e, true);
        }
        return null;
    }
    String base = null;
    if (node.getObject() instanceof Ref)
        base = ((Ref) node.getObject()).getName();
    new WizardDialog(getShell(event), new CreateBranchWizard(node.getRepository(), base)).open();
    return null;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) WizardDialog(org.eclipse.jface.wizard.WizardDialog) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CreateBranchWizard(org.eclipse.egit.ui.internal.repository.CreateBranchWizard)

Example 39 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode 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)

Example 40 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class ConfigureFetchCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode selectedNode = getFirstOrNull(getSelectedNodes(event));
    final String configName;
    if (selectedNode instanceof RemoteNode)
        configName = ((RemoteNode) selectedNode).getObject();
    else if (selectedNode instanceof FetchNode)
        configName = ((RemoteNode) selectedNode.getParent()).getObject();
    else
        return null;
    Dialog dlg = SimpleConfigureFetchDialog.getDialog(getShell(event), selectedNode.getRepository(), configName);
    dlg.open();
    return null;
}
Also used : FetchNode(org.eclipse.egit.ui.internal.repository.tree.FetchNode) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) SimpleConfigureFetchDialog(org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog) Dialog(org.eclipse.jface.dialogs.Dialog) RemoteNode(org.eclipse.egit.ui.internal.repository.tree.RemoteNode)

Aggregations

RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)46 Repository (org.eclipse.jgit.lib.Repository)17 Ref (org.eclipse.jgit.lib.Ref)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 ArrayList (java.util.ArrayList)10 TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)10 IOException (java.io.IOException)9 File (java.io.File)8 IResource (org.eclipse.core.resources.IResource)7 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)6 IPath (org.eclipse.core.runtime.IPath)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RevObject (org.eclipse.jgit.revwalk.RevObject)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)3 Path (org.eclipse.core.runtime.Path)3 Job (org.eclipse.core.runtime.jobs.Job)3 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)3 RemoteNode (org.eclipse.egit.ui.internal.repository.tree.RemoteNode)3 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)3