Search in sources :

Example 21 with ITypedElement

use of org.eclipse.compare.ITypedElement in project linuxtools by eclipse.

the class ChangeLogAction method getDocumentLocation.

protected String getDocumentLocation(IEditorPart currentEditor, boolean appendRoot) {
    IFile loc = getDocumentIFile(currentEditor);
    IEditorInput cc = null;
    String WorkspaceRoot;
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    WorkspaceRoot = myWorkspaceRoot.getLocation().toOSString();
    if (currentEditor instanceof MultiPageEditorPart) {
        Object ed = ((MultiPageEditorPart) currentEditor).getSelectedPage();
        if (ed instanceof IEditorPart)
            cc = ((IEditorPart) ed).getEditorInput();
        if (cc instanceof FileEditorInput)
            return (appendRoot) ? WorkspaceRoot + ((FileEditorInput) cc).getFile().getFullPath().toOSString() : ((FileEditorInput) cc).getFile().getFullPath().toOSString();
    }
    cc = currentEditor.getEditorInput();
    if (cc == null)
        return "";
    if ((cc instanceof SyncInfoCompareInput) || (cc instanceof CompareEditorInput)) {
        CompareEditorInput test = (CompareEditorInput) cc;
        if (test.getCompareResult() == null) {
            return "";
        } else if (test.getCompareResult() instanceof ICompareInput) {
            ITypedElement leftCompare = ((ICompareInput) test.getCompareResult()).getLeft();
            if (leftCompare instanceof IResourceProvider) {
                String localPath = ((IResourceProvider) leftCompare).getResource().getFullPath().toString();
                if (appendRoot) {
                    return WorkspaceRoot + localPath;
                }
                return localPath;
            }
        } else {
            if (appendRoot)
                return WorkspaceRoot + test.getCompareResult().toString();
            return test.getCompareResult().toString();
        }
    } else if (cc instanceof FileStoreEditorInput) {
        return ((FileStoreEditorInput) cc).getName();
    }
    if (appendRoot) {
        return WorkspaceRoot + loc.getFullPath().toOSString();
    } else if (loc != null) {
        return loc.getFullPath().toOSString();
    } else {
        return "";
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) ITypedElement(org.eclipse.compare.ITypedElement) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) IEditorPart(org.eclipse.ui.IEditorPart) IResourceProvider(org.eclipse.compare.IResourceProvider) CompareEditorInput(org.eclipse.compare.CompareEditorInput) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SyncInfoCompareInput(org.eclipse.team.ui.synchronize.SyncInfoCompareInput) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 22 with ITypedElement

use of org.eclipse.compare.ITypedElement in project egit by eclipse.

the class CompareUtils method compareBetween.

/**
 * Compares two explicit files specified by leftGitPath and rightGitPath
 * between the two revisions leftRev and rightRev.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param leftGitPath
 *            The repository relative path to be used for the left revision.
 * @param rightGitPath
 *            The repository relative path to be used for the right
 *            revision.
 * @param leftRev
 *            Left revision of the comparison (usually the local or "new"
 *            revision). Won't be used if <code>includeLocal</code> is
 *            <code>true</code>.
 * @param rightRev
 *            Right revision of the comparison (usually the "old" revision).
 * @param page
 *            If not {@null} try to re-use a compare editor on this
 *            page if any is available. Otherwise open a new one.
 */
public static void compareBetween(final Repository repository, final String leftGitPath, final String rightGitPath, final String leftRev, final String rightRev, final IWorkbenchPage page) {
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final ITypedElement left;
            final ITypedElement right;
            try {
                left = getTypedElementFor(repository, leftGitPath, leftRev);
                right = getTypedElementFor(repository, rightGitPath, rightRev);
            } catch (IOException e) {
                return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
            }
            final ITypedElement commonAncestor;
            if (left != null && right != null && !GitFileRevision.INDEX.equals(leftRev) && !GitFileRevision.INDEX.equals(rightRev)) {
                commonAncestor = getTypedElementForCommonAncestor(repository, rightGitPath, leftRev, rightRev);
            } else {
                commonAncestor = null;
            }
            final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, commonAncestor, null);
            in.getCompareConfiguration().setLeftLabel(leftRev);
            in.getCompareConfiguration().setRightLabel(rightRev);
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            openCompareEditorRunnable(page, in);
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GitCompareFileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Example 23 with ITypedElement

use of org.eclipse.compare.ITypedElement in project egit by eclipse.

the class CompareUtils method getTypedElementForCommonAncestor.

