use of org.knime.core.quickform.QuickFormRepresentation in project knime-core by knime.
the class SubNodeContainer method getXMLDescription.
/* -------------------- NodeContainer info properties -------------- */
@SuppressWarnings("rawtypes")
/**
* {@inheritDoc}
*/
@Override
public Element getXMLDescription() {
VirtualSubNodeInputNodeModel inNode = getVirtualInNodeModel();
VirtualSubNodeOutputNodeModel outNode = getVirtualOutNodeModel();
String description = inNode.getSubNodeDescription();
String sDescription;
if (StringUtils.isEmpty(description)) {
sDescription = "";
} else {
sDescription = StringUtils.split(description, ".\n")[0];
sDescription = StringUtils.abbreviate(sDescription, 200);
}
String[] inPortNames = inNode.getPortNames();
String[] inPortDescriptions = inNode.getPortDescriptions();
String[] outPortNames = outNode.getPortNames();
String[] outPortDescriptions = outNode.getPortDescriptions();
Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
List<String> optionNames = new ArrayList<String>();
List<String> optionDescriptions = new ArrayList<String>();
for (DialogNode dialogNode : nodes.values()) {
DialogNodeRepresentation representation = dialogNode.getDialogRepresentation();
if (representation instanceof QuickFormRepresentation) {
optionNames.add(((QuickFormRepresentation) representation).getLabel());
optionDescriptions.add(((QuickFormRepresentation) representation).getDescription());
}
}
try {
// Document
Document doc = NodeDescription.getDocumentBuilderFactory().newDocumentBuilder().getDOMImplementation().createDocument("http://knime.org/node2012", "knimeNode", null);
// knimeNode
Element knimeNode = doc.getDocumentElement();
knimeNode.setAttribute("type", "Unknown");
knimeNode.setAttribute("icon", "subnode.png");
// name
Element name = doc.createElement("name");
knimeNode.appendChild(name);
name.appendChild(doc.createTextNode(getName()));
// shortDescription
Element shortDescription = doc.createElement("shortDescription");
knimeNode.appendChild(shortDescription);
addText(shortDescription, sDescription, NO_DESCRIPTION_SET);
// fullDescription
Element fullDescription = doc.createElement("fullDescription");
knimeNode.appendChild(fullDescription);
// intro
Element intro = doc.createElement("intro");
fullDescription.appendChild(intro);
addText(intro, description, NO_DESCRIPTION_SET + "\nIn order to set a description browse the input node " + "contained in the Wrapped Metanode and change its configuration.");
// option
for (int i = 0; i < optionNames.size(); i++) {
Element option = doc.createElement("option");
fullDescription.appendChild(option);
option.setAttribute("name", optionNames.get(i));
addText(option, optionDescriptions.get(i), "");
}
// ports
Element ports = doc.createElement("ports");
knimeNode.appendChild(ports);
// inPort
for (int i = 0; i < inPortNames.length; i++) {
Element inPort = doc.createElement("inPort");
ports.appendChild(inPort);
inPort.setAttribute("index", "" + i);
inPort.setAttribute("name", inPortNames[i]);
String defaultText = NO_DESCRIPTION_SET;
if (i == 0) {
defaultText += "\nChange this label by browsing the input node contained in the Wrapped Metanode " + "and changing its configuration.";
}
addText(inPort, inPortDescriptions[i], defaultText);
}
// outPort
for (int i = 0; i < outPortNames.length; i++) {
Element outPort = doc.createElement("outPort");
ports.appendChild(outPort);
outPort.setAttribute("index", "" + i);
outPort.setAttribute("name", outPortNames[i]);
String defaultText = NO_DESCRIPTION_SET;
if (i == 0) {
defaultText += "\nChange this label by browsing the output node contained in the Wrapped Metanode " + "and changing its configuration.";
}
addText(outPort, outPortDescriptions[i], defaultText);
}
return new NodeDescription27Proxy(doc).getXMLDescription();
} catch (ParserConfigurationException | DOMException | XmlException e) {
LOGGER.warn("Could not generate Wrapped Metanode description", e);
}
return null;
}
Aggregations