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 "";
}
}
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();
}
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;
}
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();
}
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);
}
Aggregations