Home » Eclipse Projects » Eclipse Platform » How to make my editor support resources opened outside of the workspace?
|
Re: How to make my editor support resources opened outside of the workspace? [message #327343 is a reply to message #327342] |
Tue, 15 April 2008 21:51 |
Alex Le Messages: 649 Registered: July 2009 |
Senior Member |
|
|
AL wrote:
> Hi,
>
> My editor works fine with files from the workspace. But when I do a
> 'File->Open File', my editor gets invoked, but fails miserably, because
> the IEditorInput is FileStoreEditorInput and my document provider can't
> provider a document. My question is: How can I detect that a
> FileStoreEditorInput was given, so that I can create an document
> provider, using StorageDocumentProvider? Thanks.
I use Eclipse 3.3.2 on WINDOWS XP.
trace it down to StorageDocumentProvider.createDocument(Object element),
where 'element' is FileStoreEditorInput. Fails on the
setDocumentContent(...) call, thus return a null IDocument! Is this
expected behavior?
protected IDocument createDocument(Object element) throws CoreException {
if (element instanceof IEditorInput) {
IDocument document= createEmptyDocument();
if (setDocumentContent(document, (IEditorInput) element,
getEncoding(element))) { setupDocument(element, document);
return document;
}
}
return null;
}
|
|
|
Re: How to make my editor support resources opened outside of the workspace? [message #327344 is a reply to message #327343] |
Tue, 15 April 2008 23:29 |
Alex Le Messages: 649 Registered: July 2009 |
Senior Member |
|
|
AL wrote:
> AL wrote:
>> Hi,
>>
>> My editor works fine with files from the workspace. But when I do a
>> 'File->Open File', my editor gets invoked, but fails miserably,
>> because the IEditorInput is FileStoreEditorInput and my document
>> provider can't provider a document. My question is: How can I detect
>> that a FileStoreEditorInput was given, so that I can create an
>> document provider, using StorageDocumentProvider? Thanks.
>
> I use Eclipse 3.3.2 on WINDOWS XP.
>
> trace it down to StorageDocumentProvider.createDocument(Object element),
> where 'element' is FileStoreEditorInput. Fails on the
> setDocumentContent(...) call, thus return a null IDocument! Is this
> expected behavior?
>
> protected IDocument createDocument(Object element) throws CoreException {
> if (element instanceof IEditorInput) {
> IDocument document= createEmptyDocument();
> if (setDocumentContent(document, (IEditorInput) element,
> getEncoding(element))) { setupDocument(element, document);
> return document;
> }
> }
> return null;
> }
Getting somewhere, override the below method in my document provider
class, which extends FileDocumentProvider. Works but not able to edit
the opened file (the file outside of the workspace opened via
'File->Open File')...Tips???
@Override
protected IDocument createDocument(Object element) throws CoreException {
// Call super for the case of FileEditorInput.
IDocument doc = super.createDocument(element);
// File outside of the workspace? That is, opened via 'File->Open File'.
if (doc == null) {
if (element instanceof IURIEditorInput) {
IURIEditorInput ei = (IURIEditorInput)element;
doc = createEmptyDocument();
// Open the stream
InputStream is = null;
try {
is = ei.getURI().toURL().openStream();
setDocumentContent(doc, is, getEncoding(element));
// setupDocument(element, doc);
} catch (IOException ex) {
Activator.getDefault().log(IStatus.ERROR, ex);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException x) {
Activator.getDefault().log(IStatus.ERROR, x);
}
}
}
}
return doc;
}
|
|
|
Re: How to make my editor support resources opened outside of the workspace? [message #327345 is a reply to message #327344] |
Wed, 16 April 2008 00:04 |
Alex Le Messages: 649 Registered: July 2009 |
Senior Member |
|
|
AL wrote:
> AL wrote:
>> AL wrote:
>>> Hi,
>>>
>>> My editor works fine with files from the workspace. But when I do a
>>> 'File->Open File', my editor gets invoked, but fails miserably,
>>> because the IEditorInput is FileStoreEditorInput and my document
>>> provider can't provider a document. My question is: How can I detect
>>> that a FileStoreEditorInput was given, so that I can create an
>>> document provider, using StorageDocumentProvider? Thanks.
>>
>> I use Eclipse 3.3.2 on WINDOWS XP.
>>
>> trace it down to StorageDocumentProvider.createDocument(Object
>> element), where 'element' is FileStoreEditorInput. Fails on the
>> setDocumentContent(...) call, thus return a null IDocument! Is this
>> expected behavior?
>>
>> protected IDocument createDocument(Object element) throws CoreException {
>> if (element instanceof IEditorInput) {
>> IDocument document= createEmptyDocument();
>> if (setDocumentContent(document, (IEditorInput) element,
>> getEncoding(element))) { setupDocument(element,
>> document);
>> return document;
>> }
>> }
>> return null;
>> }
>
> Getting somewhere, override the below method in my document provider
> class, which extends FileDocumentProvider. Works but not able to edit
> the opened file (the file outside of the workspace opened via
> 'File->Open File')...Tips???
>
> @Override
> protected IDocument createDocument(Object element) throws
> CoreException {
>
> // Call super for the case of FileEditorInput.
> IDocument doc = super.createDocument(element);
>
> // File outside of the workspace? That is, opened via 'File->Open
> File'.
> if (doc == null) {
> if (element instanceof IURIEditorInput) {
> IURIEditorInput ei = (IURIEditorInput)element;
> doc = createEmptyDocument();
>
> // Open the stream
> InputStream is = null;
> try {
> is = ei.getURI().toURL().openStream();
> setDocumentContent(doc, is, getEncoding(element));
> // setupDocument(element, doc);
> } catch (IOException ex) {
> Activator.getDefault().log(IStatus.ERROR, ex);
> } finally {
> try {
> if (is != null) {
> is.close();
> }
> } catch (IOException x) {
> Activator.getDefault().log(IStatus.ERROR, x);
> }
> }
> }
> }
>
> return doc;
> }
Got it...One more override to my document provider class.
/**
* To support opening of non-workspace resource, that is, via
* "File->Open File".
*/
@Override
public boolean isModifiable(Object element) {
boolean modifiable = super.isModifiable(element);
if (!modifiable) {
// TODO: Should really make this as a preference setting, so
// that people can look at source-code-controlled file read-only.
modifiable = (element instanceof IURIEditorInput);
}
return modifiable;
}
|
|
| | | |
Re: How to make my editor support resources opened outside of the workspace? [message #327375 is a reply to message #327373] |
Wed, 16 April 2008 17:58 |
Alex Le Messages: 649 Registered: July 2009 |
Senior Member |
|
|
AL wrote:
> Daniel Megert wrote:
>> AL wrote:
>>> Hi,
>>>
>>> My editor works fine with files from the workspace. But when I do a
>>> 'File->Open File', my editor gets invoked, but fails miserably,
>>> because the IEditorInput is FileStoreEditorInput and my document
>>> provider can't provider a document. My question is: How can I detect
>>> that a FileStoreEditorInput was given, so that I can create an
>>> document provider, using StorageDocumentProvider? Thanks.
>> Do you really need your own document provider? Why not just use
>> TextFileDocumentProvider which handles this case?
>>
>> Dani
> Aha! Thanks! (I was searching for FileStoreDocumentProvider :-)
> (Should have searched "*DocumentProvider*".)
I spoke too soon...The TextFileDocumentProvider does the trick, but now
if I open resources (files) in the workspace, my none of my resource
related, such as, annotations, spelling checks, etc., does not work :-(
Is it because TextFileDocumentProvider only deals with non-workspace
resources? Thanks
|
|
|
Re: How to make my editor support resources opened outside of the workspace? [message #327386 is a reply to message #327375] |
Thu, 17 April 2008 08:30 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
AL wrote:
> AL wrote:
>> Daniel Megert wrote:
>>> AL wrote:
>>>> Hi,
>>>>
>>>> My editor works fine with files from the workspace. But when I do
>>>> a 'File->Open File', my editor gets invoked, but fails miserably,
>>>> because the IEditorInput is FileStoreEditorInput and my document
>>>> provider can't provider a document. My question is: How can I
>>>> detect that a FileStoreEditorInput was given, so that I can create
>>>> an document provider, using StorageDocumentProvider? Thanks.
>>> Do you really need your own document provider? Why not just use
>>> TextFileDocumentProvider which handles this case?
>>>
>>> Dani
>> Aha! Thanks! (I was searching for FileStoreDocumentProvider :-)
>> (Should have searched "*DocumentProvider*".)
>
> I spoke too soon...The TextFileDocumentProvider does the trick, but
> now if I open resources (files) in the workspace, my none of my
> resource related, such as, annotations, spelling checks, etc., does
> not work :-( Is it because TextFileDocumentProvider only deals with
> non-workspace resources?
No, it works for resources and everything that's backed by a file store
(e.g. local files). Not sure why it's not working in your case. I
suspect that the annotation model is 'null' for some reason.
Dani
> Thanks
|
|
| | |
Goto Forum:
Current Time: Sun Nov 03 06:45:00 GMT 2024
Powered by FUDForum. Page generated in 0.03954 seconds
|