Search in sources :

Example 1 with SubscriberMergeContext

use of org.eclipse.team.core.subscribers.SubscriberMergeContext 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

ITypedElement (org.eclipse.compare.ITypedElement)1 ResourceNode (org.eclipse.compare.ResourceNode)1 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 WorkspaceFileRevision (org.eclipse.egit.core.internal.storage.WorkspaceFileRevision)1 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)1 GitSubscriberMergeContext (org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)1 FileRevisionTypedElement (org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)1 TeamException (org.eclipse.team.core.TeamException)1 IFileRevision (org.eclipse.team.core.history.IFileRevision)1 ISynchronizationContext (org.eclipse.team.core.mapping.ISynchronizationContext)1 Subscriber (org.eclipse.team.core.subscribers.Subscriber)1 SubscriberMergeContext (org.eclipse.team.core.subscribers.SubscriberMergeContext)1 ResourceDiffCompareInput (org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput)1