Search in sources :

Example 26 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.

the class CParserTest method tearDown.

@After
public void tearDown() throws Exception {
    // content to the empty string).
    if (cppSourceEditorPart != null) {
        AbstractTextEditor castEditor = (AbstractTextEditor) cppSourceEditorPart;
        IDocumentProvider iDocProvider = castEditor.getDocumentProvider();
        IDocument changelogContentDoc = iDocProvider.getDocument(castEditor.getEditorInput());
        changelogContentDoc.set("");
        cppSourceEditorPart.doSave(null);
        // Also close open editor in order for default content to work.
        // I.e. avoid spill over from previous test runs
        closeEditor(cppSourceEditorPart);
    }
    // dispose
    project.getTestProject().delete(true, true, null);
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IDocument(org.eclipse.jface.text.IDocument) After(org.junit.After)

Example 27 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.

the class EditorHelper method getContent.

/**
 * Return the content of the given IEditorPart as String.
 * @param editorPart
 * @return Content of editorPart.
 */
public static String getContent(IEditorPart editorPart) {
    AbstractTextEditor castEditor = (AbstractTextEditor) editorPart;
    IDocumentProvider provider = castEditor.getDocumentProvider();
    IDocument document = provider.getDocument(castEditor.getEditorInput());
    return document.get();
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 28 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project dbeaver by serge-rider.

the class SQLEditorNested method refreshPart.

@Override
public void refreshPart(Object source, boolean force) {
    // Check if we are in saving process
    // If so then no refresh needed (source text was updated during save)
    IEditorSite editorSite = getEditorSite();
    if (editorSite instanceof MultiPageEditorSite && ((MultiPageEditorSite) editorSite).getMultiPageEditor() instanceof EntityEditor && ((EntityEditor) ((MultiPageEditorSite) editorSite).getMultiPageEditor()).isSaveInProgress()) {
        return;
    }
    final IDocumentProvider documentProvider = getDocumentProvider();
    if (documentProvider instanceof SQLEditorNested.ObjectDocumentProvider) {
        ((SQLEditorNested.ObjectDocumentProvider) documentProvider).sourceText = null;
    }
    if (force) {
        try {
            super.init(editorSite, getEditorInput());
        //setFocus();
        } catch (PartInitException e) {
            log.error(e);
        }
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) PartInitException(org.eclipse.ui.PartInitException) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) IEditorSite(org.eclipse.ui.IEditorSite)

Example 29 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method openXtextEditor.

private void openXtextEditor(RepositoryNode repositoryNode, IProject fsProject, boolean readonly) {
    try {
        if (ProjectManager.getInstance().isInCurrentMainProject(repositoryNode)) {
            IFile linkedFile = null;
            IOpenJobScriptActionService openJobScriptActionService = (IOpenJobScriptActionService) GlobalServiceRegister.getDefault().getService(IOpenJobScriptActionService.class);
            if (openJobScriptActionService != null) {
                linkedFile = openJobScriptActionService.createWorkspaceLink(fsProject, repositoryNode.getObject().getProperty().getItem());
            } else {
                linkedFile = createWorkspaceLink(fsProject, fsProject.getFolder(ERepositoryObjectType.getFolderName(ERepositoryObjectType.JOB_SCRIPT)).getFolder(repositoryNode.getParent().getRepositoryPath()).getFile(repositoryNode.getObject().getProperty().getLabel()).getLocation(), repositoryNode.getObject().getProperty().getVersion());
            }
            IWorkbenchPage page = getActivePage();
            IEditorPart editor = IDE.openEditor(page, linkedFile);
            if (readonly) {
                IDocumentProvider provider = ((AbstractDecoratedTextEditor) editor).getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
        } else {
            JobScriptItem jobScriptItem = (JobScriptItem) repositoryNode.getObject().getProperty().getItem();
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(jobScriptItem.eResource().getURI().path()).removeFirstSegments(1).removeFileExtension());
            IFile linkedFile = createWorkspaceLink(fsProject, file.getLocation(), "");
            IWorkbenchPage page = getActivePage();
            IEditorPart editor = IDE.openEditor(page, linkedFile);
            if (readonly) {
                IDocumentProvider provider = ((AbstractDecoratedTextEditor) editor).getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (SecurityException e) {
        ExceptionHandler.process(e);
    } catch (NoSuchMethodException e) {
        ExceptionHandler.process(e);
    } catch (IllegalArgumentException e) {
        ExceptionHandler.process(e);
    } catch (IllegalAccessException e) {
        ExceptionHandler.process(e);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IOpenJobScriptActionService(org.talend.core.ui.services.IOpenJobScriptActionService) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractDecoratedTextEditor(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 30 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project tdi-studio-se by Talend.

the class OpenDeclarationAction method highlightMethod.

/**
     * Highlights the method on editor.
     * 
     * @param editorInput The editor input
     * @param editorPart The editor part
     * @throws CoreException
     */
private void highlightMethod(IEditorInput editorInput, IEditorPart editorPart) throws CoreException {
    if (!(editorPart instanceof ITextEditor) || methodName == null || parameters == null) {
        return;
    }
    ITextEditor textEditor = (ITextEditor) editorPart;
    IDocumentProvider provider = textEditor.getDocumentProvider();
    provider.connect(editorInput);
    int offset = 0;
    int length = 0;
    ISourceRange range = getMethodNameRange(editorInput);
    if (range != null) {
        offset = range.getOffset();
        length = range.getLength();
    }
    textEditor.selectAndReveal(offset, length);
    provider.disconnect(editorInput);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)42 IDocument (org.eclipse.jface.text.IDocument)20 IEditorInput (org.eclipse.ui.IEditorInput)14 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)12 IEditorPart (org.eclipse.ui.IEditorPart)10 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 IFile (org.eclipse.core.resources.IFile)6 CoreException (org.eclipse.core.runtime.CoreException)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)6 PartInitException (org.eclipse.ui.PartInitException)6 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)6 IOException (java.io.IOException)4 IPath (org.eclipse.core.runtime.IPath)4 IDocumentWrapper (bndtools.editor.model.IDocumentWrapper)3 IResource (org.eclipse.core.resources.IResource)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 Workspace (aQute.bnd.build.Workspace)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2