Search in sources :

Example 1 with ITypedElement

use of org.eclipse.compare.ITypedElement in project erlide_eclipse by erlang.

the class ErlStructureCreator method createStructureComparator.

@Override
protected IStructureComparator createStructureComparator(final Object element, final IDocument document0, final ISharedDocumentAdapter sharedDocumentAdapter, final IProgressMonitor monitor) throws CoreException {
    IErlModule module = null;
    final IErlModel model = ErlangEngine.getInstance().getModel();
    String s = "";
    IDocument document = document0;
    if (element instanceof ResourceNode) {
        final ResourceNode rn = (ResourceNode) element;
        final IResource r = rn.getResource();
        if (r instanceof IFile) {
            final IFile f = (IFile) r;
            final IErlElement e = model.findElement(r);
            if (e instanceof IErlModule) {
                module = (IErlModule) e;
            }
            if (document == null) {
                try {
                    s = ErlStructureCreator.readString(f.getContents());
                    document = new Document(s);
                } catch (final CoreException e1) {
                }
            }
        }
    } else if (document == null && element instanceof IStreamContentAccessor) {
        try {
            try (final InputStream contents = ((IStreamContentAccessor) element).getContents()) {
                s = ErlStructureCreator.readString(contents);
            } catch (final IOException e) {
            }
            document = new Document(s);
        } catch (final CoreException ex) {
        }
    } else if (document != null) {
        s = document.get();
    }
    if (module == null) {
        String name = "comptemp";
        if (element instanceof ITypedElement) {
            final ITypedElement typedElement = (ITypedElement) element;
            name = typedElement.getName();
        }
        module = model.getModuleFromText(model, name, s, null);
    }
    ErlNode root = null;
    if (element != null && document != null) {
        try {
            module.open(null);
            root = new RootErlNode(document, element);
            recursiveMakeErlNodes(module, root, document);
        } catch (final ErlModelException e) {
            ErlLogger.warn(e);
        }
    }
    return root;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) InputStream(java.io.InputStream) ITypedElement(org.eclipse.compare.ITypedElement) IOException(java.io.IOException) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ResourceNode(org.eclipse.compare.ResourceNode) IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource)

Example 2 with ITypedElement

use of org.eclipse.compare.ITypedElement in project tmdm-studio-se by Talend.

the class ResourceCompareInput method createDiffViewer.

@Override
public Viewer createDiffViewer(Composite parent) {
    fDiffViewer = new DiffTreeViewer(parent, getCompareConfiguration()) {

        @Override
        protected void fillContextMenu(IMenuManager manager) {
            if (fOpenAction == null) {
                fOpenAction = new Action() {

                    @Override
                    public void run() {
                        handleOpen(null);
                    }
                };
                // $NON-NLS-1$
                Utilities.initAction(fOpenAction, getBundle(), "action.CompareContents.");
            }
            boolean enable = false;
            ISelection selection = getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) selection;
                if (ss.size() == 1) {
                    Object element = ss.getFirstElement();
                    if (element instanceof MyDiffNode) {
                        ITypedElement te = ((MyDiffNode) element).getId();
                        if (te != null) {
                            enable = !ITypedElement.FOLDER_TYPE.equals(te.getType());
                        }
                    } else {
                        enable = true;
                    }
                }
            }
            fOpenAction.setEnabled(enable);
            manager.add(fOpenAction);
            super.fillContextMenu(manager);
        }
    };
    fDiffViewer.getControl();
    return fDiffViewer;
}
Also used : DiffTreeViewer(org.eclipse.compare.structuremergeviewer.DiffTreeViewer) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ISelection(org.eclipse.jface.viewers.ISelection) ITypedElement(org.eclipse.compare.ITypedElement) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with ITypedElement

use of org.eclipse.compare.ITypedElement in project tmdm-studio-se by Talend.

the class ResourceCompareInput method commit.

/*
     * Recursively walks the diff tree and commits all changes.
     */
private void commit(IProgressMonitor pm, DiffNode node) throws CoreException {
    if (node instanceof MyDiffNode) {
        ((MyDiffNode) node).clearDirty();
    }
    ITypedElement left = node.getLeft();
    if (left instanceof BufferedResourceNode) {
        ((BufferedResourceNode) left).commit(pm);
    }
    ITypedElement right = node.getRight();
    if (right instanceof BufferedResourceNode) {
        ((BufferedResourceNode) right).commit(pm);
    }
    IDiffElement[] children = node.getChildren();
    if (children != null) {
        for (IDiffElement element : children) {
            if (element instanceof DiffNode) {
                commit(pm, (DiffNode) element);
            }
        }
    }
    if (this.compareHeadInfo != null) {
        commitToDB();
    }
}
Also used : IDiffElement(org.eclipse.compare.structuremergeviewer.IDiffElement) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) ITypedElement(org.eclipse.compare.ITypedElement)

Example 4 with ITypedElement

use of org.eclipse.compare.ITypedElement in project liferay-ide by liferay.

the class AbstractCompareFileHandler method _openCompareEditor.

private IStatus _openCompareEditor(IFile currentFile) {
    ITypedElement left = null;
    ITypedElement right = null;
    IStatus retval = Status.OK_STATUS;
    try {
        File tempFile = getTemplateFile(currentFile);
        if (tempFile == null) {
            return ProjectCore.createErrorStatus("Can't find the original file.");
        }
        left = new CompareItem(tempFile);
        right = new CompareItem(currentFile.getLocation().toFile());
        _openInCompare(left, right);
    } catch (Exception e) {
        retval = ProjectCore.createErrorStatus(e);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ITypedElement(org.eclipse.compare.ITypedElement) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ITypedElement

use of org.eclipse.compare.ITypedElement in project egit by eclipse.

the class CompareUtils method compareLocalWithRef.

/**
 * Opens a compare editor comparing the working directory version of the
 * file at the given location with the version corresponding to
 * {@code refName} of the same file.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param location
 *            Location of the file to compare revisions for.
 * @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.
 */
private static void compareLocalWithRef(@NonNull final Repository repository, @NonNull final IPath location, final String refName, final IWorkbenchPage page) {
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final String gitPath = getRepoRelativePath(location, repository);
            final ITypedElement base = new LocalNonWorkspaceTypedElement(repository, location);
            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) 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

ITypedElement (org.eclipse.compare.ITypedElement)29 IFile (org.eclipse.core.resources.IFile)14 IOException (java.io.IOException)10 GitCompareFileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput)10 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)8 CoreException (org.eclipse.core.runtime.CoreException)6 IFileRevision (org.eclipse.team.core.history.IFileRevision)6 CompareEditorInput (org.eclipse.compare.CompareEditorInput)5 FileRevisionTypedElement (org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 File (java.io.File)4 IResource (org.eclipse.core.resources.IResource)4 IPath (org.eclipse.core.runtime.IPath)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 ExecutionException (org.eclipse.core.commands.ExecutionException)3 Job (org.eclipse.core.runtime.jobs.Job)3