Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Possible to contribute an "editor factory" for specific resources?
Possible to contribute an "editor factory" for specific resources? [message #507319] Tue, 12 January 2010 22:04 Go to next message
Eric Rizzo is currently offline Eric Rizzo
Messages: 2252
Registered: July 2009
Senior Member
I'm familiar with the org.eclipse.ui.editors extension point for
registering a custom editor to open with a specific file type (or
types). What I need to do is a more complex decision about the type of
editor to open based on the contents of the selected IFile. In other
words, depending on the actual file contents I need to open an
appropriate custom EditorPart (actually, custom FormEditor classes); I
have several such custom editors, each appropriate for different files
based on their contents.
I don't think I can just specify a class attribute for the
org.eclipse.ui.editors extension point, since that EditorPart seems to
be instantiated before I have a chance to get involved in the decision.
Specifying an IEditorLauncher (via the "launcher" extension point
attribute) looks somewhat promising, although the docs for it indicate
it is intended for external editors. Would there be any problems in
using an IEditorLauncher for my purposes (to open an internal editor)?
Would that be a horrible abuse of the launcher attribute?

Are there any other solutions for deciding which editor class to open
based on file contents?

Thanks in advance,
Eric
Re: Possible to contribute an "editor factory" for specific resources? [message #507524 is a reply to message #507319] Wed, 13 January 2010 18:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

are the file extensions the same? i.e. if they're all .mdl you can use
content type to analyze the file (well, the first 100 bytes) and then
use the content types to pick editors. Content type is to distinguish
between files that have the same file extension.

If you use IEditorLauncher please be sure to conform to the API. But if
you do that, you could use this method (I've seen it used to open a view
for a resource instead of opening an editor).

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Possible to contribute an "editor factory" for specific resources? [message #507545 is a reply to message #507524] Wed, 13 January 2010 19:36 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric Rizzo
Messages: 2252
Registered: July 2009
Senior Member
On 1/13/10 1:37 PM, Paul Webster wrote:
> are the file extensions the same? i.e. if they're all .mdl you can use
> content type to analyze the file (well, the first 100 bytes) and then
> use the content types to pick editors. Content type is to distinguish
> between files that have the same file extension.

This is actually for Java source files and I need to analyze an unknown
amount of the file contents (because .java files can be so freely
formatted/composed), so I don't think content-types can help in this
case; but please correct me if that analysis is flawed in any way.


> If you use IEditorLauncher please be sure to conform to the API. But if
> you do that, you could use this method (I've seen it used to open a view
> for a resource instead of opening an editor).

The IEditorLauncher interface is so simple that there is really no API
contract; the Javadoc does specifically talk about external editors,
though, which is why I've asked the question (to make sure there is no
implied contract somewhere in the code that uses IEditorLauncher instances).

Eric
Re: Possible to contribute an "editor factory" for specific resources? [message #507556 is a reply to message #507545] Wed, 13 January 2010 20:01 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Eric Rizzo wrote:
>
> The IEditorLauncher interface is so simple that there is really no API
> contract; the Javadoc does specifically talk about external editors,
> though, which is why I've asked the question (to make sure there is no
> implied contract somewhere in the code that uses IEditorLauncher
> instances).

I don't believe so (the API is almost nothing :-). I think it's OK to
use it, although the problem might be how to pick your launcher for
..java vs the actual CompilationUnitEditor.

We use it in the SDK, see the subclasses like
org.eclipse.jdt.internal.ui.jarpackager.OpenJarExportWizardE ditorLauncher

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Possible to contribute an "editor factory" for specific resources? [message #510555 is a reply to message #507319] Wed, 27 January 2010 19:52 Go to previous message
Eric Rizzo is currently offline Eric Rizzo
Messages: 2252
Registered: July 2009
Senior Member
Just wanted to follow-up to say that specifying an IEditorLauncher (via the "launcher" extension point attribute) worked out just fine,in case someone stumbles on this thread in the future...
Previous Topic:Eclipse CVS Client - running in Windows - CVS folder conflict
Next Topic:Eclipse with Java 6
Goto Forum:
  


Current Time: Tue Sep 23 12:29:57 GMT 2014

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

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