Search in sources :

Example 6 with TagNode

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

the class RepositoriesView method createCommonViewer.

@Override
protected CommonViewer createCommonViewer(Composite aParent) {
    CommonViewer viewer = super.createCommonViewer(aParent);
    // handle the double-click event for tags and branches
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TreeSelection sel = (TreeSelection) event.getSelection();
            RepositoryTreeNode element = (RepositoryTreeNode) sel.getFirstElement();
            // Disable checkout for bare repositories
            if (element.getRepository().isBare()) {
                return;
            }
            if (element instanceof RefNode) {
                executeOpenCommandWithConfirmation(element, ((RefNode) element).getObject().getName());
            } else if (element instanceof TagNode) {
                executeOpenCommandWithConfirmation(element, ((TagNode) element).getObject().getName());
            }
        }
    });
    // handle open event for the working directory
    viewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            TreeSelection sel = (TreeSelection) event.getSelection();
            RepositoryTreeNode element = (RepositoryTreeNode) sel.getFirstElement();
            if (element instanceof FileNode || element instanceof StashedCommitNode)
                executeOpenCommand(element);
        }
    });
    // react on selection changes
    ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class);
    srv.addPostSelectionListener(selectionChangedListener);
    // react on changes in the configured repositories
    repositoryUtil.getPreferences().addPreferenceChangeListener(configurationListener);
    initRepositoriesAndListeners();
    activateContextService();
    emptyArea.setBackground(viewer.getControl().getBackground());
    if (!repositories.isEmpty())
        layout.topControl = viewer.getControl();
    else
        layout.topControl = emptyArea;
    return viewer;
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) IOpenListener(org.eclipse.jface.viewers.IOpenListener) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionService(org.eclipse.ui.ISelectionService) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) FileNode(org.eclipse.egit.ui.internal.repository.tree.FileNode) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 7 with TagNode

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

the class PushTagsPage method initiallySelectTags.

