Java 类org.eclipse.ui.texteditor.IDocumentProvider 实例源码

项目:convertigo-eclipse    文件:HandlersDeclarationTreeObject.java   
public void moveTo(String handlerName) {

    IEditorPart editor =  PlatformUI
                                .getWorkbench()
                                .getActiveWorkbenchWindow()
                                .getActivePage()
                                .getActiveEditor();

    if (editor instanceof JscriptTransactionEditor) {
        JscriptTransactionEditor myEditor = (JscriptTransactionEditor) editor;
        MyJScriptEditor jsEditor = myEditor.getEditor();
        IDocumentProvider provider = jsEditor.getDocumentProvider();
        IDocument document = provider.getDocument(editor.getEditorInput());
        String content = document.get();
        int index = content.indexOf(handlerName);
        jsEditor.selectAndReveal(index, handlerName.length());
    }
}
项目:pgcodekeeper    文件:FileUtilsUi.java   
/**
 * Saves the content as a temp-file, opens it using SQL-editor
 * and ensures that UTF-8 is used for everything.
 */
public static void saveOpenTmpSqlEditor(String content, String filenamePrefix) throws IOException, CoreException {
    Log.log(Log.LOG_INFO, "Creating file " + filenamePrefix); //$NON-NLS-1$
    Path path = Files.createTempFile(filenamePrefix + '_', ".sql"); //$NON-NLS-1$
    Files.write(path, content.getBytes(StandardCharsets.UTF_8));
    IFileStore externalFile = EFS.getLocalFileSystem().fromLocalFile(path.toFile());
    IEditorInput input = new FileStoreEditorInput(externalFile);

    IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .openEditor(input, EDITOR.SQL);
    if (part instanceof ITextEditor) {
        IDocumentProvider prov = ((ITextEditor) part).getDocumentProvider();
        if (prov instanceof TextFileDocumentProvider) {
            ((TextFileDocumentProvider) prov).setEncoding(input, ApgdiffConsts.UTF_8);
            prov.resetDocument(input);
        }
    }
}
项目:eclemma    文件:CoverageAnnotationModel.java   
/**
 * Attaches a coverage annotation model for the given editor if the editor can
 * be annotated. Does nothing if the model is already attached.
 *
 * @param editor
 *          Editor to attach a annotation model to
 */
public static void attach(ITextEditor editor) {
  IDocumentProvider provider = editor.getDocumentProvider();
  // there may be text editors without document providers (SF #1725100)
  if (provider == null)
    return;
  IAnnotationModel model = provider.getAnnotationModel(editor
      .getEditorInput());
  if (!(model instanceof IAnnotationModelExtension))
    return;
  IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

  IDocument document = provider.getDocument(editor.getEditorInput());

  CoverageAnnotationModel coveragemodel = (CoverageAnnotationModel) modelex
      .getAnnotationModel(KEY);
  if (coveragemodel == null) {
    coveragemodel = new CoverageAnnotationModel(editor, document);
    modelex.addAnnotationModel(KEY, coveragemodel);
  }
}
项目:ermasterr    文件:TestEditor.java   
private void initializeSourceViewer(final IEditorInput input) {

        final IDocumentProvider documentProvider = getDocumentProvider();
        final IAnnotationModel model = documentProvider.getAnnotationModel(input);
        final IDocument document = documentProvider.getDocument(input);

        if (document != null) {
            fSourceViewer.setDocument(document, model);
            fSourceViewer.setEditable(isEditable());
            fSourceViewer.showAnnotations(model != null);
        }

        if (fElementStateListener instanceof IElementStateListenerExtension) {
            boolean isStateValidated = false;
            if (documentProvider instanceof IDocumentProviderExtension)
                isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input);

            final IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener;
            extension.elementStateValidationChanged(input, isStateValidated);
        }

    }
项目:ermasterr    文件:TestEditor.java   
/**
 * Disposes of the connection with the document provider. Subclasses may
 * extend.
 * 
 * @since 3.0
 */
