Search in sources :

Example 6 with FileRevisionTypedElement

use of org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement in project egit by eclipse.

the class GitModelSynchronizeParticipant method asCompareInput.

@Override
public ICompareInput asCompareInput(Object object) {
    final ICompareInput input = super.asCompareInput(object);
    final ISynchronizationContext ctx = getContext();
    if (input instanceof ResourceDiffCompareInput && ctx instanceof SubscriberMergeContext) {
        // Team only considers local resources as "left"
        // We'll use the cached data instead as left could be remote
        final IResource resource = ((ResourceNode) input.getLeft()).getResource();
        final Subscriber subscriber = ((SubscriberMergeContext) ctx).getSubscriber();
        if (resource instanceof IFile && subscriber instanceof GitResourceVariantTreeSubscriber) {
            try {
                final IFileRevision revision = ((GitResourceVariantTreeSubscriber) subscriber).getSourceFileRevision((IFile) resource);
                if (revision == null) {
                    final ITypedElement newSource = new GitCompareFileRevisionEditorInput.EmptyTypedElement(resource.getName());
                    ((ResourceDiffCompareInput) input).setLeft(newSource);
                } else if (!(revision instanceof WorkspaceFileRevision)) {
                    final ITypedElement newSource = new FileRevisionTypedElement(revision, getLocalEncoding(resource));
                    ((ResourceDiffCompareInput) input).setLeft(newSource);
                }
            } catch (TeamException e) {
                // Keep the input from super as-is
                String error = NLS.bind(UIText.GitModelSynchronizeParticipant_noCachedSourceVariant, resource.getName());
                Activator.logError(error, e);
            }
        }
    }
    return input;
}
Also used : IFile(org.eclipse.core.resources.IFile) ISynchronizationContext(org.eclipse.team.core.mapping.ISynchronizationContext) IFileRevision(org.eclipse.team.core.history.IFileRevision) ITypedElement(org.eclipse.compare.ITypedElement) WorkspaceFileRevision(org.eclipse.egit.core.internal.storage.WorkspaceFileRevision) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) ResourceDiffCompareInput(org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput) ResourceNode(org.eclipse.compare.ResourceNode) TeamException(org.eclipse.team.core.TeamException) Subscriber(org.eclipse.team.core.subscribers.Subscriber) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) SubscriberMergeContext(org.eclipse.team.core.subscribers.SubscriberMergeContext) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) FileRevisionTypedElement(org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement) IResource(org.eclipse.core.resources.IResource)

Aggregations

FileRevisionTypedElement (org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)6 ITypedElement (org.eclipse.compare.ITypedElement)5 IFileRevision (org.eclipse.team.core.history.IFileRevision)5 IFile (org.eclipse.core.resources.IFile)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)2 IDiffContainer (org.eclipse.compare.structuremergeviewer.IDiffContainer)2 CoreException (org.eclipse.core.runtime.CoreException)2 GitFileRevision (org.eclipse.egit.core.internal.storage.GitFileRevision)2 WorkingTreeFileRevision (org.eclipse.egit.core.internal.storage.WorkingTreeFileRevision)2 WorkspaceFileRevision (org.eclipse.egit.core.internal.storage.WorkspaceFileRevision)2 GitCompareFileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput)2 EmptyTypedElement (org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput.EmptyTypedElement)2 DirCacheIterator (org.eclipse.jgit.dircache.DirCacheIterator)2 AbstractTreeIterator (org.eclipse.jgit.treewalk.AbstractTreeIterator)2 FileTreeIterator (org.eclipse.jgit.treewalk.FileTreeIterator)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2 OrTreeFilter (org.eclipse.jgit.treewalk.filter.OrTreeFilter)2 TreeFilter (org.eclipse.jgit.treewalk.filter.TreeFilter)2