private void initiallySelectTags(Object[] tagNodes, CheckboxTreeViewer viewer) {
    List<TagNode> checkedTags = new ArrayList<>();
    for (Object node : tagNodes) {
        if (node instanceof TagNode) {
            TagNode tagNode = (TagNode) node;
            Ref ref = tagNode.getObject();
            if (tagRefNamesToSelect.contains(ref.getName()))
                checkedTags.add(tagNode);
        }
    }
    TagNode[] checkedTagsArray = checkedTags.toArray(new TagNode[checkedTags.size()]);
    viewer.setCheckedElements(checkedTagsArray);
    if (checkedTagsArray.length > 0) {
        // Reveal tags (just using reveal does not work on some platforms)
        viewer.setSelection(new StructuredSelection(checkedTagsArray), true);
        // Clear selection, we don't want to highlight the rows that much
        viewer.setSelection(StructuredSelection.EMPTY);
    }
    setSelectedTags(checkedTagsArray);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 8 with TagNode

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

the class AbstractBranchSelectionDialog method markRef.

/**
 * Set the selection to a {@link Ref} if possible
 *
 * @param refName
 *            the name of the {@link Ref}
 * @return <code>true</code> if the {@link Ref} with the given name was
 *         found
 */
protected boolean markRef(String refName) {
    // selects the entry specified by the name
    if (refName == null)
        return false;
    RepositoryTreeNode node;
    try {
        if (refName.startsWith(Constants.R_HEADS)) {
            Ref ref = repo.exactRef(refName);
            if (ref == null)
                return false;
            node = createRefNode(localBranches, repo, ref);
        } else if (refName.startsWith(Constants.R_REMOTES)) {
            Ref ref = repo.exactRef(refName);
            if (ref == null)
                return false;
            node = createRefNode(remoteBranches, repo, ref);
        } else if (Constants.HEAD.equals(refName)) {
            Ref ref = repo.exactRef(refName);
            if (ref == null)
                return false;
            node = new AdditionalRefNode(references, repo, ref);
        } else {
            String mappedRef = Activator.getDefault().getRepositoryUtil().mapCommitToRef(repo, refName, false);
            if (mappedRef != null && mappedRef.startsWith(Constants.R_REMOTES)) {
                Ref ref = repo.exactRef(mappedRef);
                if (ref == null)
                    return false;
                node = createRefNode(remoteBranches, repo, ref);
            } else if (mappedRef != null && mappedRef.startsWith(Constants.R_TAGS)) {
                Ref ref = repo.exactRef(mappedRef);
                if (ref == null)
                    return false;
                node = new TagNode(tags, repo, ref);
            } else
                return false;
        }
    } catch (IOException e) {
        return false;
    }
    branchTree.setSelection(new StructuredSelection(node), true);
    return true;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) IOException(java.io.IOException) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 9 with TagNode

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

the class GitHistoryPage method inputSet.

@Override
public boolean inputSet() {
    try {
        if (trace)
            GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());
        if (this.input != null)
            return true;
        Object o = super.getInput();
        if (o == null) {
            setErrorMessage(UIText.GitHistoryPage_NoInputMessage);
            return false;
        }
        boolean showHead = false;
        boolean showRef = false;
        boolean showTag = false;
        Repository repo = null;
        RevCommit selection = null;
        Ref ref = null;
        if (o instanceof IResource) {
            RepositoryMapping mapping = RepositoryMapping.getMapping((IResource) o);
            if (mapping != null) {
                repo = mapping.getRepository();
                input = new HistoryPageInput(repo, new IResource[] { (IResource) o });
                showHead = true;
            }
        } else if (o instanceof RepositoryTreeNode) {
            RepositoryTreeNode repoNode = (RepositoryTreeNode) o;
            repo = repoNode.getRepository();
            switch(repoNode.getType()) {
                case FILE:
                    File file = ((FileNode) repoNode).getObject();
                    input = new HistoryPageInput(repo, new File[] { file });
                    showHead = true;
                    break;
                case FOLDER:
                    File folder = ((FolderNode) repoNode).getObject();
                    input = new HistoryPageInput(repo, new File[] { folder });
                    showHead = true;
                    break;
                case REF:
                    input = new HistoryPageInput(repo);
                    ref = ((RefNode) repoNode).getObject();
                    showRef = true;
                    break;
                case ADDITIONALREF:
                    input = new HistoryPageInput(repo);
                    ref = ((AdditionalRefNode) repoNode).getObject();
                    showRef = true;
                    break;
                case TAG:
                    input = new HistoryPageInput(repo);
                    ref = ((TagNode) repoNode).getObject();
                    showTag = true;
                    break;
                default:
                    input = new HistoryPageInput(repo);
                    showHead = true;
                    break;
            }
        } else if (o instanceof HistoryPageInput) {
            input = (HistoryPageInput) o;
        } else {
            IResource resource = AdapterUtils.adaptToAnyResource(o);
            if (resource != null) {
                RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
                if (mapping != null) {
                    repo = mapping.getRepository();
                    input = new HistoryPageInput(repo, new IResource[] { resource });
                }
            }
        }
        if (repo == null) {
            repo = AdapterUtils.adapt(o, Repository.class);
            if (repo != null) {
                File file = AdapterUtils.adapt(o, File.class);
                if (file == null) {
                    input = new HistoryPageInput(repo);
                } else {
                    input = new HistoryPageInput(repo, new File[] { file });
                }
            }
        }
        selection = AdapterUtils.adapt(o, RevCommit.class);
        if (input == null) {
            // $NON-NLS-1$
            this.name = "";
            setErrorMessage(UIText.GitHistoryPage_NoInputMessage);
            return false;
        }
        final IResource[] inResources = input.getItems();
        final File[] inFiles = input.getFileList();
        this.name = calculateName(input);
        // disable the filters if we have a Repository as input
        boolean filtersActive = inResources != null || inFiles != null;
        actions.showAllRepoVersionsAction.setEnabled(filtersActive);
        actions.showAllProjectVersionsAction.setEnabled(filtersActive);
        // the repository itself has no notion of projects
        actions.showAllFolderVersionsAction.setEnabled(inResources != null);
        actions.showAllResourceVersionsAction.setEnabled(filtersActive);
        setErrorMessage(null);
        try {
            initAndStartRevWalk(false);
        } catch (IllegalStateException e) {
            Activator.handleError(e.getMessage(), e, true);
            return false;
        }
        if (showHead)
            showHead(repo);
        if (showRef)
            showRef(ref, repo);
        if (showTag)
            showTag(ref, repo);
        if (selection != null)
            graph.selectCommitStored(selection);
        return true;
    } finally {
        if (trace)
            GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());
    }
}
Also used : AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RevObject(org.eclipse.jgit.revwalk.RevObject) File(java.io.File) IResource(org.eclipse.core.resources.IResource) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 10 with TagNode

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

the class RepositoriesView method getShowInElements.

private static List<Object> getShowInElements(IStructuredSelection selection) {
    List<Object> elements = new ArrayList<>();
    for (Object element : selection.toList()) {
        if (element instanceof FileNode || element instanceof FolderNode || element instanceof WorkingDirNode) {
            RepositoryTreeNode treeNode = (RepositoryTreeNode) element;
            IPath path = treeNode.getPath();
            IResource resource = ResourceUtil.getResourceForLocation(path, false);
            if (resource != null)
                elements.add(resource);
        } else if (element instanceof RepositoryNode) {
            // Can be shown in History, Reflog and Properties views
            elements.add(element);
        } else if (element instanceof RepositoryNode || element instanceof RemoteNode || element instanceof FetchNode || element instanceof PushNode || element instanceof TagNode || element instanceof RefNode) {
            // These can be shown in Properties view directly
            elements.add(element);
        }
    }
    return elements;
}
Also used : FolderNode(org.eclipse.egit.ui.internal.repository.tree.FolderNode) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) RemoteNode(org.eclipse.egit.ui.internal.repository.tree.RemoteNode) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) PushNode(org.eclipse.egit.ui.internal.repository.tree.PushNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) FetchNode(org.eclipse.egit.ui.internal.repository.tree.FetchNode) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) WorkingDirNode(org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode) FileNode(org.eclipse.egit.ui.internal.repository.tree.FileNode) IResource(org.eclipse.core.resources.IResource) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Aggregations

TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)14 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)10 ArrayList (java.util.ArrayList)5 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)5 Ref (org.eclipse.jgit.lib.Ref)5 Repository (org.eclipse.jgit.lib.Repository)5 IOException (java.io.IOException)4 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 File (java.io.File)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 AdditionalRefNode (org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)2 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RevObject (org.eclipse.jgit.revwalk.RevObject)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2