Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-ui-dev] Registering own IDocumentProvider

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?

Thank you very much.







Back to the top