protected void disposeDocumentProvider() {
    final IDocumentProvider provider = getDocumentProvider();
    if (provider != null) {

        final IEditorInput input = getEditorInput();
        if (input != null)
            provider.disconnect(input);

        if (fElementStateListener != null) {
            provider.removeElementStateListener(fElementStateListener);
            fElementStateListener = null;
        }

    }
    fImplicitDocumentProvider = null;
}
项目:ermasterr    文件:TestEditor.java   
protected void updateState(final IEditorInput input) {
    final IDocumentProvider provider = getDocumentProvider();
    if (provider instanceof IDocumentProviderExtension) {
        final IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
        try {

            extension.updateStateCache(input);

            if (fSourceViewer != null)
                fSourceViewer.setEditable(isEditable());

        } catch (final CoreException e) {
            ERDiagramActivator.log(e);
        }
    }
}
项目:ermaster-k    文件:TestEditor.java   
private void initializeSourceViewer(IEditorInput input) {

        IDocumentProvider documentProvider = getDocumentProvider();
        IAnnotationModel model = documentProvider.getAnnotationModel(input);
        IDocument document = documentProvider.getDocument(input);

        if (document != null) {
            fSourceViewer.setDocument(document, model);
            fSourceViewer.setEditable(isEditable());
            fSourceViewer.showAnnotations(model != null);
        }

        if (fElementStateListener instanceof IElementStateListenerExtension) {
            boolean isStateValidated = false;
            if (documentProvider instanceof IDocumentProviderExtension)
                isStateValidated = ((IDocumentProviderExtension) documentProvider)
                        .isStateValidated(input);

            IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener;
            extension.elementStateValidationChanged(input, isStateValidated);
        }

    }
项目:ermaster-k    文件:TestEditor.java   
/**
 * Disposes of the connection with the document provider. Subclasses may
 * extend.
 * 
 * @since 3.0
 */
protected void disposeDocumentProvider() {
    IDocumentProvider provider = getDocumentProvider();
    if (provider != null) {

        IEditorInput input = getEditorInput();
        if (input != null)
            provider.disconnect(input);

        if (fElementStateListener != null) {
            provider.removeElementStateListener(fElementStateListener);
            fElementStateListener = null;
        }

    }
    fImplicitDocumentProvider = null;
}
项目:ermaster-k    文件:TestEditor.java   
protected void updateState(IEditorInput input) {
    IDocumentProvider provider = getDocumentProvider();
    if (provider instanceof IDocumentProviderExtension) {
        IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
        try {

            extension.updateStateCache(input);

            if (fSourceViewer != null)
                fSourceViewer.setEditable(isEditable());

        } catch (CoreException e) {
            ERDiagramActivator.log(e);
        }
    }
}
项目:tlaplus    文件:TLAEditor.java   
/**
 * Register the element state listener to react on the changes to the state (saved, dirty:=not saved) 
 */
