Created
July 30, 2010 02:14
-
-
Save owenthereal/499743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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