Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Link a custom EditorInput to a resource type
Link a custom EditorInput to a resource type [message #539085] Wed, 09 June 2010 11:25 Go to next message
Guillaume P. is currently offline Guillaume P.
Messages: 69
Registered: June 2010
Location: Toulouse, France
Member
Hello,

I am currently trying to open a customized editor when the user double-click on a *.myExtension file in the package explorer (or another explorer type).

The problem is that my editor needs, during initialization, some informations which are not in the file. The solution I fund is to create a new implementation of IEditorInput interface (MyEditorInput) containing these extra informations. The system works when I create myself the MyEditorInput instance before using it with the IWorkbenchPage.openEditor(...) function.

But the problem is when the user accesses the editor via the package explorer (I've used here the org.eclipse.ui.editors extension point). Here a simple IFileEditorInput is created...

I tried to override the EditorPart.init(IEditorSite site, IEditorInput input) in order to transform the IFileEditorInput to a MyEditorInput before calling the super.init(...) with the new editor input, but it is too late.

I have also tried to use the org.eclipse.ui.navigator.LinkHelper extension point:

   <extension point="org.eclipse.ui.navigator.linkHelper">
      <linkHelper
            class="myPlugin.workbench.editors.MyLinkHelper"
            id="myPlugin.workbench.myLinkHelper">
         <editorInputEnablement>
            <instanceof
                  value="myPlugin.workbench.utils.MyFileEditorInput">
            </instanceof>
         </editorInputEnablement>
         <selectionEnablement>
            <instanceof
                  value="org.eclipse.core.resources.IFile">
            </instanceof>
         </selectionEnablement>
      </linkHelper>
   </extension>


with the org.eclipse.ui.navigator.viewer extension point:

   <extension
         point="org.eclipse.ui.navigator.viewer">
      <viewerContentBinding
            viewerId="org.eclipse.jdt.ui.PackageExplorer">
         <includes>
            <contentExtension
                  pattern="myPlugin.workbench.myLinkHelper">
            </contentExtension></includes>
      </viewerContentBinding>
   </extension>


... but it does nothing (the MyLinkHelper is not used)... Moreover, this extension point seems to be specific to only one navigator view, while the file can be opened from several type of navigators views (Package explorer, Project explorer, ...)


Could someone help me, please ? :-/

[Updated on: Thu, 10 June 2010 04:04]

Report message to a moderator

Re: Link another type of EditorInput to some resources [message #539294 is a reply to message #539085] Thu, 10 June 2010 05:46 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2237
Registered: July 2009
Senior Member
On 6/9/2010 11:25 AM, pelouas@gmail.com wrote:
> I am currently trying to open a customized editor when the user
> double-click on a *.myExtension file in the package explorer (or another
> explorer type).
>
> The problem is that my editor needs, during initialization, some
> informations which are not in the file. The solution I fund is to create
> a new implementation of IEditorInput interface (MyEditorInput)
> containing these extra informations.

Perhaps you should review what that information is and whether it really
needs to be in the editor input object.

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Link a custom EditorInput to a resource type [message #539308 is a reply to message #539085] Thu, 10 June 2010 07:08 Go to previous messageGo to next message
Guillaume P. is currently offline Guillaume P.
Messages: 69
Registered: June 2010
Location: Toulouse, France
Member
Yes, I really need these extra informations:
The file I am opening contains a model definition, while the opened editor presents a model instance (so asking to open the file two times will open two instances, instead of re-opening the same editor). The extra informations are related to this instance, in order to be able to differentiate each editor, and in order to display information specific to the instance.
Re: Link a custom EditorInput to a resource type [message #539533 is a reply to message #539308] Fri, 11 June 2010 04:30 Go to previous messageGo to next message
Guillaume P. is currently offline Guillaume P.
Messages: 69
Registered: June 2010
Location: Toulouse, France
Member
Do nobody knows a solution ? I am working on this problem since 3 days now :-/ I am becoming really desperate...

Why the linkHelper extension point doesn't works ?
Re: Link another type of EditorInput to some resources [message #539585 is a reply to message #539085] Fri, 11 June 2010 08:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

1) you can provide an editor match strategy with your
org.eclipse.ui.editors definition. That way you can only open one
editor if there is an existing editor open that matches your "input".
For example, the PDE editor uses this so double-clicking on a
MANIFEST.MF will activate the PDE editor open on the matching
plugin.xml, instead of trying to open a new editor.

2) you can create an editor definition that uses a launcher instead of a
class. That launcher can build a new input and call
IWorkbenchPage.openEditor(*) with your input and an editorId that can
display it (not the same as your launcher).

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: Link another type of EditorInput to some resources [message #539590 is a reply to message #539585] Fri, 11 June 2010 09:09 Go to previous messageGo to next message
Guillaume P. is currently offline Guillaume P.
Messages: 69
Registered: June 2010
Location: Toulouse, France
Member
The first solution is not what I want: I need a new different editor to be opened each time I double-click the file in navigator.

But the second solution is exactly what I needed !!! Like this I can open programmatically each editor for my file type, and so setting a different editor input for each of them Smile

The last problem is that I can see now the two editor types in the "Open with..." > "Other..." menu, while the real editor (not the launcher) should never be used directly. Is it possible to hide the real editor to the user ?

Thank you very much for your help ! You are saving me ! Smile
Re: Link another type of EditorInput to some resources [message #539600 is a reply to message #539590] Fri, 11 June 2010 09:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Guillaume P. wrote:
>
> The last problem is that I can see now the two editor types in the "Open
> with..." > "Other..." menu, while the real editor (not the launcher)
> should never be used directly. Is it possible to hide the real editor to
> the user ?

What if you don't put an extension on the real editor? If it still gets
shown despite that in the "Other..." dialog, I don't believe there's
anything you can do about it.

Except check your IEditorInput when it arrives and if it is something
other than your editor input class, throw a PartInitException and say
"don't use this 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: Link another type of EditorInput to some resources [message #539608 is a reply to message #539600] Fri, 11 June 2010 09:36 Go to previous message
Guillaume P. is currently offline Guillaume P.
Messages: 69
Registered: June 2010
Location: Toulouse, France
Member
No, letting the extension empty doesn't resolve the problem... I will search a little more, and I will show this error if I don't found a cleaner solution.

I just want to come back to the linkHelper extension: I hadn't understood its correct utility. It's not for producing editor input from a selected resource in a navigator, but, as described at the top of the extension point description Rolling Eyes , it's for overriding the "Link with editor" button behaviour... Mea culpa.

Well, really thank you for your help Paul Webster Surprised
Previous Topic:Managing API-Leaks
Next Topic:Change eclipse workspace programmatically
Goto Forum:
  


Current Time: Wed Jul 30 01:04:05 EDT 2014

Powered by FUDForum. Page generated in 0.07281 seconds