protected void setDocumentProvider(IEditorInput input)
{
    super.setDocumentProvider(input);

    IDocumentProvider provider = getDocumentProvider();
    if (provider != null)
    {
        provider.addElementStateListener(new ElementStateAdapter() {
            public void elementDirtyStateChanged(Object element, boolean isDirty)
            {
                if (isDirty)
                {
                    contextService.deactivateContext(contextActivation);
                } else
                {
                    contextActivation = contextService.activateContext("toolbox.contexts.cleaneditor");
                }
            }
        });
    }
}
项目:typescript.java    文件:EditorUtils.java   
public static Position getPosition(IFile file, TextSpan textSpan) throws BadLocationException {
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(file.getLocation(), LocationKind.IFILE);
    if (buffer != null) {
        return getPosition(buffer.getDocument(), textSpan);
    }
    IDocumentProvider provider = new TextFileDocumentProvider();
    try {
        provider.connect(file);
        IDocument document = provider.getDocument(file);
        if (document != null) {
            return getPosition(document, textSpan);
        }
    } catch (CoreException e) {
    } finally {
        provider.disconnect(file);
    }
    return null;
}
项目:typescript.java    文件:TypeScriptEditor.java   
private void removeOccurrenceAnnotations() {
    // fMarkOccurrenceModificationStamp=
    // IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
    // fMarkOccurrenceTargetRegion= null;

    IDocumentProvider documentProvider = getDocumentProvider();
    if (documentProvider == null)
        return;

    IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
    if (annotationModel == null || fOccurrenceAnnotations == null)
        return;

    synchronized (getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
        } else {
            for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
                annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
        }
        fOccurrenceAnnotations = null;
    }
}
项目:typescript.java    文件:TypeScriptEditor.java   
@Override
protected void installTabsToSpacesConverter() {
    ISourceViewer sourceViewer = getSourceViewer();
    SourceViewerConfiguration config = getSourceViewerConfiguration();
    if (config != null && sourceViewer instanceof ITextViewerExtension7) {
        int tabWidth = config.getTabWidth(sourceViewer);
        TabsToSpacesConverter tabToSpacesConverter = new TabsToSpacesConverter();
        tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
        IDocumentProvider provider = getDocumentProvider();
        if (provider instanceof ICompilationUnitDocumentProvider) {
            ICompilationUnitDocumentProvider cup = (ICompilationUnitDocumentProvider) provider;
            tabToSpacesConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
        } else
            tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
        ((ITextViewerExtension7) sourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
        updateIndentPrefixes();
    }
}
项目:gwt-eclipse-plugin    文件:JavaCompilationParticipantTest.java   
private List<GWTJavaProblem> getGWTProblemsInEditor(CompilationUnitEditor editor)
    throws Exception {
  List<GWTJavaProblem> problems = new ArrayList<GWTJavaProblem>();

  Field annotationProblemField = CompilationUnitDocumentProvider.ProblemAnnotation.class.getDeclaredField("fProblem");
  annotationProblemField.setAccessible(true);

  IEditorInput editorInput = editor.getEditorInput();
  IDocumentProvider documentProvider = editor.getDocumentProvider();
  IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editorInput);
  Iterator<?> iter = annotationModel.getAnnotationIterator();
  while (iter.hasNext()) {
    Object annotation = iter.next();
    if (annotation instanceof CompilationUnitDocumentProvider.ProblemAnnotation) {
      CompilationUnitDocumentProvider.ProblemAnnotation problemAnnotation = (ProblemAnnotation) annotation;
      if (problemAnnotation.getMarkerType().equals(GWTJavaProblem.MARKER_ID)) {
        GWTJavaProblem problem = (GWTJavaProblem) annotationProblemField.get(problemAnnotation);
        problems.add(problem);
      }
    }
  }

  return problems;
}
项目:PDFReporter-Studio    文件:AMultiEditor.java   
protected String model2xml() {
    try {
        if (model != null) {
            String xml = doModel2xml();
            IDocumentProvider dp = xmlEditor.getDocumentProvider();
            IDocument doc = dp.getDocument(xmlEditor.getEditorInput());
            if (xml != null && !Arrays.equals(doc.get().getBytes(), xml.getBytes()))
                doc.set(xml);
            xmlFresh = true;
            return xml;
        }
    } catch (final Exception e) {
        UIUtils.showError(e);
    }
    return null;
}
项目:PDFReporter-Studio    文件:JrxmlEditor.java   
/**
 * Xml2model.
 * 
 * @throws JRException
 *           the jR exception
 */
