Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Registering own IDocumentProvider for JavaScriptEditor
Registering own IDocumentProvider for JavaScriptEditor [message #229384] Mon, 23 March 2009 06:36 Go to next message
Andrew Arapov is currently offline Andrew ArapovFriend
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 Go to previous messageGo to next message
Andrew Arapov is currently offline Andrew ArapovFriend
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 #229493 is a reply to message #229384] Wed, 25 March 2009 09:54 Go to previous messageGo to next message
Andrew Arapov is currently offline Andrew ArapovFriend
Messages: 5
Registered: July 2009
Junior Member
up
Re: Registering own IDocumentProvider for JavaScriptEditor [message #229569 is a reply to message #229384] Wed, 25 March 2009 17:48 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

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
Re: Registering own IDocumentProvider for JavaScriptEditor [message #229799 is a reply to message #229569] Mon, 30 March 2009 07:29 Go to previous message
Andrew Arapov is currently offline Andrew ArapovFriend
Messages: 5
Registered: July 2009
Junior Member
Nitin Dahyabhai wrote:

> 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.

Hi! Thank you for reply.

I would like to suggest you simple create some external wrapper for
saveDocument method.
May be it could be something like:

//=================================
if (saveWrapper == null) return;
saveWrapper.doSave(...);
//=================================

I think it could be configured in plugin.xml...
Previous Topic:Early testers wanted for M6 update site and all-in-one packages
Next Topic:How to change the code in jar file
Goto Forum:
  


Current Time: Tue Apr 23 17:02:35 GMT 2024

Powered by FUDForum. Page generated in 0.02786 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top