private void initLabels(ICompareInput input) { CompareConfiguration cc = getCompareConfiguration(); if (getLeftRevision() != null) { String leftLabel = getFileRevisionLabel(getLeftRevision()); cc.setLeftLabel(leftLabel); } else if (getResource(input) != null) { String label = NLS.bind( Messages.GitCompareFileRevisionEditorInput_workspace, new Object[] {input.getLeft().getName()}); cc.setLeftLabel(label); } if (getRightRevision() != null) { String rightLabel = getFileRevisionLabel(getRightRevision()); cc.setRightLabel(rightLabel); } }
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { CompareConfiguration cc = getCompareConfiguration(); cc.setRightEditable(false); cc.setLeftEditable(false); cc.setLeftLabel("original"); cc.setRightLabel("formatted Text"); return new DiffNode(left, right); }
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // make sure all resources belong to the same repository try (RevWalk rw = new RevWalk(repository)) { monitor.beginTask( UIText.GitCompareEditorInput_CompareResourcesTaskName, IProgressMonitor.UNKNOWN); for (IResource resource : resources) { RepositoryMapping map = RepositoryMapping.getMapping(resource.getProject()); if (map == null) { throw new InvocationTargetException( new IllegalStateException( UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge)); } if (repository != null && repository != map.getRepository()) throw new InvocationTargetException( new IllegalStateException( UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge)); String repoRelativePath = map.getRepoRelativePath(resource); filterPathStrings.add(repoRelativePath); DiffNode node = new DiffNode(Differencer.NO_CHANGE) { @Override public Image getImage() { return FOLDER_IMAGE; } }; diffRoots.put(new Path(map.getRepoRelativePath(resource)), node); repository = map.getRepository(); } if (repository == null) throw new InvocationTargetException( new IllegalStateException( UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge)); if (monitor.isCanceled()) throw new InterruptedException(); final RevCommit baseCommit; try { try { baseCommit = rw.parseCommit(repository.resolve(baseVersion)); } catch (IOException e) { throw new InvocationTargetException(e); } final RevCommit compareCommit; if (compareVersion == null) { compareCommit = null; } else { try { compareCommit = rw.parseCommit(repository.resolve(compareVersion)); } catch (IOException e) { throw new InvocationTargetException(e); } } if (monitor.isCanceled()) throw new InterruptedException(); // set the labels CompareConfiguration config = getCompareConfiguration(); config.setLeftLabel(compareVersion); config.setRightLabel(baseVersion); // set title and icon if (resources.length == 0) { Object[] titleParameters = new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repository), CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion) }; setTitle(NLS.bind(UIText.GitCompareEditorInput_EditorTitle, titleParameters)); } else if (resources.length == 1) { Object[] titleParameters = new Object[] { resources[0].getFullPath().makeRelative().toString(), CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion) }; setTitle( NLS.bind(UIText.GitCompareEditorInput_EditorTitleSingleResource, titleParameters)); } else { setTitle( NLS.bind( UIText.GitCompareEditorInput_EditorTitleMultipleResources, CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion))); } // build the nodes try { return buildDiffContainer(baseCommit, compareCommit, monitor); } catch (IOException e) { throw new InvocationTargetException(e); } } finally { monitor.done(); } } }