org.eclipse.ui.editors.text.TextFileDocumentProvider Java Examples

The following examples show how to use org.eclipse.ui.editors.text.TextFileDocumentProvider. 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: EditorUtilities.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Obtains the document of a file.
 * @param file the file
 * @return the document of the file, or <code>null</code> if none
 */
public static IDocument getDocument(IFile file) {
    if (file == null) {
        return null;
    }
    
    try {
        TextFileDocumentProvider provider = new TextFileDocumentProvider();
        provider.connect(file);
        IDocument doc = provider.getDocument(file);
        provider.disconnect(file);
        return doc;
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #2
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 #3
Source File: XMLEditor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getContentType()
{
	try
	{
		IContentType contentType = ((TextFileDocumentProvider) getDocumentProvider())
				.getContentType(getEditorInput());
		if (contentType != null)
		{
			IContentType baseType = contentType.getBaseType();
			if (baseType != null && IXMLConstants.CONTENT_TYPE_XML.equals(baseType.getId()))
			{
				return contentType.getId();
			}
		}
	}
	catch (Exception e)
	{
	}
	return IXMLConstants.CONTENT_TYPE_XML;
}
 
Example #4
Source File: AbstractThemeableEditor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public String getContentType()
{
	try
	{
		IContentType contentType = ((TextFileDocumentProvider) getDocumentProvider())
				.getContentType(getEditorInput());
		if (contentType != null)
		{
			return contentType.getId();
		}
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
	return null;
}
 
Example #5
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 #6
Source File: EditorPool.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private static void findAndLogDocumentProviderIssues(final IEditorPart editorPart) {

    final IDocumentProvider defaultDocumentProvider =
        EditorAPI.getDocumentProvider(editorPart.getEditorInput());

    if (!(defaultDocumentProvider instanceof TextFileDocumentProvider)) {
      log.warn(
          "The default document provider "
              + defaultDocumentProvider
              + " for editor with title '"
              + editorPart.getTitle()
              + "' might not support shared access. It is likely that the editor content is not properly synchronized!");

      return;
    }

    final ITextEditor textEditor = editorPart.getAdapter(ITextEditor.class);

    if (textEditor == null) return;

    final IDocumentProvider editorDocumentProvider = textEditor.getDocumentProvider();

    if (!(editorDocumentProvider instanceof TextFileDocumentProvider)) {
      log.warn(
          "The document provider "
              + editorDocumentProvider
              + " for editor with title '"
              + editorPart.getTitle()
              + "' might not support shared access. It is likely that the editor content is not properly synchronized!");
    }
  }
 
Example #7
Source File: OberonDocumentProvider.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new Oberon-2 source file document provider and sets up the parent chain.
 */
public OberonDocumentProvider() {
    super( IModulaPartitions.M2_PARTITIONING
         , new OberonDocumentSetupParticipant()
         , new TextFileDocumentProvider() );
}
 
Example #8
Source File: ModulaDocumentProvider.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new Modula-2 source file document provider and sets up the parent chain.
 */
public ModulaDocumentProvider() {
    super( IModulaPartitions.M2_PARTITIONING
         , new ModulaDocumentSetupParticipant()
         , new TextFileDocumentProvider() );
}