Search in sources :

Example 6 with CompareEditorInput

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;
        }
    });
}
Also used : CompareEditorInput(org.eclipse.compare.CompareEditorInput) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareConfiguration(org.eclipse.compare.CompareConfiguration) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with CompareEditorInput

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);
    }
}
Also used : CompareEditorInput(org.eclipse.compare.CompareEditorInput) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareConfiguration(org.eclipse.compare.CompareConfiguration) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) ITypedElement(org.eclipse.compare.ITypedElement) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with CompareEditorInput

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);
}
Also used : CompareEditorInput(org.eclipse.compare.CompareEditorInput) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareConfiguration(org.eclipse.compare.CompareConfiguration) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode)

Example 9 with CompareEditorInput

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);
}
Also used : MatchEngineFactoryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryImpl) Diff(org.eclipse.emf.compare.Diff) CompareConfiguration(org.eclipse.compare.CompareConfiguration) EMFCompareConfiguration(org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) MatchEngineFactoryRegistryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryRegistryImpl) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) Comparison(org.eclipse.emf.compare.Comparison) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ICompareEditingDomain(org.eclipse.emf.compare.domain.ICompareEditingDomain) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EMFCompareConfiguration(org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration) ComparisonScopeEditorInput(org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeEditorInput) CompareEditorInput(org.eclipse.compare.CompareEditorInput) EMFCompare(org.eclipse.emf.compare.EMFCompare) IEObjectMatcher(org.eclipse.emf.compare.match.eobject.IEObjectMatcher) IMatchEngine(org.eclipse.emf.compare.match.IMatchEngine)

Example 10 with CompareEditorInput

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

CompareEditorInput (org.eclipse.compare.CompareEditorInput)12 CompareConfiguration (org.eclipse.compare.CompareConfiguration)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ITypedElement (org.eclipse.compare.ITypedElement)5 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)4 IPath (org.eclipse.core.runtime.IPath)3 GitCompareEditorInput (org.eclipse.egit.ui.internal.merge.GitCompareEditorInput)3 SaveableCompareEditorInput (org.eclipse.team.ui.synchronize.SaveableCompareEditorInput)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 Job (org.eclipse.core.runtime.jobs.Job)2 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)2 GitMergeEditorInput (org.eclipse.egit.ui.internal.merge.GitMergeEditorInput)2 MergeModeDialog (org.eclipse.egit.ui.internal.merge.MergeModeDialog)2 LocalNonWorkspaceTypedElement (org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement)2 ArrayList (java.util.ArrayList)1 IResourceProvider (org.eclipse.compare.IResourceProvider)1 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)1