Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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();
}
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();
}
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
You can’t perform that action at this time.