org.eclipse.ui.texteditor.IDocumentProvider Java Examples

The following examples show how to use org.eclipse.ui.texteditor.IDocumentProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
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);
		}

	}
 
Example #2
Source File: TestEditor.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
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);
        }

    }
 
Example #3
Source File: TestEditor.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: TestEditor.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #5
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
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) {
			Activator.log(e);
		}
	}
}
 
Example #6
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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();
	}
}
 
Example #7
Source File: TLAEditor.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * 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");
                }
            }
        });
    }
}
 
Example #8
Source File: JavaCompilationParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: EditorManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private String doGetContent(saros.filesystem.IFile wrappedFile) {
  IFile file = ((EclipseFileImpl) wrappedFile).getDelegate();
  FileEditorInput input = new FileEditorInput(file);

  IDocumentProvider provider = EditorAPI.connect(input);

  if (provider == null) {
    log.warn("Failed to retrieve the content of " + wrappedFile);
    return null;
  }

  IDocument doc = provider.getDocument(input);
  String content = (doc != null) ? doc.get() : null;

  provider.disconnect(input);

  return content;
}
 
Example #10
Source File: EditorUtils.java    From typescript.java with MIT License 6 votes vote down vote up
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;
}
 
Example #11
Source File: ScriptEditor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: EditorAPITextPositionTest.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds the ITextEditor mock.
 *
 * @return the ITextEditor mock
 * @see #withLineOffsetLookupAnswer(int, int)
 */
private ITextEditor build() {
  IDocument document = documentBuilder.build();

  IEditorInput editorInput = EasyMock.createNiceMock(IEditorInput.class);
  EasyMock.replay(editorInput);

  IDocumentProvider documentProvider = EasyMock.createNiceMock(IDocumentProvider.class);
  EasyMock.expect(documentProvider.getDocument(editorInput)).andReturn(document).anyTimes();
  EasyMock.replay(documentProvider);

  editor = EasyMock.createNiceMock(ITextEditor.class);
  EasyMock.expect(editor.getDocumentProvider()).andReturn(documentProvider).anyTimes();
  EasyMock.expect(editor.getEditorInput()).andReturn(editorInput).anyTimes();
  EasyMock.replay(editor);

  return editor;
}
 
Example #13
Source File: CommonReconcilingStrategy.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reports problems found in reconcile to the annotation model so we can draw them on the editor without creating
 * markers on the underlying resource.
 * 
 * @param context
 * @param monitor
 */
private void reportProblems(ReconcileContext context, IProgressMonitor monitor)
{
	AbstractThemeableEditor editor = fEditor;
	if (editor == null)
	{
		return;
	}

	IDocumentProvider docProvider = editor.getDocumentProvider();
	if (docProvider == null)
	{
		return;
	}

	IEditorInput editorInput = editor.getEditorInput();
	if (editorInput == null)
	{
		return;
	}

	IAnnotationModel model = docProvider.getAnnotationModel(editorInput);
	if (!(model instanceof ICommonAnnotationModel))
	{
		return;
	}

	ICommonAnnotationModel caModel = (ICommonAnnotationModel) model;
	// Now report them all to the annotation model!
	caModel.reportProblems(context.getProblems(), monitor);
}
 
Example #14
Source File: EditorConfigUIPlugin.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the shared document provider for .editorconfig files used by this
 * plug-in instance.
 *
 * @return the shared document provider for .editorconfig files
 */
public synchronized IDocumentProvider getEditorConfigDocumentProvider() {
	if (editorConfigDocumentProvider == null) {
		editorConfigDocumentProvider = new EditorConfigDocumentProvider();
	}
	return editorConfigDocumentProvider;
}
 
Example #15
Source File: ClassFileEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dispose() {
	// http://bugs.eclipse.org/bugs/show_bug.cgi?id=18510
	IDocumentProvider documentProvider= getDocumentProvider();
	if (documentProvider instanceof ClassFileDocumentProvider)
		((ClassFileDocumentProvider) documentProvider).removeInputChangeListener(this);
	super.dispose();
}
 
