Search in sources :

Example 1 with CompareTreeView

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) HistoryPageInput(org.eclipse.egit.ui.internal.history.HistoryPageInput) CompareTreeView(org.eclipse.egit.ui.internal.dialogs.CompareTreeView) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with CompareTreeView

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);
            }
        }
    });
}
Also used : CompareTreeView(org.eclipse.egit.ui.internal.dialogs.CompareTreeView) PartInitException(org.eclipse.ui.PartInitException) Display(org.eclipse.swt.widgets.Display)

Aggregations

CompareTreeView (org.eclipse.egit.ui.internal.dialogs.CompareTreeView)2 PartInitException (org.eclipse.ui.PartInitException)2 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 HistoryPageInput (org.eclipse.egit.ui.internal.history.HistoryPageInput)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 Display (org.eclipse.swt.widgets.Display)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1