| Get editor for file [message #302282] | 
Tue, 18 April 2006 15:05   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
In my Eclipse application, I have a need to embed individual editors  
within a single multipage editor part.  I have historically just known  
(read as hardcoded) the editor to be included.  However, I would really  
prefer to get the editor at runtime using the editor registry, etc.  I  
seem to be having two (2) problems with this, though. 
 
1) I have registered new content types with the platform, but when I try  
to get the default editor for a file (using  
org.eclipse.ui.ide.IDE#getDefaultEditor(IFile)) I get nothing in return.  
  I have stepped through the code and it seems that the  
 org.eclipse.core.internal.resources.ContentDescriptionManage r is unable  
to find the content type for my file.  Therefore, I stopped using  
IDE#getDefaultEditor(IFile) in favor of IDE#getEditorDescriptor(IFile)  
which simply returns the default text editor, since it can't find the  
*actual* default editor.  This leads to problem #2. 
 
2) When I manage to get af org.eclipse.ui.IEditorDescriptor, it is not  
very straightforward to get an instance of the actual  
org.eclipse.ui.IEditorPart.  The javadoc insists that once I have the  
IEditorDescriptor, that I have everything I need to instantiate the  
IEditorPart.  I'm sure I'm missing something.  I have been digging  
through the code trying to find a good way of getting the IEditorPart.  
The org.eclipse.ui.internal.EditorManager class has some lovely methods  
(openEditor(), openEditorFromDescriptor(), etc.), but I am unable to use  
them.  Either because they are private, or because I'm not really  
supposed to use EditorManager anyway, because it is in an *.internal.*  
package. 
 
So bottom line: Is there a slick way of dynamically getting a new  
instance of the IEditorPart for a given IFile? 
 
Thanks for your patience and help, 
Keith
 |  
 |  
  | 
 | 
| Re: Get editor for file [message #302378 is a reply to message #302313] | 
Wed, 19 April 2006 15:04   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Paul Webster wrote: 
> There's no public API that allows you to create an editor outside of the  
> framework.  However, the framework uses public API to instantiate one. 
>  
>  http://dev.eclipse.org/newslists/news.eclipse.platform/msg52 958.html 
>  
> You can search the newsgroups using google.  I use searches that start  
> with "site:dev.eclipse.org news.eclipse" 
>  
> Later, 
> PW 
 
That's what I ended up doing (navigating through the extension registry  
until I found the right IConfigurationElement and instantiated it that  
way).  I guess the thing that is really frustrating is that  
EditorDescriptor (the only implementation of IEditorDescriptor) has a  
method for getting the IConfigurationElement, but EditorDescriptor is  
*internal*.  On the other hand, if one can manage to get a hold of an  
IEditorReference, the editor could be created that way, but there is no  
public way of getting one of those either.  There is only one  
implementation of IEditorReference (EditorReference) which is also  
*internal*, so there really is no *good* way to get an instance of an  
editor at runtime. 
 
Thanks for the help, though. 
Keith
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.23561 seconds