Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to make my editor support resources opened outside of the workspace?
How to make my editor support resources opened outside of the workspace? [message #327342] Tue, 15 April 2008 21:01 Go to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
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.
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 messageGo to next message
Alex Le is currently offline Alex LeFriend
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 messageGo to next message
Alex Le is currently offline Alex LeFriend
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 messageGo to next message
Alex Le is currently offline Alex LeFriend
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 #327346 is a reply to message #327345] Wed, 16 April 2008 00:31 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
>
> Got it...One more override to my document provider class.
>

Not really...Allow me to edit and save, but actually does not save at
all! Need to override
AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object,
IDocument, boolean). Is there an implementation out there? Or I am
heading the wrong direction? Thanks.

> /**
> * 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 #327359 is a reply to message #327342] Wed, 16 April 2008 12:38 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
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.
Do you really need your own document provider? Why not just use
TextFileDocumentProvider which handles this case?

Dani
Re: How to make my editor support resources opened outside of the workspace? [message #327373 is a reply to message #327359] Wed, 16 April 2008 17:45 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
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*".)
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 messageGo to next message
Alex Le is currently offline Alex LeFriend
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 messageGo to next message
Dani Megert is currently offline Dani MegertFriend
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
Re: How to make my editor support resources opened outside of the workspace? [message #327413 is a reply to message #327386] Fri, 18 April 2008 02:16 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
Daniel Megert wrote:

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

Yes, the annotation model is null using TextFileDocumentProvider.
Haven't got a chance to find out why.

I did a test by opening a Java file outside of the workspace. It opens
with syntax coloring, etc., but I can't put a TODO marker on the file. :-(
Re: How to make my editor support resources opened outside of the workspace? [message #327414 is a reply to message #327413] Fri, 18 April 2008 02:17 Go to previous message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
AL wrote:
> Daniel Megert wrote:
>
>> 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.
>>
>
> Yes, the annotation model is null using TextFileDocumentProvider.
> Haven't got a chance to find out why.
>
> I did a test by opening a Java file outside of the workspace. It opens
> with syntax coloring, etc., but I can't put a TODO marker on the file. :-(

Same for *.txt files. If opened outside of the workspace, can't put a
bookmark or a todo task, since that markers are associated to workspace
resources.
Previous Topic:Button in the titlebar of a section?
Next Topic:Re: Can I customize when the plug-in be loaded?
Goto Forum:
  


Current Time: Mon Jul 22 00:19:02 GMT 2024

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

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

Back to the top