use of org.eclipse.compare.CompareEditorInput in project liferay-ide by liferay.
the class AbstractCompareFileHandler method _openInCompare.
private void _openInCompare(final ITypedElement left, final ITypedElement right) {
final CompareConfiguration configuration = new CompareConfiguration();
configuration.setLeftLabel("Template");
configuration.setRightLabel(((CompareItem) right).getFile().getAbsolutePath());
CompareUI.openCompareEditor(new CompareEditorInput(configuration) {
@Override
protected Object prepareInput(final IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
DiffNode diffNode = new DiffNode(left, right);
return diffNode;
}
});
}
use of org.eclipse.compare.CompareEditorInput in project liferay-ide by liferay.
the class LiferayUpgradeCompare method openCompareEditor.
public void openCompareEditor() {
try {
final ITypedElement left = new CompareItem(getSourceFile(), _fileName);
final ITypedElement right = new CompareItem(getTargetFile(), _fileName + "_preview");
final CompareConfiguration configuration = new CompareConfiguration();
configuration.setLeftLabel("Original File");
configuration.setRightLabel("Upgraded File");
CompareEditorInput editorInput = new CompareEditorInput(configuration) {
@Override
protected Object prepareInput(final IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
DiffNode diffNode = new DiffNode(left, right);
return diffNode;
}
};
StringBuilder titleBuilder = new StringBuilder("Compare ('");
titleBuilder.append(_fileName);
titleBuilder.append("'-'");
titleBuilder.append(_fileName);
titleBuilder.append("_preview");
titleBuilder.append("')");
editorInput.setTitle(titleBuilder.toString());
CompareUI.openCompareEditor(editorInput);
} catch (Exception e) {
ProjectUI.logError(e);
}
}
use of org.eclipse.compare.CompareEditorInput in project liferay-ide by liferay.
the class CustomJspPage method compare.
public void compare(final String originalFilePath, final String changedFilePath, final String leftLabel, final String rightLabel) {
CompareConfiguration config = new CompareConfiguration();
config.setLeftEditable(false);
config.setLeftLabel(leftLabel);
config.setRightEditable(false);
config.setRightLabel(rightLabel);
CompareEditorInput editorInput = new CompareEditorInput(config) {
@Override
public void saveChanges(IProgressMonitor pm) throws CoreException {
super.saveChanges(pm);
_changedItem.writeFile();
}
@Override
protected Object prepareInput(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
return new DiffNode(_originalItem, _changedItem);
}
private CompareItem _changedItem = new CompareItem(changedFilePath);
private CompareItem _originalItem = new CompareItem(originalFilePath);
};
editorInput.setTitle("Compare ('" + originalFilePath + "'-'" + changedFilePath + "')");
CompareUI.openCompareEditor(editorInput);
}
use of org.eclipse.compare.CompareEditorInput in project tdq-studio-se by Talend.
the class ExampleLauncher method compare.
public static void compare() {
// Load the two input models
ResourceSet resourceSet1 = new ResourceSetImpl();
ResourceSet resourceSet2 = new ResourceSetImpl();
// String xmi1 = "path/to/first/model.xmi";
// String xmi2 = "path/to/second/model.xmi";
load(fileName1, resourceSet1);
load(fileName2, resourceSet2);
// Configure EMF Compare
IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);
IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
IMatchEngine.Factory matchEngineFactory = new MatchEngineFactoryImpl(matcher, comparisonFactory);
matchEngineFactory.setRanking(20);
IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
matchEngineRegistry.add(matchEngineFactory);
EMFCompare comparator = EMFCompare.builder().setMatchEngineFactoryRegistry(matchEngineRegistry).build();
// Compare the two models
IComparisonScope scope = new DefaultComparisonScope(resourceSet1, resourceSet2, null);
Comparison compare = comparator.compare(scope);
comparator.compare(scope);
EList<Diff> differences = compare.getDifferences();
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(scope.getLeft(), scope.getRight(), null);
AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
EMFCompareConfiguration configuration = new EMFCompareConfiguration(new CompareConfiguration());
CompareEditorInput input = new ComparisonScopeEditorInput(configuration, editingDomain, adapterFactory, comparator, scope);
// CompareUI.openCompareDialog(input); // or CompareUI.openCompareEditor(input);
CompareUI.openCompareEditor(input);
}
use of org.eclipse.compare.CompareEditorInput 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();
}
Aggregations