public void run(IAction action) {
insert();
}
public void insert() {
TemplateEditor te = getTemplateEditor();
WodEditor we = getWodEditor();
InsertComponentSpecification ics = getComponentSpecification();
System.out.println("InsertHtmlAndWodAction.insert: " + te + ", " + we + ", " + ics);
if (te != null && we != null && ics != null) {
SimpleWodElement wodElement = new SimpleWodElement(ics.getComponentInstanceName(), ics.getComponentName());
List<Binding> bindings = ics.getRequiredBindings();
if (bindings != null) {
for (Binding binding : bindings) {
wodElement.addBinding(new SimpleWodBinding(null, binding.getName(), "", true));
}
}
// If the component name is blank, then this is an HTML tag
if (ics.getComponentName() == null || ics.getComponentName().length() == 0) {
wodElement.setTagName(ics.getTagName());
}
SimpleWodElement htmlElement;
if (ics.isInline()) {
htmlElement = wodElement;
} else {
htmlElement = new SimpleWodElement("", "");
htmlElement.setTagName(ics.getTagName());
}
Map<String, String> htmlAttributes = ics.getHtmlAttributes();
if (htmlAttributes != null) {
for (Map.Entry<String, String> htmlAttribute : htmlAttributes.entrySet()) {
htmlElement.addBinding(new SimpleWodBinding(null, htmlAttribute.getKey(), htmlAttribute.getValue(), true));
}
}
IDocument teDoc = te.getHtmlEditDocument();
IDocument weDoc = we.getWodEditDocument();
ITextSelection teDocTSel = (ITextSelection) te.getSourceEditor().getSelectionProvider().getSelection();
// insert the WebObjects component into the template portion.
try {
ITextViewerExtension teExt = (ITextViewerExtension) te.getSourceEditor().getViewer();
teExt.getRewriteTarget().beginCompoundChange();
try {
int selectionStartOffset = teDocTSel.getOffset();
int selectionEndOffset = teDocTSel.getOffset() + teDocTSel.getLength();