private static ITypedElement getTypedElementForCommonAncestor(Repository repository, final String gitPath, String srcRev, String dstRev) {
    ITypedElement ancestor = null;
    try {
        final ObjectId srcID = repository.resolve(srcRev);
        final ObjectId dstID = repository.resolve(dstRev);
        if (srcID != null && dstID != null)
            ancestor = getFileRevisionTypedElementForCommonAncestor(gitPath, srcID, dstID, repository);
    } catch (IOException e) {
        Activator.logError(NLS.bind(UIText.CompareUtils_errorCommonAncestor, srcRev, dstRev), e);
    }
    return ancestor;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ITypedElement(org.eclipse.compare.ITypedElement) IOException(java.io.IOException)

Example 24 with ITypedElement

use of org.eclipse.compare.ITypedElement in project egit by eclipse.

the class CompareUtils method compareWorkspaceWithRef.

/**
 * Opens a compare editor comparing the working directory version of the
 * given file or link with the version of that file corresponding to
 * {@code refName}.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param file
 *            Resource to compare revisions for. Must be either
 *            {@link IFile} or a symbolic link to directory ({@link IFolder}).
 * @param refName
 *            Reference to compare with the workspace version of
 *            {@code file}. Can be either a commit ID, a reference or a
 *            branch name.
 * @param page
 *            If not {@null} try to re-use a compare editor on this page if
 *            any is available. Otherwise open a new one.
 */
public static void compareWorkspaceWithRef(@NonNull final Repository repository, final IResource file, final String refName, final IWorkbenchPage page) {
    if (file == null) {
        return;
    }
    final IPath location = file.getLocation();
    if (location == null) {
        return;
    }
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final RepositoryMapping mapping = RepositoryMapping.getMapping(file);
            if (mapping == null) {
                return Activator.createErrorStatus(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, location, repository));
            }
            final ITypedElement base;
            if (Files.isSymbolicLink(location.toFile().toPath())) {
                base = new LocalNonWorkspaceTypedElement(repository, location);
            } else if (file instanceof IFile) {
                base = SaveableCompareEditorInput.createFileElement((IFile) file);
            } else {
                return Activator.createErrorStatus(NLS.bind(UIText.CompareUtils_wrongResourceArgument, location, file));
            }
            final String gitPath = mapping.getRepoRelativePath(file);
            CompareEditorInput in;
            try {
                in = prepareCompareInput(repository, gitPath, base, refName);
            } catch (IOException e) {
                return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            openCompareEditorRunnable(page, in);
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Example 25 with ITypedElement

use of org.eclipse.compare.ITypedElement in project egit by eclipse.

the class CompareUtils method openInCompare.

/**
 * Compares two files between the given commits, taking possible renames
 * into account.
 *
 * @param commit1
 *            the "left" commit for the comparison editor
 * @param commit2
 *            the "right" commit for the comparison editor
 * @param commit1Path
 *            path to the file within commit1's tree
 * @param commit2Path
 *            path to the file within commit2's tree
 * @param repository
 *            the repository this commit was loaded out of
 * @param workBenchPage
 *            the page to open the compare editor in
 */
public static void openInCompare(RevCommit commit1, RevCommit commit2, String commit1Path, String commit2Path, Repository repository, IWorkbenchPage workBenchPage) {
    final ITypedElement base = CompareUtils.getFileRevisionTypedElement(commit1Path, commit1, repository);
    final ITypedElement next = CompareUtils.getFileRevisionTypedElement(commit2Path, commit2, repository);
    CompareEditorInput in = new GitCompareFileRevisionEditorInput(base, next, null);
    CompareUtils.openInCompare(workBenchPage, in);
}
Also used : CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) GitCompareFileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput) ITypedElement(org.eclipse.compare.ITypedElement)

Aggregations

ITypedElement (org.eclipse.compare.ITypedElement)41 IFile (org.eclipse.core.resources.IFile)16 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)14 IOException (java.io.IOException)11 GitCompareFileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput)10 CoreException (org.eclipse.core.runtime.CoreException)9 File (java.io.File)6 CompareEditorInput (org.eclipse.compare.CompareEditorInput)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IFileRevision (org.eclipse.team.core.history.IFileRevision)6 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)5 IDiffElement (org.eclipse.compare.structuremergeviewer.IDiffElement)5 IResource (org.eclipse.core.resources.IResource)5 FileRevisionTypedElement (org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 ArrayList (java.util.ArrayList)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 CompareConfiguration (org.eclipse.compare.CompareConfiguration)3