Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Obtaining the default editor for a file type programmatically?
Obtaining the default editor for a file type programmatically? [message #301170] Fri, 24 March 2006 08:10 Go to next message
Eclipse UserFriend
This is a multi-part message in MIME format.

------=_NextPart_000_005B_01C64F44.631886C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi
Does anyone know how to get hold of the default editor for a file =
type programmatically?

I have tried using this;

IEditorDescriptor d =3D =
PlatformUI.getWorkbench().getEditorRegistry().getDefaultEdit or( ".xml");
text =3D (AbstractTextEditor) =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().
getActivePage().openEditor(editorInput, d.getId(), false);

However this gives me two side effects of which I don't want.
The first is the editor descriptor specifies an EditorInput and I want =
specify my own.=20
The second is that (I know this is obvious) the editor is opened in the =
editor pane. I want to obtain the IEditorPart and place it within my =
MultiPartEditor.

The reason why I used openEditor is that I could see no other way of =
getting the IEditorPart without using internal stuff such as =
creatEditor()=20

Anyone have any ideas?


thanks



------=_NextPart_000_005B_01C64F44.631886C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1528" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Does anyone know how =
to get hold=20
of the default editor for a file type </FONT><FONT face=3DArial=20
size=3D2>programmatically</FONT><FONT face=3DArial =
size=3D2>?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have tried using this;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>IEditorDescriptor d =3D=20
PlatformUI.getWorkbench().getEditorRegistry().getDefaultEdit or( ".xml");<B=
R> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;text=20
=3D (AbstractTextEditor)=20
PlatformUI.getWorkbench().getActiveWorkbenchWindow().<BR>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;getActivePage().openEditor(editorIn=
put,=20
d.getId(), false);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>However this gives me two side effects =
of which I=20
don't want.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The first is the editor descriptor =
specifies an=20
EditorInput and I want specify my own. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The second is that (I know this is =
obvious) the=20
editor is opened in the editor pane. I want to obtain the IEditorPart =
and place=20
it within my MultiPartEditor.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The reason why I used openEditor is =
that I could=20
see no other way of getting the IEditorPart without using internal=20
stuff&nbsp;such as creatEditor()&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anyone have any ideas?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_005B_01C64F44.631886C0--
Re: Obtaining the default editor for a file type programmatically? [message #301174 is a reply to message #301170] Fri, 24 March 2006 08:48 Go to previous messageGo to next message
Eclipse UserFriend
Martin Holmes wrote:
>
> The reason why I used openEditor is that I could see no other way of
> getting the IEditorPart without using internal stuff such as creatEditor()
>

As you found out, there isn't a way to do this without writing your one
code.

Basically, you have the editor id from the IEditorDescription. You now
need to walk through the IConfigurationElements for the
org.eclipse.ui.editors extension point and find the
IConfigurationElement that matches your id.

Then you can use createExecutableExtension() to get the correct EditorPart.

Later,
PW
Re: Obtaining the default editor for a file type programmatically? [message #301192 is a reply to message #301174] Fri, 24 March 2006 12:12 Go to previous message
Eclipse UserFriend
Thanks Paul,
the extension point approach worked I was just begining to
think it was possible to solve my problem.

heres my code

private IConfigurationElement getUIEditorConfigElement(String id){
IEditorDescriptor d =
PlatformUI.getWorkbench().getEditorRegistry().getDefaultEdit or(id);
IExtensionRegistry registry = RegistryFactory.getRegistry();
IExtensionPoint ext =
registry.getExtensionPoint("org.eclipse.ui.editors");
IConfigurationElement [] configElements =
ext.getConfigurationElements();
for (IConfigurationElement element : configElements) {
String className = element.getAttributeAsIs("class");
if( d.getId().equals(className)){
return element;
}
}
return null;
}

Object of = i.createExecutableExtension("class");


All I need todo now is to fix my "unsupported content type" error!



"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:e00tfe$96n$1@utils.eclipse.org...
> Martin Holmes wrote:
> >
> > The reason why I used openEditor is that I could see no other way of
> > getting the IEditorPart without using internal stuff such as
creatEditor()
> >
>
> As you found out, there isn't a way to do this without writing your one
> code.
>
> Basically, you have the editor id from the IEditorDescription. You now
> need to walk through the IConfigurationElements for the
> org.eclipse.ui.editors extension point and find the
> IConfigurationElement that matches your id.
>
> Then you can use createExecutableExtension() to get the correct
EditorPart.
>
> Later,
> PW
Previous Topic:Problem with regsitration of Workbench Plugin in Eclipse Debug session
Next Topic:how to disable an IWorkbenchWindowActionDelegate?
Goto Forum:
  


Current Time: Sun Nov 09 23:02:07 EST 2025

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

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

Back to the top