Search in sources :

Example 21 with RepositoryTreeNode

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

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

the class AbstractBranchSelectionDialog method createDialogArea.

@Override
protected final Composite createDialogArea(Composite base) {
    Composite parent = (Composite) super.createDialogArea(base);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    int selectionModel = -1;
    if ((settings & ALLOW_MULTISELECTION) != 0)
        selectionModel = SWT.MULTI;
    else
        selectionModel = SWT.SINGLE;
    FilteredTree tree = new FilteredTree(composite, selectionModel | SWT.BORDER, new PatternFilter(), true);
    branchTree = tree.getViewer();
    branchTree.setUseHashlookup(true);
    branchTree.setLabelProvider(new RepositoriesViewStyledCellLabelProvider());
    branchTree.setContentProvider(new RepositoriesViewContentProvider());
    ColumnViewerToolTipSupport.enableFor(branchTree);
    GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
    branchTree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String refName = refNameFromDialog();
            refNameSelected(refName);
        }
    });
    // double-click support
    branchTree.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            RepositoryTreeNode node = (RepositoryTreeNode) ((IStructuredSelection) branchTree.getSelection()).getFirstElement();
            if (node == null)
                return;
            final RepositoryTreeNodeType type = node.getType();
            if (type != RepositoryTreeNodeType.REF && type != RepositoryTreeNodeType.TAG && type != RepositoryTreeNodeType.ADDITIONALREF)
                branchTree.setExpandedState(node, !branchTree.getExpandedState(node));
            else if (isOkButtonEnabled())
                buttonPressed(OK);
        }
    });
    branchTree.setComparator(new ViewerComparator(STRING_ASCENDING_COMPARATOR));
    createCustomArea(composite);
    setTitle(getTitle());
    setMessage(getMessageText());
    getShell().setText(getWindowTitle());
    applyDialogFont(composite);
    return composite;
}
Also used : RepositoryTreeNodeType(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNodeType) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) RepositoriesViewStyledCellLabelProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewStyledCellLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener)

Example 23 with RepositoryTreeNode

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

the class AbstractBranchSelectionDialog method refFromDialog.

/**
 * @return the selected {@link Ref} from the tree, may be null
 */
protected Ref refFromDialog() {
    IStructuredSelection sel = (IStructuredSelection) branchTree.getSelection();
    if (sel.size() != 1)
        return null;
    RepositoryTreeNode node = (RepositoryTreeNode) sel.getFirstElement();
    if (node.getType() == RepositoryTreeNodeType.REF || node.getType() == RepositoryTreeNodeType.TAG)
        return ((Ref) node.getObject());
    return null;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 24 with RepositoryTreeNode

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

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

the class GitAdapterFactory method getAdapter.

@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType.isAssignableFrom(IHistoryPageSource.class)) {
        return GitHistoryPageSource.INSTANCE;
    }
    if (IWorkbenchAdapter.class == adapterType) {
        // property page names for git repository tree nodes
        if (adaptableObject instanceof RepositoryTreeNode) {
            return getRepositoryTreeNodeWorkbenchAdapter((RepositoryTreeNode) adaptableObject);
        }
        if (gitModelWorkbenchAdapter == null) {
            gitModelWorkbenchAdapter = new GitModelWorkbenchAdapter();
        }
        return gitModelWorkbenchAdapter;
    }
    if (adaptableObject instanceof IHistoryView && IShowInSource.class == adapterType) {
        IHistoryView historyView = (IHistoryView) adaptableObject;
        IHistoryPage historyPage = historyView.getHistoryPage();
        if (historyPage instanceof GitHistoryPage) {
            return historyPage;
        }
    }
    if (adaptableObject instanceof IURIEditorInput && adapterType == Repository.class) {
        return getRepository((IURIEditorInput) adaptableObject);
    }
    if (adaptableObject instanceof IURIEditorInput && adapterType == File.class) {
        return getFile((IURIEditorInput) adaptableObject);
    }
    if (adaptableObject instanceof GitModelObject && adapterType == ResourceMapping.class) {
        return GitObjectMapping.create((GitModelObject) adaptableObject);
    }
    if (adaptableObject instanceof GitModelObject && adapterType == IResource.class) {
        GitModelObject obj = (GitModelObject) adaptableObject;
        if (obj instanceof GitModelBlob) {
            IResource res = ResourceUtil.getFileForLocation(obj.getLocation(), false);
            if (res == null) {
                // Deleted resource?
                res = getWorkspaceResourceFromGitPath(obj.getLocation());
            }
            return res;
        }
        if (obj instanceof GitModelTree) {
            IResource res = root.getContainerForLocation(obj.getLocation());
            if (res == null) {
                res = root.getFolder(obj.getLocation());
            }
            return res;
        }
    }
    if (adapterType == Repository.class) {
        ResourceMapping m = AdapterUtils.adapt(adaptableObject, ResourceMapping.class);
        if (m != null) {
            return SelectionUtils.getRepository(new StructuredSelection(m));
        }
    }
    return null;
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) GitModelTree(org.eclipse.egit.ui.internal.synchronize.model.GitModelTree) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject) IHistoryPage(org.eclipse.team.ui.history.IHistoryPage) Repository(org.eclipse.jgit.lib.Repository) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) GitModelWorkbenchAdapter(org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IShowInSource(org.eclipse.ui.part.IShowInSource) IHistoryView(org.eclipse.team.ui.history.IHistoryView) File(java.io.File) IResource(org.eclipse.core.resources.IResource) GitModelBlob(org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)

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