Example #16
Source File: AnnotationModelHelper.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
public IAnnotationModel retrieveAnnotationModel(IEditorPart editorPart) {
  IEditorInput input = editorPart.getEditorInput();
  IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(input);
  IAnnotationModel model = provider.getAnnotationModel(input);

  return model;
}
 
Example #17
Source File: TypeScriptEditor.java    From typescript.java with MIT License 5 votes vote down vote up
private IAnnotationModel getAnnotationModel() {
	IDocumentProvider documentProvider = getDocumentProvider();
	if (documentProvider == null) {
		return null;
	}
	return documentProvider.getAnnotationModel(getEditorInput());
}
 
Example #18
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean mustSaveDirtyEditor(IEditorPart ep, IEditorInput input, boolean saveUnknownEditors) {
	/*
	 * Goal: save all editors that could interfere with refactoring operations.
	 *
	 * Always save all editors for compilation units that are not working copies.
	 * (Leaving them dirty would cause problems, since the file buffer could have been
	 * modified but the Java model is not reconciled.)
	 *
	 * If <code>saveUnknownEditors</code> is <code>true</code>, save all editors
	 * whose implementation is probably not based on file buffers.
	 */
	IResource resource= (IResource) input.getAdapter(IResource.class);
	if (resource == null)
		return saveUnknownEditors;

	IJavaElement javaElement= JavaCore.create(resource);
	if (javaElement instanceof ICompilationUnit) {
		ICompilationUnit cu= (ICompilationUnit) javaElement;
		if (!cu.isWorkingCopy()) {
			return true;
		}
	}

	if (! (ep instanceof ITextEditor))
		return saveUnknownEditors;

	ITextEditor textEditor= (ITextEditor) ep;
	IDocumentProvider documentProvider= textEditor.getDocumentProvider();
	if (! (documentProvider instanceof TextFileDocumentProvider))
		return saveUnknownEditors;

	return false;
}
 
Example #19
Source File: CommonOccurrencesUpdater.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * getAnnotationModel
 * 
 * @return
 */
protected IAnnotationModel getAnnotationModel() {
	IDocumentProvider documentProvider = getDocumentProvider();
	IEditorInput editorInput = getEditorInput();
	IAnnotationModel result = null;

	if (documentProvider != null && editorInput != null) {
		result = documentProvider.getAnnotationModel(editorInput);
	}

	return result;
}
 
Example #20
Source File: SpecificContentAssistAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IDocument getDocument() {
Assert.isTrue(fEditor != null);
   IDocumentProvider provider= fEditor.getDocumentProvider();
   if (provider == null)
   	return null;

IDocument document= provider.getDocument(fEditor.getEditorInput());
   return document;
  }
 
Example #21
Source File: EditorUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static IDocument getDocument(ITextEditor editor) {
    IDocumentProvider documentProvider = editor.getDocumentProvider();
    if (documentProvider != null) {
        return documentProvider.getDocument(editor.getEditorInput());
    }
    return null;
}
 
Example #22
Source File: JavaSpellingReconcileStrategy.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IAnnotationModel getAnnotationModel() {
	final IDocumentProvider documentProvider= fEditor.getDocumentProvider();
	if (documentProvider == null)
		return null;
	return documentProvider.getAnnotationModel(fEditor.getEditorInput());
}
 
Example #23
Source File: IDEFileReportProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IDocumentProvider getReportDocumentProvider( Object element )
{
	if ( element instanceof FileEditorInput )
	{
		// workspace file
		return new ReportDocumentProvider( );
	}
	else
	{
		// system file
		return new IDEFileReportDocumentProvider( );
	}
}
 
Example #24
Source File: DTDPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns DTD document provider
 * @return
 */
public synchronized IDocumentProvider getDTDDocumentProvider() {
	if (dtdDocumentProvider == null) {
		dtdDocumentProvider = new DTDDocumentProvider();
	}
	return dtdDocumentProvider;
}
 
