Reputation:
When i am selecting a file in the project explorer, it should allow me to open my editor instead it shows text editor.How can we handle this programmatically in eclipse plugin development ?
regards Mathan
Upvotes: 1
Views: 584
Reputation: 1893
There is also possibility to register your own content type of file. It can be registered as a sub-type of existing content type i.e. XML. To do that you should add an extension point of org.eclipse.core.contenttype.contentTypes
Sample extension point:
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.xml"
default-charset="UTF-8"
describer="com.example.MyContentDescriber"
file-extensions="xml"
id="org.eclipse.core.runtime.xml.exampleContentType"
name="exampleContentType"
priority="normal">
</content-type>
As you can see new content type is extending an xml content type. The next step is to implement content describer, which looks into the file and determines if it is of your type. There are two interfaces you can implement to do the job: IContentDescriber
or ITextContentDescriber
. Path to your implementation of describer must be specified in content type as it is shown in the snippet.
Then your editor can be declared as the one, who will be handling your kind of content types.
<editor class="com.example.MyEditor"
default="true"
icon="res/icons/dialog.png"
id="[some_id]"
name="Dialog editor">
<contentTypeBinding
contentTypeId="org.eclipse.core.runtime.xml.exampleContentType">
</contentTypeBinding>
</editor>
Important things:
More in the topic: ECLIPSE: Contributing content types
Upvotes: 1
Reputation: 19443
Using the file extension method is preferred because that's easy. However if you can't do that, then the only alternative I know of is to provide an action provider in the Common Navigator configuration.
You will need to subclass CommonActionProvider and in the fillContextMenu() method you can look at the resource and then decide to have your own Open action (for your editor) or add the standard Open action.
Upvotes: 0
Reputation: 17593
Any plugin that contributes an editor to the workbench can associate an extension the editor understands in their plugin.xml.
The extensions attribute describes the file types that the editor understands. (You could also specify filenames if you need to be more specific.)
I believe this is enough to make your editor open when you click a file of your extension. (at least be preferred the first time you open the file. i.e. eclipse will prefer the last used editor for that file that session).
Upvotes: 0
Reputation: 12257
Window - Preferences - General - Editors - File Associations
Their you can select which editor is open, for the different file endings.
When you want to do this with a self implemented editor you have to implement the extension poin for editors
org.eclipse.ui.editors
The field "extensions" defines which file ending is associated to the editor
Upvotes: 1