Opening a default editor, on a treeviewer selection eclipse rcp(eg: as eclipse knows that j.java files must be opened in text editor)

好久不见. 提交于 2019-12-11 04:33:00

问题


I have a file with extension .xyz .i want to open an editor when it is double clicked How to go about doing it.I have a treeviewer that lists only my files that i need ,in those i have a .xyz file.I have added an editor in the extension point and in the extensions textfield i hav e added .xyz also.I dont want to add a doubleclicklistener to the viewer.Is there a way to add or tell eclipse that if this is the extension of the file then by default it should open.


回答1:


Well if you have your own viewer implementation you will need to define the complete behavior in that viewer, even the opening of files. Since you have registered an editor against that extension so whenever that file is opened in Eclipse, either by your viewer or some other viewer (Project Explorer, Navigator) Eclipse will automatically open the file in the assigned editor.

In your double click listener you can use org.eclipse.ui.actions.OpenFileAction or something like it to ensure that the file is opened by Eclipse according to Workbench rules. Btw why do you want to avoid adding a double click listener?




回答2:


You need to add an org.eclipse.ui.editors extension point.

 <extension point="org.eclipse.ui.editors">
  <editor
        name="MyEditor Name"
        extensions="my_file_extension"
        icon="icons/sample.gif"
        class="com.me.MyEditor"
        id="com.me.MyEditorID">
  </editor>



来源:https://stackoverflow.com/questions/14374921/opening-a-default-editor-on-a-treeviewer-selection-eclipse-rcpeg-as-eclipse-k

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!