private void xml2model() throws Exception {
    InputStream in = null;
    try {
        IDocumentProvider dp = xmlEditor.getDocumentProvider();
        IDocument doc = dp.getDocument(xmlEditor.getEditorInput());
        in = new ByteArrayInputStream(doc.get().getBytes("UTF-8"));

        JasperDesign jd = new JRXmlLoader(jrContext, JasperReportsConfiguration.getJRXMLDigester()).loadXML(in);
        jrContext.setJasperDesign(jd);
        JaspersoftStudioPlugin.getExtensionManager().onLoad(jd, this);
        setModel(ReportFactory.createReport(jrContext));
    } finally {
        FileUtils.closeStream(in);
    }
}
项目:strutsclipse    文件:TilesXmlValidator.java   
@Override
public ValidationResult validate(IResource resource, int kind,
        ValidationState state, IProgressMonitor monitor) {
    IDocument document = null;
    // get document
    try {
        final IDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(resource);
        document = provider.getDocument(resource);
        provider.disconnect(resource);
    } catch (CoreException e) {
        e.printStackTrace();
    }

    ValidationResult result = new ValidationResult();
    if (document != null) {
        // validate definitions names
        List<ElementRegion> definitionNameRegions = tilesXmlParser
                .getDefinitionNameRegions(document);
        validateRegions(resource, document, result, definitionNameRegions,
                DUP_DEFINITION_MESSAGE_TEXT, IMarker.SEVERITY_WARNING);
    }

    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSourceViewerConfiguration.java   
private IJavaProject getProject() {
    ITextEditor editor= getEditor();
    if (editor == null)
        return null;

    IJavaElement element= null;
    IEditorInput input= editor.getEditorInput();
    IDocumentProvider provider= editor.getDocumentProvider();
    if (provider instanceof ICompilationUnitDocumentProvider) {
        ICompilationUnitDocumentProvider cudp= (ICompilationUnitDocumentProvider) provider;
        element= cudp.getWorkingCopy(input);
    } else if (input instanceof IClassFileEditorInput) {
        IClassFileEditorInput cfei= (IClassFileEditorInput) input;
        element= cfei.getClassFile();
    }

    if (element == null)
        return null;

    return element.getJavaProject();
}
项目:Eclipse-Postfix-Code-Completion    文件:CompilationUnitEditor.java   
@Override
protected void installTabsToSpacesConverter() {
    ISourceViewer sourceViewer= getSourceViewer();
    SourceViewerConfiguration config= getSourceViewerConfiguration();
    if (config != null && sourceViewer instanceof ITextViewerExtension7) {
        int tabWidth= config.getTabWidth(sourceViewer);
        TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
        tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
        IDocumentProvider provider= getDocumentProvider();
        if (provider instanceof ICompilationUnitDocumentProvider) {
            ICompilationUnitDocumentProvider cup= (ICompilationUnitDocumentProvider) provider;
            tabToSpacesConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
        } else
            tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
        ((ITextViewerExtension7)sourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
        updateIndentPrefixes();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditor.java   
void removeOccurrenceAnnotations() {
    fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
    fMarkOccurrenceTargetRegion= null;

    IDocumentProvider documentProvider= getDocumentProvider();
    if (documentProvider == null)
        return;

    IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
    if (annotationModel == null || fOccurrenceAnnotations == null)
        return;

    synchronized (getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
        } else {
            for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++)
                annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
        }
        fOccurrenceAnnotations= null;
    }
}
项目:ermaster-nhit    文件:TestEditor.java   
private void initializeSourceViewer(IEditorInput input) {

        IDocumentProvider documentProvider = getDocumentProvider();
        IAnnotationModel model = documentProvider.getAnnotationModel(input);
        IDocument document = documentProvider.getDocument(input);

        if (document != null) {
            fSourceViewer.setDocument(document, model);
            fSourceViewer.setEditable(isEditable());
            fSourceViewer.showAnnotations(model != null);
        }

        if (fElementStateListener instanceof IElementStateListenerExtension) {
            boolean isStateValidated = false;
            if (documentProvider instanceof IDocumentProviderExtension)
                isStateValidated = ((IDocumentProviderExtension) documentProvider)
                        .isStateValidated(input);

            IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener;
            extension.elementStateValidationChanged(input, isStateValidated);
        }

    }
项目:ermaster-nhit    文件:TestEditor.java   
/**
 * Disposes of the connection with the document provider. Subclasses may
 * extend.
 * 
 * @since 3.0
 */
protected void disposeDocumentProvider() {
    IDocumentProvider provider = getDocumentProvider();
    if (provider != null) {

        IEditorInput input = getEditorInput();
        if (input != null)
            provider.disconnect(input);

        if (fElementStateListener != null) {
            provider.removeElementStateListener(fElementStateListener);
            fElementStateListener = null;
        }

    }
    fImplicitDocumentProvider = null;
}
项目:ermaster-nhit    文件:TestEditor.java   
protected void updateState(IEditorInput input) {
    IDocumentProvider provider = getDocumentProvider();
    if (provider instanceof IDocumentProviderExtension) {
        IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
        try {

            extension.updateStateCache(input);

            if (fSourceViewer != null)
                fSourceViewer.setEditable(isEditable());

        } catch (CoreException e) {
            ERDiagramActivator.log(e);
        }
    }
}
项目:WP3    文件:DeleteAllHandler.java   
private void refresh() {
  ITextEditor iteEditor = null;
  if (this.editor instanceof EcoreEditor) {
    final EcoreEditor ecEditor = (EcoreEditor) this.editor;
    ecEditor.getViewer().refresh();
  } else {
    if (this.editor instanceof ITextEditor) {
      iteEditor = (ITextEditor) this.editor;
    } else {
      final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) this.editor;
      final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput());
      iteEditor = (ITextEditor) editors[0];
    }
    final IDocumentProvider idp = iteEditor.getDocumentProvider();
    try {
      idp.resetDocument(iteEditor.getEditorInput());
    } catch (final CoreException e) {
      e.printStackTrace();
    }
  }
  MarkerFactory.refreshProjectExp();
  if (Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getActivePage()
      .findView(Visualization.ID) != null) {
    Visualization.showViz();
  }
}
项目:WP3    文件:DeleteHandler.java   
private void refresh() {
  ITextEditor iteEditor = null;
  if (editor instanceof EcoreEditor) {
    final EcoreEditor ecEditor = (EcoreEditor) editor;
    ecEditor.getViewer().refresh();
  } else {
    if (editor instanceof ITextEditor) {
      iteEditor = (ITextEditor) editor;
    } else {
      final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) editor;
      final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput());
      iteEditor = (ITextEditor) editors[0];
    }
    final IDocumentProvider idp = iteEditor.getDocumentProvider();
    try {
      idp.resetDocument(iteEditor.getEditorInput());
    } catch (final CoreException e) {
      e.printStackTrace();
    }
  }
  MarkerFactory.refreshProjectExp();
  if (Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getActivePage()
      .findView(Visualization.ID) != null) {
    Visualization.showViz();
  }
}
项目:WP3    文件:DeleteAtomCommand.java   
private void refresh() {
  ITextEditor iteEditor = null;
  if (editor instanceof EcoreEditor) {
    final EcoreEditor ecEditor = (EcoreEditor) editor;
    ecEditor.getViewer().refresh();
  } else {
    if (editor instanceof ITextEditor) {
      iteEditor = (ITextEditor) editor;
    } else {
      final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) editor;
      final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput());
      iteEditor = (ITextEditor) editors[0];
    }
    final IDocumentProvider idp = iteEditor.getDocumentProvider();
    try {
      idp.resetDocument(iteEditor.getEditorInput());
    } catch (final CoreException e) {
      e.printStackTrace();
    }
  }
  MarkerFactory.refreshProjectExp();
}
项目:connectiq-monkeyc    文件:PCMatcher.java   
private void gotoLine(ITextEditor editor, int line) {

            IDocumentProvider provider = editor.getDocumentProvider();
            IDocument document = provider.getDocument(editor.getEditorInput());
            try {

                int start = document.getLineOffset(line);
                editor.selectAndReveal(start, 0);

                IWorkbenchPage page = editor.getSite().getPage();
                page.activate(editor);

            } catch (BadLocationException x) {
                // ignore
            }
        }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaSourceViewerConfiguration.java   
private IJavaProject getProject() {
    ITextEditor editor= getEditor();
    if (editor == null)
        return null;

    IJavaElement element= null;
    IEditorInput input= editor.getEditorInput();
    IDocumentProvider provider= editor.getDocumentProvider();
    if (provider instanceof ICompilationUnitDocumentProvider) {
        ICompilationUnitDocumentProvider cudp= (ICompilationUnitDocumentProvider) provider;
        element= cudp.getWorkingCopy(input);
    } else if (input instanceof IClassFileEditorInput) {
        IClassFileEditorInput cfei= (IClassFileEditorInput) input;
        element= cfei.getClassFile();
    }

    if (element == null)
        return null;

    return element.getJavaProject();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CompilationUnitEditor.java   
@Override
protected void installTabsToSpacesConverter() {
    ISourceViewer sourceViewer= getSourceViewer();
    SourceViewerConfiguration config= getSourceViewerConfiguration();
    if (config != null && sourceViewer instanceof ITextViewerExtension7) {
        int tabWidth= config.getTabWidth(sourceViewer);
        TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
        tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
        IDocumentProvider provider= getDocumentProvider();
        if (provider instanceof ICompilationUnitDocumentProvider) {
            ICompilationUnitDocumentProvider cup= (ICompilationUnitDocumentProvider) provider;
            tabToSpacesConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
        } else
            tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
        ((ITextViewerExtension7)sourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
        updateIndentPrefixes();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaEditor.java   
void removeOccurrenceAnnotations() {
    fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
    fMarkOccurrenceTargetRegion= null;

    IDocumentProvider documentProvider= getDocumentProvider();
    if (documentProvider == null)
        return;

    IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
    if (annotationModel == null || fOccurrenceAnnotations == null)
        return;

    synchronized (getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
        } else {
            for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++)
                annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
        }
        fOccurrenceAnnotations= null;
    }
}
项目:watchdog    文件:WatchDogUtils.java   
private static IDocument extractDocument(final ITextEditor editor)
        throws ContentReaderException {
    if (editor == null) {
        throw new IllegalArgumentException("Editor is null");
    }

    IDocumentProvider documentProvider = editor.getDocumentProvider();
    if (documentProvider == null) {
        throw new ContentReaderException(
                "Editor closed: Document provider is null");
    }

    IDocument document = documentProvider
            .getDocument(editor.getEditorInput());
    return document;
}
项目:watchdog    文件:DocumentCreatorTest.java   
/**
 * Tests whether the creation of a Java production class via the
 * {@link DocumentCreator} actually returns said class, and that the
 * document classification returns the correct type.
 */
@Test
public void testCreateDocument() {
    String contents = "public class A {}";

    ITextEditor mockedEditor = mock(ITextEditor.class);
    IDocumentProvider mockedProvider = mock(IDocumentProvider.class);
    org.eclipse.jface.text.IDocument mockedDocument = mock(org.eclipse.jface.text.IDocument.class);

    when(mockedEditor.getDocumentProvider()).thenReturn(mockedProvider);
    when(mockedProvider.getDocument(Matchers.anyObject())).thenReturn(
            mockedDocument);
    when(mockedDocument.get()).thenReturn(contents);
    when(mockedEditor.getTitle()).thenReturn("A.java");

    Document doc = DocumentCreator.createDocument(mockedEditor);

    assertEquals("A.java", doc.getFileName());

    doc.prepareDocument();
    assertEquals(DocumentType.PRODUCTION, doc.getDocumentType());
}
项目:birt    文件:DecoratedScriptEditor.java   
public String getScript( )
{
    IDocumentProvider provider = getDocumentProvider( );
    String script = ""; //$NON-NLS-1$

    if ( provider != null )
    {
        IDocument document = provider.getDocument( getEditorInput( ) );

        if ( document != null )
        {
            script = document.get( );
        }
    }
    return script;
}
项目:birt    文件:ScriptEditor.java   
public String getScript( )
{
    IDocumentProvider provider = getDocumentProvider( );
    String script = ""; //$NON-NLS-1$

    if ( provider != null )
    {
        IDocument document = provider.getDocument( getEditorInput( ) );

        if ( document != null )
        {
            script = document.get( );
        }
    }
    return script;
}
项目:StringEditEclipse    文件:MultiLineHyperlinkDector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
        IRegion region, boolean canShowMultipleHyperlinks) {

    ITextEditor editor = (ITextEditor) getAdapter(ITextEditor.class);
    if (!editor.getTitle().endsWith(".java")) {
        return null;
    }
    IDocumentProvider dp = editor.getDocumentProvider();
    StringUtils textUtils = new StringUtils();
    textUtils.setDoc(dp.getDocument(editor.getEditorInput()).get());
    textUtils.setCursorPosition(StringHandler.getCursorPosition());
    boolean val = textUtils.proccess();
    int cursorPosition = textUtils.getCursorPosition();
    if (cursorPosition < 0) {
        return null;
    }
    if (!val) {
        return null;
    }

    return new IHyperlink[] { new MultiLineHyperlink(new Region(
            textUtils.getStart(), textUtils.getLength())) };
}
项目:eclipse-batch-editor    文件:BatchEditor.java   
private IDocumentProvider createDocumentProvider(IEditorInput input) {
    if (input instanceof FileStoreEditorInput) {
        return new BatchTextFileDocumentProvider();
    } else {
        return new BatchFileDocumentProvider();
    }
}
项目:eclipse-bash-editor    文件:BashEditor.java   
private IDocumentProvider createDocumentProvider(IEditorInput input) {
    if (input instanceof FileStoreEditorInput) {
        return new BashTextFileDocumentProvider();
    } else {
        return new BashFileDocumentProvider();
    }
}
项目:visuflow-plugin    文件:JavaToCFGHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IFileEditorInput input = (IFileEditorInput) part.getEditorInput();
    IFile file = input.getFile();
    if (part instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) part;
        IVerticalRulerInfo ruleInfo = editor.getAdapter(IVerticalRulerInfo.class);
        IDocumentProvider provider = editor.getDocumentProvider();
        IDocument document = provider.getDocument(editor.getEditorInput());
        int lineNumber = ruleInfo.getLineOfLastMouseButtonActivity();
        String className = file.getName().substring(0, file.getName().lastIndexOf('.'));
        HashMap<VFUnit, VFMethod> resultantUnit = getSelectedUnit(className, document, lineNumber);
        List<VFNode> unit = new ArrayList<>();
        if (resultantUnit.size() > 0) {
            if (event.getCommand().getId().equals("JavaHandler.NavigateToJimple")) {
                NavigationHandler handler = new NavigationHandler();
                handler.highlightJimpleSource(new ArrayList<>(resultantUnit.keySet()));
            } else {
                for (VFUnit vfUnit : resultantUnit.keySet()) {
                    unit.add(new VFNode(vfUnit, 0));
                }
                try {
                    ServiceUtil.getService(DataModel.class).filterGraph(unit, true, true, null);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }

        // call graph highlighting code here
    } else {
        logger.error("Editor not a  Text Editor");
    }
    return null;
}
项目:egradle    文件:AbstractGroovyBasedEditor.java   
private IDocumentProvider createDocumentProvider(IEditorInput input) {
    if (input instanceof FileStoreEditorInput) {
        return createFileStoreEditorInputProvider();
    } else {
        return createStandardEditorInputProvider();
    }
}
项目:eclemma    文件:CoverageAnnotationModel.java   
/**
 * Detaches the coverage annotation model from the given editor. If the editor
 * does not have a model attached, this method does nothing.
 *
 * @param editor
 *          Editor to detach the annotation model from
 */
public static void detach(ITextEditor editor) {
  IDocumentProvider provider = editor.getDocumentProvider();
  // there may be text editors without document providers (SF #1725100)
  if (provider == null)
    return;
  IAnnotationModel model = provider.getAnnotationModel(editor
      .getEditorInput());
  if (!(model instanceof IAnnotationModelExtension))
    return;
  IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
  modelex.removeAnnotationModel(KEY);
}