Example #25
Source File: SVNPristineCopyQuickDiffProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void setActiveEditor(ITextEditor targetEditor) {
	if(! (targetEditor.getEditorInput() instanceof IFileEditorInput)) return;
	editor = targetEditor;
	documentProvider= editor.getDocumentProvider();
	
	if(documentProvider != null) {
		SVNWorkspaceSubscriber.getInstance().addListener(teamChangeListener);
		((IDocumentProvider)documentProvider).addElementStateListener(documentListener);
	}	
	isReferenceInitialized= true;
}
 
Example #26
Source File: XMLPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns XML document provider
 * 
 * @return
 */
public synchronized IDocumentProvider getXMLDocumentProvider()
{
	if (xmlDocumentProvider == null)
	{
		xmlDocumentProvider = new XMLDocumentProvider();
	}
	return xmlDocumentProvider;
}
 
Example #27
Source File: TextEditorContextMenuContribution.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the 1-based line number of the current text editor selection,
 * or 0 if some weird error occurs. If there is a multi-line selection. the
 * first line will get returned. Which is what we want for the purposes of
 * creating a review comment.
 */
private int getSelectedLineNumber() {
  ITextSelection textSelection =
      (ITextSelection) editor.getSite().getSelectionProvider().getSelection();
  IDocumentProvider provider = editor.getDocumentProvider();
  IDocument document = provider.getDocument(editor.getEditorInput());
  int offset = textSelection.getOffset();
  try {
    return document.getLineOfOffset(offset) + 1;
  } catch (BadLocationException e) {
    return 0;
  }
}
 
Example #28
Source File: JsonEditor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
private void hack_AbstractTextEditor_doSave(IProgressMonitor progressMonitor) {

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

        if (p.isDeleted(getEditorInput())) {

            if (isSaveAsAllowed()) {

                /*
                 * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the editors. Changed Behavior to make
                 * sure that if called inside a regular save (because of deletion of input element) there is a way to
                 * report back to the caller.
                 */
                performSaveAs(progressMonitor);

            } else {

                Shell shell = getSite().getShell();
                String title = "Cannot Save";
                String msg = "The file has been deleted or is not accessible.";
                MessageDialog.openError(shell, title, msg);
            }

        } else {
            updateState(getEditorInput());
            validateState(getEditorInput());
            performSave(false, progressMonitor);
        }
    }
 
Example #29
Source File: TypeScriptEditor.java    From typescript.java with MIT License 5 votes vote down vote up
public void uninstall() {
	ISourceViewer sourceViewer = getSourceViewer();
	if (sourceViewer != null)
		sourceViewer.removeTextInputListener(this);

	IDocumentProvider documentProvider = getDocumentProvider();
	if (documentProvider != null) {
		IDocument document = documentProvider.getDocument(getEditorInput());
		if (document != null)
			document.removeDocumentListener(this);
	}
}
 
Example #30
Source File: TestResultHyperlink.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void revealLocationInFile(IEditorPart editorPart)
		throws CoreException {
	if (editorPart instanceof ITextEditor && locationText.line > 0) {
		ITextEditor textEditor = (ITextEditor) editorPart;
		IDocumentProvider provider = textEditor.getDocumentProvider();
		IEditorInput editorInput = editorPart.getEditorInput();
		provider.connect(editorInput);
		IDocument document = provider.getDocument(editorInput);
		try {
			IRegion regionOfLine = document.getLineInformation(locationText.line - 1);
			// only used to reveal the location
			textEditor.selectAndReveal(regionOfLine.getOffset(), regionOfLine.getLength());
			int startOffset = regionOfLine.getOffset() + locationText.column - 1;
			int length = regionOfLine.getLength() - locationText.column;
			if (startOffset >= document.getLength()) {
				startOffset = document.getLength() - 1;
			}
			if (length + startOffset >= document.getLength()) {
				length = document.getLength() - startOffset - 1;
			}
			textEditor.setHighlightRange(startOffset, length, true);
		} catch (BadLocationException e) {
			MessageDialog.openInformation(N4JSGracefulActivator.getActiveWorkbenchShell(),
					ConsoleMessages.msgInvalidLineNumberTitle(),
					ConsoleMessages.msgInvalidLineNumberIn(
							(locationText.line) + "",
							locationText.fileName));
		}
		provider.disconnect(editorInput);
	}
}