use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class StepLoopAction method runOnNodes.
/**
* Perform one step through the entire loop and pause again.
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating 'Step Loop Execution' job for " + nodeParts.length + " node(s)...");
WorkflowManager manager = getManager();
for (NodeContainerEditPart p : nodeParts) {
NodeContainerUI nc = p.getNodeContainer();
if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
manager.resumeLoopExecution(nnc, /*oneStep=*/
true);
} else if (manager.canExecuteNodeDirectly(nc.getID())) {
manager.executeUpToHere(nc.getID());
manager.pauseLoopExecution(nnc);
}
}
}
try {
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
} catch (Exception e) {
// ignore
}
}
use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class NodeOutputView method updateSettingsTable.
/*
* Put info about node settings into table.
*/
private void updateSettingsTable(final NodeContainer nc, final boolean showAll) {
assert Display.getCurrent().getThread() == Thread.currentThread();
// display swt table
((StackLayout) m_stackPanel.getLayout()).topControl = m_table;
m_stackPanel.layout();
m_info.setText("Node Configuration");
// retrieve settings
NodeSettings settings = new NodeSettings("");
try {
nc.getParent().saveNodeSettings(nc.getID(), settings);
} catch (InvalidSettingsException ise) {
// never happens.
}
// and put them into the table
m_table.removeAll();
for (TableColumn tc : m_table.getColumns()) {
tc.dispose();
}
String[] titles = { "Key", "Value" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText(titles[i]);
}
// add information about plugin and version to list (in show all/expert mode only)
if ((nc instanceof NativeNodeContainer) && showAll) {
NativeNodeContainer nnc = (NativeNodeContainer) nc;
TableItem item4 = new TableItem(m_table, SWT.NONE);
item4.setText(0, "Node's feature name");
item4.setText(1, nnc.getNodeAndBundleInformation().getFeatureName().orElse("?"));
TableItem item5 = new TableItem(m_table, SWT.NONE);
item5.setText(0, "Node's feature symbolic name");
item5.setText(1, nnc.getNodeAndBundleInformation().getFeatureSymbolicName().orElse("?"));
TableItem item6 = new TableItem(m_table, SWT.NONE);
item6.setText(0, "Node's feature version (last saved with)");
item6.setText(1, nnc.getNodeAndBundleInformation().getFeatureVersion().map(v -> v.toString()).orElse("?"));
TableItem item1 = new TableItem(m_table, SWT.NONE);
item1.setText(0, "Node's plug-in name");
item1.setText(1, nnc.getNodeAndBundleInformation().getBundleName().orElse("?"));
TableItem item2 = new TableItem(m_table, SWT.NONE);
item2.setText(0, "Node's plug-in symbolic name");
item2.setText(1, nnc.getNodeAndBundleInformation().getBundleSymbolicName().orElse("?"));
TableItem item3 = new TableItem(m_table, SWT.NONE);
item3.setText(0, "Node's plug-in version (last saved with)");
item3.setText(1, nnc.getNodeAndBundleInformation().getBundleVersion().map(v -> v.toString()).orElse("?"));
}
// add settings to table
Stack<Pair<Iterator<String>, ConfigBase>> stack = new Stack<Pair<Iterator<String>, ConfigBase>>();
Iterator<String> it = settings.keySet().iterator();
if (it.hasNext()) {
stack.push(new Pair<Iterator<String>, ConfigBase>(it, settings));
}
while (!stack.isEmpty()) {
String key = stack.peek().getFirst().next();
int depth = stack.size();
boolean noexpertskip = (depth <= 1);
AbstractConfigEntry ace = stack.peek().getSecond().getEntry(key);
if (!stack.peek().getFirst().hasNext()) {
stack.pop();
}
if (ace.getType().equals(ConfigEntries.config)) {
// it's another Config entry, push on stack!
String val = ace.toStringValue();
if ((!val.endsWith("_Internals")) || showAll) {
Iterator<String> it2 = ((ConfigBase) ace).iterator();
if (it2.hasNext()) {
stack.push(new Pair<Iterator<String>, ConfigBase>(it2, (ConfigBase) ace));
}
} else {
noexpertskip = true;
}
}
// in both cases, we report its value
if ((!noexpertskip) || showAll) {
String value = ace.toStringValue();
TableItem item = new TableItem(m_table, SWT.NONE);
char[] indent = new char[depth - 1];
Arrays.fill(indent, '_');
item.setText(0, new String(indent) + key);
item.setText(1, value != null ? value : "null");
}
}
for (int i = 0; i < m_table.getColumnCount(); i++) {
m_table.getColumn(i).pack();
}
}
use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class NodeMonitorView method updateSettingsTable.
/*
* Put info about node settings into table.
*/
private void updateSettingsTable(final NodeContainerUI nc, final boolean showAll) {
assert Display.getCurrent().getThread() == Thread.currentThread();
m_info.setText("Node Configuration");
// retrieve settings
ConfigBaseRO settings = nc.getNodeSettings();
// and put them into the table
m_table.removeAll();
for (TableColumn tc : m_table.getColumns()) {
tc.dispose();
}
String[] titles = { "Key", "Value" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText(titles[i]);
}
// add information about plugin and version to list (in show all/expert mode only)
if (Wrapper.wraps(nc, NativeNodeContainer.class) && showAll) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
TableItem item4 = new TableItem(m_table, SWT.NONE);
item4.setText(0, "Node's feature name");
item4.setText(1, nnc.getNodeAndBundleInformation().getFeatureName().orElse("?"));
TableItem item5 = new TableItem(m_table, SWT.NONE);
item5.setText(0, "Node's feature symbolic name");
item5.setText(1, nnc.getNodeAndBundleInformation().getFeatureSymbolicName().orElse("?"));
TableItem item6 = new TableItem(m_table, SWT.NONE);
item6.setText(0, "Node's feature version (last saved with)");
item6.setText(1, nnc.getNodeAndBundleInformation().getFeatureVersion().map(v -> v.toString()).orElse("?"));
TableItem item1 = new TableItem(m_table, SWT.NONE);
item1.setText(0, "Node's plug-in name");
item1.setText(1, nnc.getNodeAndBundleInformation().getBundleName().orElse("?"));
TableItem item2 = new TableItem(m_table, SWT.NONE);
item2.setText(0, "Node's plug-in symbolic name");
item2.setText(1, nnc.getNodeAndBundleInformation().getBundleSymbolicName().orElse("?"));
TableItem item3 = new TableItem(m_table, SWT.NONE);
item3.setText(0, "Node's plug-in version (last saved with)");
item3.setText(1, nnc.getNodeAndBundleInformation().getBundleVersion().map(v -> v.toString()).orElse("?"));
}
// add settings to table
Stack<Pair<Iterator<String>, ConfigBaseRO>> stack = new Stack<Pair<Iterator<String>, ConfigBaseRO>>();
Iterator<String> it = settings.keySet().iterator();
if (it.hasNext()) {
stack.push(new Pair<Iterator<String>, ConfigBaseRO>(it, settings));
}
while (!stack.isEmpty()) {
String key = stack.peek().getFirst().next();
int depth = stack.size();
boolean noexpertskip = (depth <= 1);
ConfigBaseRO second = stack.peek().getSecond();
ConfigBaseRO confBase = null;
try {
confBase = second.getConfigBase(key);
} catch (InvalidSettingsException e) {
// nothing to do here - then it's just null as handled below
}
if (!stack.peek().getFirst().hasNext()) {
stack.pop();
}
if (confBase != null) {
// it's another Config entry, push on stack!
String val = confBase.toString();
if ((!val.endsWith("_Internals")) || showAll) {
Iterator<String> it2 = confBase.iterator();
if (it2.hasNext()) {
stack.push(new Pair<Iterator<String>, ConfigBaseRO>(it2, confBase));
}
} else {
noexpertskip = true;
}
}
// in both cases, we report its value
if ((!noexpertskip) || showAll) {
// TODO little problem here: there is no way to turn the entry for a specific key in the config base into a string!
// Hence, we check for a implementation that allows to do that as workaround.
// Yet, it would be better to add, e.g., a #toStringValue(String key) method to the ConfigRO interface ...
// However, so far there isn't any other implementation than ConfigBase anyway ...
String value;
if (second instanceof ConfigBase) {
value = ((ConfigBase) second).getEntry(key).toStringValue();
} else {
throw new IllegalStateException("Sub type \"" + second.getClass() + "\" of ConfigBaseRO not supported.");
}
TableItem item = new TableItem(m_table, SWT.NONE);
char[] indent = new char[depth - 1];
Arrays.fill(indent, '_');
item.setText(0, new String(indent) + key);
item.setText(1, value != null ? value : "null");
}
}
for (int i = 0; i < m_table.getColumnCount(); i++) {
m_table.getColumn(i).pack();
}
}
use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class NodeRecommendationManager method getNodeRecommendationFor.
/**
* Determines lists of node recommendation based on the given nodes (e.g. that are selected in the workflow editor).
* The {@link NodeRecommendation}s are determined based on the statistics of {@link NodeTriple}s (i.e. predecessor,
* node, successor, count -> (p,n,s,c)) that are provided by {@link NodeTripleProvider}s.
*
* Given the list's of node triples, {(predecessor, node, successor, count/frequency)} = {(p,n,s,c)} and given a
* selected node 'sn', the recommendations are determined for each node-triple-list as follows:
*
* (1) find all node triples (p,n,s,c) where n==sn and add them to the result list; in that case the predecessor is
* essentially ignored and recommendation are determined only based on n. The recommendation is the successor 's'
* given by each found triple. Since there will be multiple triples for the same 'n' and therewith successor
* duplicates (i.e. recommendations), those will be joined by taking the mean of the respective frequencies 'c' (2)
* determine all current predecessors ('sp') of the selected node 'sn' and find all node triples that match the
* given predecessor-node pairs ('sp','sn') (i.e. 'sp'='p' and 'sn'='n'). The recommended nodes are the successor
* nodes 's' given by the found triples. Those are added to the same list as the recommendations of (1). (3)
* Post-processing: duplicate recommendations are resolved by removing the recommendations with a smaller
* counts/frequencies
*
* If the array of given nodes is empty, all potential source nodes are recommended, i.e. all nodes 'n' in the node
* triples list that don't have a predecessor 'p'.
*
* @param nnc if it's an empty array, source nodes only will be recommended, if more than one node is given, the
* node recommendations for different nodes will end up in the same list
* @return an array of lists of node recommendations, i.e. a list of node recommendations for each used node
* {@link NodeTripleProvider}. It will return <code>null</code> if something went wrong with loading the
* node statistics!
*/
public List<NodeRecommendation>[] getNodeRecommendationFor(final NativeNodeContainer... nnc) {
if (m_recommendations == null) {
return null;
}
@SuppressWarnings("unchecked") List<NodeRecommendation>[] res = new List[m_recommendations.size()];
for (int idx = 0; idx < res.length; idx++) {
if (nnc.length == 0) {
// recommendations if no node is given -> source nodes are recommended
res[idx] = m_recommendations.get(idx).get(SOURCE_NODES_KEY);
if (res[idx] == null) {
res[idx] = Collections.emptyList();
}
} else if (nnc.length == 1) {
String nodeID = getKey(nnc[0]);
Set<NodeRecommendation> set = new HashSet<NodeRecommendationManager.NodeRecommendation>();
/* recommendations based on the given node and possible predecessors */
for (int i = 0; i < nnc[0].getNrInPorts(); i++) {
ConnectionContainer cc = nnc[0].getParent().getIncomingConnectionFor(nnc[0].getID(), i);
if (cc != null) {
// only take the predecessor if its not leaving the workflow (e.g. the actual predecessor is outside of a metanode)
if (cc.getType() != ConnectionType.WFMIN) {
NodeContainer predecessor = nnc[0].getParent().getNodeContainer(cc.getSource());
if (predecessor instanceof NativeNodeContainer) {
List<NodeRecommendation> l = m_recommendations.get(idx).get(getKey((NativeNodeContainer) predecessor) + NODE_NAME_SEP + getKey(nnc[0]));
if (l != null) {
set.addAll(l);
}
}
}
}
}
/* recommendation based on the given node only */
List<NodeRecommendation> p1 = m_recommendations.get(idx).get(nodeID);
if (p1 != null) {
set.addAll(p1);
}
// add to the result list
res[idx] = new ArrayList<NodeRecommendationManager.NodeRecommendation>(set.size());
res[idx].addAll(set);
} else {
throw new UnsupportedOperationException("Recommendations for more than one node are not supported, yet.");
}
/* post-process result */
Collections.sort(res[idx]);
if (nnc.length == 1) {
// remove the node, the recommendations have bee requested for, from the list
// in order to match the nodes [NodeFactory]#[NodeName] needs to be compared, otherwise it won't work with dynamically generated nodes
res[idx] = res[idx].stream().filter(nr -> !getKey(nr.getNodeTemplate()).equals(getKey(nnc[0]))).collect(Collectors.toList());
}
// update the total frequencies
int tmpFreqs = 0;
for (NodeRecommendation np : res[idx]) {
tmpFreqs += np.getFrequency();
}
for (NodeRecommendation np : res[idx]) {
np.setTotalFrequency(tmpFreqs);
}
}
return res;
}
Aggregations