Skip to content

Instantly share code, notes, and snippets.

@owenthereal
Created July 30, 2010 02:14
Show Gist options
  • Save owenthereal/499743 to your computer and use it in GitHub Desktop.
Save owenthereal/499743 to your computer and use it in GitHub Desktop.
<extension point="com.luxoft.eclipse.fit.runner.fitSourceEditor">
<sourceeditor class="org.eclipse.wst.sse.ui.StructuredTextEditor" id="com.luxoft.eclipse.fit.runner.optional.wtpHTMLEditor">
</sourceeditor>
</extension>
<element name="extension">
<complextype>
<sequence>
<element ref="sourceEditor"></element>
</sequence>
...
</complextype>
</element>
<element name="sourceEditor">
<complextype>
<attribute name="id" type="string" use="required">
...
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<appinfo>
<meta.attribute kind="java" basedon=":org.eclipse.ui.texteditor.ITextEditor">
</meta.attribute>
</appinfo>
</annotation>
</attribute>
</complextype>
</element>
public class SourceEditorFactory {
private static IConfigurationElement cachedConfigurationElement;
private static final String ATTRIBUTE_CLASS = "class";
public static ITextEditor createSourceEditor() {
if (cachedConfigurationElement == null) {
cachedConfigurationElement = readConfigurationElement();
}
if (cachedConfigurationElement != null) {
try {
return (ITextEditor) cachedConfigurationElement
.createExecutableExtension(ATTRIBUTE_CLASS);
} catch (Exception exception) {
// errors when initializing the source editor
}
}
return new TextEditor();
}
// Reads the first configuration element whose implemented class is not
// TextEditor
private static IConfigurationElement readConfigurationElement() {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(FitPlugin.PLUGIN_ID, "fitSourceEditor");
for (IConfigurationElement configurationElement : extensionPoint
.getConfigurationElements()) {
if (!StringUtils.equals(TextEditor.class.getCanonicalName(),
configurationElement.getAttribute(ATTRIBUTE_CLASS))) {
return configurationElement;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment