Registering own IDocumentProvider for JavaScriptEditor [message #229384] |
Mon, 23 March 2009 06:36 |
Andrew Arapov Messages: 5 Registered: July 2009 |
Junior Member |
|
|
Hi!
I'm trying to register my own IDocumentProvider, which extends
StorageDocumentProvider.
My steps are:
1. I have my own IStorageEditorInput, which provides editing some string
without openning IFile
============================================================ ==================public
class SimpleEditorInput implements IStorageEditorInput {
private String inputString;
public SimpleEditorInput(String inputString) {
this.inputString = inputString;
}
public IStorage getStorage() throws CoreException {
return new IStorage() {
public InputStream getContents() throws CoreException {
return IOUtils.toInputStream(inputString);
}
public IPath getFullPath() {
return null;
}
public String getName() {
return SimpleEditorInput.this.getName();
}
public boolean isReadOnly() {
return false;
}
public Object getAdapter(Class adapter) {
return null;
}
};
}
public boolean exists() {
return true;
}
public ImageDescriptor getImageDescriptor() {
return ImageDescriptor.getMissingImageDescriptor();
}
public String getName() {
return "JSEditor";
}
public IPersistableElement getPersistable() {
return null;
}
public String getToolTipText() {
return "JSEditor Tool Tip Text";
}
public Object getAdapter(Class adapter) {
return null;
}
public void setInputString(String inputString) {
this.inputString = inputString;
}
}
============================================================ ==================
2. Next, I'm opennig JavaScriptEditor:
============================================================ ==================
window.getActivePage().openEditor(new
SimpleEditorInput(TEST_JS_1),"org.eclipse.wst.jsdt.ui.CompilationUnitEditor ");
============================================================ ==================
3. The problem is, that I'd like to process SAVE action. But default
provider for my EditorInput is StorageDocumentProvider, which
doSaveDocument method is empty:
============================================================ ==================
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
}
============================================================ ==================
So, I'm trying to register my own DocumentProvider:
============================================================ ==================
public class StringStorageDocumentProvider extends StorageDocumentProvider
{
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
... here do something ...
}
}
============================================================ ==================
by placing in my plugin.xml this block:
============================================================ ==================
<extension
point="org.eclipse.ui.editors.documentProviders">
<provider
class="test.jseditor.StringStorageDocumentProvider"
inputTypes="test.jseditor.SimpleEditorInput"
id="test.jseditor.StringStorageDocumentProvider">
</provider>
</extension>
============================================================ ==================
It works fine, when I'm using "org.eclipse.ui.DefaultTextEditor" - my
StringStorageDocumentProvider is generated in this case.
But when I'm using JavaScript editor
(org.eclipse.wst.jsdt.ui.CompilationUnitEditor) problem is still appears.
What do you think about this? May be it is bug/fault of JSDT plugin or
special restriction?
|
|
|
Re: Registering own IDocumentProvider for JavaScriptEditor [message #229488 is a reply to message #229384] |
Wed, 25 March 2009 09:53 |
Andrew Arapov Messages: 5 Registered: July 2009 |
Junior Member |
|
|
Andrew Arapov wrote:
> Hi!
> I'm trying to register my own IDocumentProvider, which extends
> StorageDocumentProvider.
> My steps are:
> 1. I have my own IStorageEditorInput, which provides editing some string
> without openning IFile
>
============================================================ ==================public
> class SimpleEditorInput implements IStorageEditorInput {
> private String inputString;
> public SimpleEditorInput(String inputString) {
> this.inputString = inputString;
> }
> public IStorage getStorage() throws CoreException {
> return new IStorage() {
> public InputStream getContents() throws CoreException {
> return IOUtils.toInputStream(inputString);
> }
> public IPath getFullPath() {
> return null;
> }
> public String getName() {
> return SimpleEditorInput.this.getName();
> }
> public boolean isReadOnly() {
> return false;
> }
> public Object getAdapter(Class adapter) {
> return null;
> }
> };
> }
> public boolean exists() {
> return true;
> }
> public ImageDescriptor getImageDescriptor() {
> return ImageDescriptor.getMissingImageDescriptor();
> }
> public String getName() {
> return "JSEditor";
> }
> public IPersistableElement getPersistable() {
> return null;
> }
> public String getToolTipText() {
> return "JSEditor Tool Tip Text";
> }
> public Object getAdapter(Class adapter) {
> return null;
> }
> public void setInputString(String inputString) {
> this.inputString = inputString;
> }
> }
>
============================================================ ==================
> 2. Next, I'm opennig JavaScriptEditor:
>
============================================================ ==================
> window.getActivePage().openEditor(new
>
SimpleEditorInput(TEST_JS_1),"org.eclipse.wst.jsdt.ui.CompilationUnitEditor ");
>
============================================================ ==================
> 3. The problem is, that I'd like to process SAVE action. But default
> provider for my EditorInput is StorageDocumentProvider, which
> doSaveDocument method is empty:
>
============================================================ ==================
> protected void doSaveDocument(IProgressMonitor monitor, Object element,
> IDocument document, boolean overwrite) throws CoreException {
> }
>
============================================================ ==================
> So, I'm trying to register my own DocumentProvider:
>
============================================================ ==================
> public class StringStorageDocumentProvider extends StorageDocumentProvider
> {
> @Override
> protected void doSaveDocument(IProgressMonitor monitor, Object element,
> IDocument document, boolean overwrite) throws CoreException {
> ... here do something ...
> }
> }
>
============================================================ ==================
> by placing in my plugin.xml this block:
>
============================================================ ==================
> <extension
> point="org.eclipse.ui.editors.documentProviders">
> <provider
> class="test.jseditor.StringStorageDocumentProvider"
> inputTypes="test.jseditor.SimpleEditorInput"
> id="test.jseditor.StringStorageDocumentProvider">
> </provider>
> </extension>
>
============================================================ ==================
> It works fine, when I'm using "org.eclipse.ui.DefaultTextEditor" - my
> StringStorageDocumentProvider is generated in this case.
> But when I'm using JavaScript editor
> (org.eclipse.wst.jsdt.ui.CompilationUnitEditor) problem is still appears.
> What do you think about this? May be it is bug/fault of JSDT plugin or
> special restriction?
up
|
|
|
|
Re: Registering own IDocumentProvider for JavaScriptEditor [message #229569 is a reply to message #229384] |
Wed, 25 March 2009 17:48 |
|
Andrew Arapov wrote:
> What do you think about this? May be it is bug/fault of JSDT plugin or
> special restriction?
It's intentional, just as it is with the Java editor. The JSDT
CompilationUnitEditor is hard-wired to use its own document
provider, CompilationUnitDocumentProvider, to make sure that the
partitioning setup in the IDocument is correct, as well as perform
some additional setup for handling as-you-type validation results.
As a workaround, you could open a file outside of the workspace, but
you'll need to open a feature request to get this changed...and if
you have suggestions on exactly how to change it, please let us know.
--
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational
_
Nitin Dahyabhai
Eclipse Web Tools Platform
|
|
|
|
Powered by
FUDForum. Page generated in 0.02786 seconds