use of org.knime.core.node.dialog.DialogNode 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;
}
use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.
the class SubNodeContainer method setHideNodeFromDialog.
/**
* Sets a flag on a given {@link DialogNode}, whether or not it is hidden from a containing metanode dialog
* @param id the node to set the flag on
* @param hide true if the node is supposed to be hidden from a containing metanode dialog, false otherwise
* @since 3.5
* @noreference This method is not intended to be referenced by clients.
*/
public void setHideNodeFromDialog(final NodeID id, final boolean hide) {
try (WorkflowLock lock = lock()) {
NativeNodeContainer nnc = m_wfm.getNodeContainer(id, NativeNodeContainer.class, true);
NodeModel model = nnc.getNodeModel();
CheckUtils.checkArgument(model instanceof DialogNode, "Can't set hide in dialog flag on non-dialog nodes.");
DialogNode<?, ?> dn = (DialogNode<?, ?>) model;
if (hide != dn.isHideInDialog()) {
dn.setHideInDialog(hide);
nnc.saveNodeSettingsToDefault();
nnc.setDirty();
}
}
}
use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.
the class SubNodeContainer method loadModelSettingsIntoDialogNodes.
/**
* Applies the "modelSettings" (stored in the {@link SingleNodeContainerSettings} into the {@link DialogNode}
* contained in this workflow.
* @param modelSettings The new model settings.
* @param performReset true when called via dialog, false when called during load.
* @throws InvalidSettingsException ...
*/
@SuppressWarnings("rawtypes")
private void loadModelSettingsIntoDialogNodes(final NodeSettingsRO modelSettings, final boolean performReset) throws InvalidSettingsException {
assert isLockedByCurrentThread();
synchronized (m_nodeMutex) {
// check state of contained WFM as state of this Subnode may already be "MARKED".
if (m_wfm.getInternalState().isExecutionInProgress()) {
throw new IllegalStateException("Cannot load settings as the Wrapped Metanode is currently executing");
}
Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
// contains all nodes that have new value (different to previous value, even if null now).
Map<NodeID, DialogNodeValue> newDialogValueMap = new HashMap<>();
// but do not set it yet in order to verify/load all settings before applying them
for (Map.Entry<NodeID, DialogNode> entry : nodes.entrySet()) {
final NodeID id = entry.getKey();
final DialogNode node = entry.getValue();
final String parameterName = getDialogNodeParameterName(node, id);
// the old/previously set value in the node
final DialogNodeValue oldDialogValue = node.getDialogValue();
final NodeSettings oldDialogValueSettings;
if (oldDialogValue != null) {
oldDialogValueSettings = new NodeSettings(parameterName);
oldDialogValue.saveToNodeSettings(oldDialogValueSettings);
} else {
oldDialogValueSettings = null;
}
final NodeSettingsRO newDialogValueSettings = modelSettings.containsKey(parameterName) ? modelSettings.getNodeSettings(parameterName) : null;
// #equals on DialogNodeValue might not be implemented.
if (ObjectUtils.notEqual(newDialogValueSettings, oldDialogValueSettings)) {
final DialogNodeValue newDialogValue;
if (newDialogValueSettings != null) {
newDialogValue = node.createEmptyDialogValue();
try {
newDialogValue.loadFromNodeSettings(newDialogValueSettings);
} catch (InvalidSettingsException e) {
throw new InvalidSettingsException(String.format("Cannot load dialog value for node \"%s\": %s", m_wfm.getNodeContainer(id).getNameWithID(), e.getMessage()), e);
}
} else {
newDialogValue = null;
}
newDialogValueMap.put(id, newDialogValue);
}
}
// apply all new dialog values and reset/configure those nodes with modified config.
for (Map.Entry<NodeID, DialogNodeValue> modifiedNodesEntry : newDialogValueMap.entrySet()) {
final DialogNode node = nodes.get(modifiedNodesEntry.getKey());
node.setDialogValue(modifiedNodesEntry.getValue());
if (performReset) {
m_wfm.resetAndConfigureNode(modifiedNodesEntry.getKey());
}
}
}
}
use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.
the class SubNodeContainer method performSaveModelSettingsTo.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("rawtypes")
void performSaveModelSettingsTo(final NodeSettings modelSettings) {
Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
for (Map.Entry<NodeID, DialogNode> entry : nodes.entrySet()) {
final DialogNode dialogNode = entry.getValue();
final String parameterName = getDialogNodeParameterName(dialogNode, entry.getKey());
final DialogNodeValue dialogValue = dialogNode.getDialogValue();
if (dialogValue != null) {
NodeSettingsWO subSettings = modelSettings.addNodeSettings(parameterName);
dialogValue.saveToNodeSettings(subSettings);
}
}
}
use of org.knime.core.node.dialog.DialogNode in project knime-core by knime.
the class SubNodeContainer method getDialogPaneWithSettings.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("rawtypes")
NodeDialogPane getDialogPaneWithSettings(final PortObjectSpec[] inSpecs, final PortObject[] inData) throws NotConfigurableException {
NodeDialogPane dialogPane = getDialogPane();
// find all dialog nodes and update subnode dialog
Map<NodeID, MetaNodeDialogNode> nodes = m_wfm.findNodes(MetaNodeDialogNode.class, new NodeModelFilter<MetaNodeDialogNode>() {
@Override
public boolean include(final MetaNodeDialogNode nodeModel) {
return nodeModel instanceof DialogNode && !((DialogNode) nodeModel).isHideInDialog();
}
}, false);
((MetaNodeDialogPane) dialogPane).setQuickformNodes(nodes);
NodeSettings settings = new NodeSettings("subnode_settings");
saveSettings(settings);
// remove the flow variable port from the specs and data
PortObjectSpec[] correctedInSpecs = ArrayUtils.remove(inSpecs, 0);
PortObject[] correctedInData = ArrayUtils.remove(inData, 0);
// the next call will call dialogPane.internalLoadSettingsFrom()
// dialogPane is a MetaNodeDialogPane and does not handle the flow variable port correctly
// this is why we remove it first
Node.invokeDialogInternalLoad(dialogPane, settings, correctedInSpecs, correctedInData, getFlowObjectStack(), new CredentialsProvider(this, m_wfm.getCredentialsStore()), getParent().isWriteProtected());
return dialogPane;
}
Aggregations