|
|
Re: How to open correct XML editor for different XML documents [message #667205 is a reply to message #666972] |
Wed, 27 April 2011 12:26 |
Richard Adams Messages: 77 Registered: July 2009 Location: Edinburgh |
Member |
|
|
Hello Paul
Thanks for the help. I was a bit dense as I didn't see the contentTypeBinding
extension point sub element in the editor extension.
So I've done that, and created the following contentTypeBinding
<content-type
base-type="org.eclipse.core.runtime.xml"
describer="org.sedml.jlibsedml.editor.SEDMLContentDescriber "
id="org.sedml.jlibsedml.editor.sedmlBinding"
file-extensions="xml"
name="SEDML content type"
priority="normal">
</content-type>
My describer class extends XMLContentDescriber .
Running it through the debugger, the code is called (e.g., when a context menu is requested) and returns 'INVALID' if the file is the 'wrong' type of XML,as it should, but nonetheless, the editor still appears in the Open->With context menu. I.e., the INVALID seems to be ignored.
Am I missing something, to get the editor removed from the 'Open With' context menu?
Thank you,
Richard
Dr Richard Adams, University of Edinburgh
http://richardadams606blog.blogspot.com/
http://csbe.bio.ed.ac.uk/adams.php
|
|
|
|
Re: How to open correct XML editor for different XML documents [message #670157 is a reply to message #667377] |
Thu, 12 May 2011 21:40 |
Max Mising name Messages: 54 Registered: September 2010 |
Member |
|
|
I'm hoping someone can help me out with a similar problem. I've been trying to figure out this content type extension point for a while and this is what I have. In our application, we have plugins included that have files with .cfg extensions. Some of these plugins have xml in their cfg files and another has text. I have written a generic file browser for the plugins and I am trying to use this extension point to differentiate between the types of extensions and open the xml editor by default in one and the text editor by default on the other.
Right now I'm just trying to get my descriptor working, making sure it's getting used. It should deny all files and I'm thinking everything should default to the text editor when opened. Here it is:
public class TestContentDescriber implements ITextContentDescriber {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.content.IContentDescriber#describe(java.io.
* InputStream, org.eclipse.core.runtime.content.IContentDescription)
*/
@Override
public int describe(InputStream contents, IContentDescription description)
throws IOException {
System.out.println(contents + " : " + description);
return INVALID;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.runtime.content.IContentDescriber#getSupportedOptions()
*/
@Override
public QualifiedName[] getSupportedOptions() {
return new QualifiedName[] {};
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.runtime.content.ITextContentDescriber#describe(java.
* io.Reader, org.eclipse.core.runtime.content.IContentDescription)
*/
@Override
public int describe(Reader contents, IContentDescription description)
throws IOException {
System.out.println(contents + " : " + description);
return INVALID;
}
}
This is my extension point definition:
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
id="localizationContentType"
base-type="org.eclipse.core.runtime.xml"
name="Localization Content Type"
file-extensions="cfg"
priority="normal">
<describer
class="com.abc.def.TestContentDescriber">
</describer>
</content-type>
</extension>
What I'm expecting is that if I return VALID, the xml editor will open because my base-type is the core runtime xml contentId and if I return INVALID, text editor will be used. What I'm seeing is that even before my describer is called, IEditorRegistry.getImageDescritor(fileName) is returning the xml image for my cfg file and no matter what I return in my describer, the xml editor is used.
Any ideas
Thanks
Max
[Updated on: Thu, 12 May 2011 21:41] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03343 seconds