use of org.eclipse.egit.ui.internal.dialogs.CompareTreeView in project egit by eclipse.
the class CompareVersionsInTreeHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = getSelection(event);
if (selection.size() == 2) {
Iterator<?> it = selection.iterator();
RevCommit commit1 = (RevCommit) it.next();
RevCommit commit2 = (RevCommit) it.next();
HistoryPageInput pageInput = getPage(event).getInputInternal();
Object input = pageInput.getSingleItem();
Repository repository = pageInput.getRepository();
IWorkbenchPage workBenchPage = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage();
// available in this case in the UI
if (input instanceof IFile) {
IFile resource = (IFile) input;
final RepositoryMapping map = RepositoryMapping.getMapping(resource);
if (map != null) {
final String gitPath = map.getRepoRelativePath(resource);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, map.getRepository(), workBenchPage);
}
} else if (input instanceof File) {
File fileInput = (File) input;
Repository repo = getRepository(event);
final String gitPath = getRepoRelativePath(repo, fileInput);
final String commit1Path = getRenamedPath(gitPath, commit1);
final String commit2Path = getRenamedPath(gitPath, commit2);
CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, repo, workBenchPage);
} else if (input instanceof IResource) {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
view.setInput(new IResource[] { (IResource) input }, commit1.getId().name(), commit2.getId().name());
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
} else if (input == null) {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
view.setInput(repository, commit1.getId().name(), commit2.getId().name());
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
}
return null;
}
use of org.eclipse.egit.ui.internal.dialogs.CompareTreeView in project egit by eclipse.
the class DefaultGitSynchronizer method openGitTreeCompare.
/**
* Open the git tree compare view.
*
* @param resources
* The resources to display
* @param leftRev
* The left revision
* @param rightRev
* The right revision
* @param includeLocal
* Whether the local version must be used, if <code>true</code>
* {@code leftRev} will be ignored
*/
protected void openGitTreeCompare(IResource[] resources, String leftRev, String rightRev, boolean includeLocal) {
Display display = PlatformUI.getWorkbench().getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
CompareTreeView view;
try {
view = (CompareTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CompareTreeView.ID);
if (includeLocal) {
view.setInput(resources, rightRev);
} else {
view.setInput(resources, leftRev, rightRev);
}
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
});
}
Aggregations