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 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Alex Le![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=unbonnevie%40yahoo.com) 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 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Alex Le![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=unbonnevie%40yahoo.com) 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 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Alex Le![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=unbonnevie%40yahoo.com) 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 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Alex Le![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=unbonnevie%40yahoo.com) 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 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Dani Megert![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=Daniel_Megert%40ch.ibm.com) 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: Sat Aug 24 03:53:23 GMT 2024
Powered by FUDForum. Page generated in 0.04353 seconds
|