Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320374 - [editor] JavaScript editor does not support alternative DocumentProviders
Summary: [editor] JavaScript editor does not support alternative DocumentProviders
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-20 06:56 EDT by Christian Pontesegger CLA
Modified: 2013-06-19 11:11 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Pontesegger CLA 2010-07-20 06:56:25 EDT
Build Identifier: I20100608-0911

I am using the javascript editor (CompilationUnitEditor.class) within my RCP to edit script files - which works fine for all kinds of IFile. Now I wanted to add another IDocumentProvider to edit some JavaScript code that is generated by the RCP (and not written to any IFile). Unfortunately the editor fires up with a single line stating "error".

This is how I am accessing the editor:
final IEditorDescriptor editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry()
				.getDefaultEditor("foo.js");
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final MacroEditorInput editorInput = new MacroEditorInput("//test\nvar a = 5;");
page.openEditor(editorInput, editorDescriptor.getId(), true);


I tracked it down to 
CompilationUnitEditor.setDocumentProvider()
here my registered provider is assigned to fImplicitDocumentProvider. But as there is an explicit provider too (which is of type CompilationunitDocumentProvider) my implicit provider is never used.

How is it possible to edit such files?


Reproducible: Always
Comment 1 Christian Pontesegger CLA 2011-03-02 07:46:43 EST
I found a way to make this work:

The editorInput used for the editor needs to implement IStorageEditorInput.
here is a reference implementation:

public class MacroEditorInput implements IStorageEditorInput {

	@Override
	public Object getAdapter(final Class adapter) {
		return null;
	}

	@Override
	public IPersistableElement getPersistable() {
		return null;
	}

	@Override
	public boolean exists() {
		return true;
	}

	@Override
	public IStorage getStorage() {
		return new IStorage() {
			@Override
			public Object getAdapter(final Class adapter) {
				return null;
			}

			@Override
			public boolean isReadOnly() {
				return false;
			}

			@Override
			public String getName() {
				return MacroEditorInput.this.getName();
			}

			@Override
			public IPath getFullPath() {
				return null;
			}

			@Override
			public InputStream getContents() throws CoreException {
				return new StringBufferInputStream("this is the content for the editor");
			}
		};
	}

	@Override
	public final ImageDescriptor getImageDescriptor() {
		return null;
	}

	@Override
	public final String getName() {
		return "Editor with generated content";
	}

	@Override
	public final String getToolTipText() {
		return "My editor";
	}
}