Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Registering own IDocumentProvider
Registering own IDocumentProvider [message #335031] Tue, 17 March 2009 13:19 Go to next message
Andrew Arapov is currently offline Andrew ArapovFriend
Messages: 5
Registered: July 2009
Junior Member
Hello!
Let me describe my problem.

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 any Editor (for example:
window.getActivePage().openEditor(new
SimpleEditorInput(TEST_JS_1),"org.eclipse.ui.DefaultTextEditor ");
or
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="org.eclipse.ui.IStorageEditorInput"
id="test.jseditor.StringStorageDocumentProvider">
</provider>
</extension>

But this doesn't work!

Please, help me. What do I wrong?
Re: Registering own IDocumentProvider [message #335047 is a reply to message #335031] Thu, 19 March 2009 10:37 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Andrew Arapov wrote:
> Hello!
> Let me describe my problem.
See my answer in eclipse.platform.rcp.

Dani
>
> 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 any Editor (for example:
> window.getActivePage().openEditor(new
> SimpleEditorInput(TEST_JS_1),"org.eclipse.ui.DefaultTextEditor ");
> or
> 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="org.eclipse.ui.IStorageEditorInput"
> id="test.jseditor.StringStorageDocumentProvider">
> </provider>
> </extension>
>
> But this doesn't work!
>
> Please, help me. What do I wrong?
>
>
Previous Topic:Toggle Menu Item
Next Topic:Annotation for problemMarkers
Goto Forum:
  


Current Time: Wed Apr 24 15:47:46 GMT 2024

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

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

Back to the top