Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Problem with IDE.openEditor(URI): cannot open external file in UTF8
Problem with IDE.openEditor(URI): cannot open external file in UTF8 [message #330944] Mon, 18 August 2008 20:57 Go to next message
Sergey Bushkov is currently offline Sergey BushkovFriend
Messages: 29
Registered: July 2009
Junior Member
Good day,

I need to open an external file in editor. The following code works in
eclipse 3.3 for files in default system encoding:

IEditorPart part = IDE.openEditor(page, file.toURI(),
"org.eclipse.jdt.debug.ui.SnippetEditor", true);

I can't find any API to open that file in non-system encoding, e.g. UTF-8.

It's possible to change the default workbench encoding on the workbench
properties page; after that, the editor opens UTF-8 files correctly.
However, I don't want to change the entire workspace settings - user
preferences should be respected.

Is there any workaround?

Thanks
/Sergey
Re: Problem with IDE.openEditor(URI): cannot open external file in UTF8 [message #330950 is a reply to message #330944] Tue, 19 August 2008 12:08 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Sergey Bushkov wrote:
> Good day,
>
> I need to open an external file in editor. The following code works in
> eclipse 3.3 for files in default system encoding:
>
> IEditorPart part = IDE.openEditor(page, file.toURI(),
> "org.eclipse.jdt.debug.ui.SnippetEditor", true);
>
> I can't find any API to open that file in non-system encoding, e.g.
> UTF-8.
>
> It's possible to change the default workbench encoding on the
> workbench properties page; after that, the editor opens UTF-8 files
> correctly. However, I don't want to change the entire workspace
> settings - user preferences should be respected.
>
> Is there any workaround?
You could set the preference (use putValue to prevent firing of property
change events), open the editor and set it back. Another thing you could
try is to open it with the wrong encoding and then set yours:
IEncodingSupport encodingSupport=
(IEncodingSupport)part.getAdapter(IEncodingSupport.class);
encodingSupport.setEncoding(String);

Dani
>
> Thanks
> /Sergey
Re: Problem with IDE.openEditor(URI): cannot open external file in UTF8 [message #330966 is a reply to message #330950] Tue, 19 August 2008 18:27 Go to previous message
Sergey Bushkov is currently offline Sergey BushkovFriend
Messages: 29
Registered: July 2009
Junior Member
Thanks for ideas, Daniel!

The second workaround does not work for me because the snippet editor
does not return adapter for IEncodingSupport (at least, in eclpse 3.3).

The first workaround.. well, I could not find which property should be
changed. But - instead - I found the better solution for my problem:

<extension point="org.eclipse.core.runtime.contentTypes">
<content-type
id = "xyz.my.id"
name = "xyz"
file-extensions="xyz"
default-charset="UTF-8"
...
/>
</extension>

This works fine for me, since I want to open files with specific
extension. So, you helped me actually :)

/Sergey

Daniel Megert wrote:
> Sergey Bushkov wrote:
>
>> Good day,
>>
>> I need to open an external file in editor. The following code works in
>> eclipse 3.3 for files in default system encoding:
>>
>> IEditorPart part = IDE.openEditor(page, file.toURI(),
>> "org.eclipse.jdt.debug.ui.SnippetEditor", true);
>>
>> I can't find any API to open that file in non-system encoding, e.g.
>> UTF-8.
>>
>> It's possible to change the default workbench encoding on the
>> workbench properties page; after that, the editor opens UTF-8 files
>> correctly. However, I don't want to change the entire workspace
>> settings - user preferences should be respected.
>>
>> Is there any workaround?
>
> You could set the preference (use putValue to prevent firing of property
> change events), open the editor and set it back. Another thing you could
> try is to open it with the wrong encoding and then set yours:
> IEncodingSupport encodingSupport=
> (IEncodingSupport)part.getAdapter(IEncodingSupport.class);
> encodingSupport.setEncoding(String);
>
> Dani
>
>>
>> Thanks
>> /Sergey
Previous Topic:adding validation to a TextEditor
Next Topic:Packaging rcp application
Goto Forum:
  


Current Time: Thu Dec 26 14:42:34 GMT 2024

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

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

Back to the top