Created
July 28, 2010 21:07
-
-
Save owenthereal/496301 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
public TextEditor createHTMLTextEditor() { | |
try { | |
Class cls = Class | |
.forName("org.eclipse.wst.sse.ui.StructuredTextEditor"); | |
for (Constructor constructor : cls.getDeclaredConstructors()) { | |
if (constructor.getGenericParameterTypes().length == 0) { | |
return (TextEditor) constructor.newInstance(new Object[0]); | |
} | |
} | |
} catch (Throwable throwable) { | |
// couldn't find the WTP plugin | |
} | |
return new TextEditor(); | |
} |
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
private static final String HTML_EDITOR_ID = "org.eclipse.wst.sse.ui.StructuredTextEditor"; | |
private static final String ATTRIBUTE_CLASS = "class"; | |
private static final String ATTRIBUTE_ID = "id"; | |
private static final String EDITOR_EXTENSION_POINT_ID = "org.eclipse.ui.editors"; | |
public TextEditor createHTMLTextEditor() { | |
try { | |
IExtensionPoint extensionPoint = Platform.getExtensionRegistry() | |
.getExtensionPoint(EDITOR_EXTENSION_POINT_ID); | |
if (extensionPoint != null) { | |
IConfigurationElement[] configurationElements = extensionPoint | |
.getConfigurationElements(); | |
for (IConfigurationElement element : configurationElements) { | |
if (StringUtils.equals(element.getAttribute(ATTRIBUTE_ID), | |
HTML_EDITOR_ID)) { | |
return (TextEditor) element | |
.createExecutableExtension(ATTRIBUTE_CLASS); | |
} | |
} | |
} | |
} catch (Exception exception) { | |
// couldn't find the WTP plugin | |
} | |
return new TextEditor(); | |
} |
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
Require-Bundle: | |
... | |
org.eclipse.wst.sse.ui;resolution:=optional |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment