use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class SubnodeLayoutPage method createControl.
/**
* {@inheritDoc}
*/
@Override
public void createControl(final Composite parent) {
ScrolledComposite scrollPane = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
scrollPane.setExpandHorizontal(true);
scrollPane.setExpandVertical(true);
Composite composite = new Composite(scrollPane, SWT.NONE);
scrollPane.setContent(composite);
scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
composite.setLayout(new GridLayout(4, false));
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
Label titleLabel = new Label(composite, SWT.LEFT);
FontData fontData = titleLabel.getFont().getFontData()[0];
Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
titleLabel.setText("Node");
titleLabel.setFont(boldFont);
Label xLabel = new Label(composite, SWT.LEFT);
xLabel.setText("X");
xLabel.setFont(boldFont);
Label yLabel = new Label(composite, SWT.LEFT);
yLabel.setText("Y");
yLabel.setFont(boldFont);
Label paddingLabel = new Label(composite, SWT.LEFT);
paddingLabel.setText("Padding");
paddingLabel.setFont(boldFont);
for (final NodeID nodeID : m_viewNodes) {
NodeContainer nodeContainer = m_wfManager.getNodeContainer(nodeID);
WizardNodeLayoutInfo layoutInfo = null;
if (m_subNodeContainer != null && m_subNodeContainer.getLayoutInfo() != null) {
layoutInfo = m_subNodeContainer.getLayoutInfo().get(nodeID.getIndex());
if (layoutInfo != null) {
m_layoutMap.put(nodeID.getIndex(), layoutInfo);
}
}
Composite labelComposite = new Composite(composite, SWT.NONE);
labelComposite.setLayout(new GridLayout(2, false));
labelComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
Label iconLabel = new Label(labelComposite, SWT.CENTER);
iconLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
try (InputStream iconURLStream = FileLocator.resolve(nodeContainer.getIcon()).openStream()) {
iconLabel.setImage(new Image(Display.getCurrent(), iconURLStream));
} catch (IOException e) {
/* do nothing */
}
Label nodeLabel = new Label(labelComposite, SWT.LEFT);
nodeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
String nodeName = nodeContainer.getName();
String annotation = nodeContainer.getNodeAnnotation().getText();
nodeLabel.setText(nodeName + "\nID: " + nodeID.getIndex() + "\n" + annotation);
GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gridData.widthHint = 80;
final Text xText = new Text(composite, SWT.SINGLE | SWT.BORDER);
xText.setLayoutData(gridData);
xText.setText(layoutInfo == null ? "" : layoutInfo.getX());
xText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
editX(nodeID, xText);
}
});
final Text yText = new Text(composite, SWT.SINGLE | SWT.BORDER);
yText.setLayoutData(gridData);
yText.setText(layoutInfo == null ? "" : layoutInfo.getY());
yText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
editY(nodeID, yText);
}
});
final Text paddingText = new Text(composite, SWT.SINGLE | SWT.BORDER);
paddingText.setLayoutData(gridData);
paddingText.setText(layoutInfo == null || layoutInfo.getPadding() == null ? "" : layoutInfo.getPadding());
paddingText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
editPadding(nodeID, paddingText);
}
});
}
scrollPane.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
setControl(scrollPane);
}
use of org.knime.core.node.workflow.NodeContainer 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;
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class KnimeResourcePatternFilter method select.
/**
* {@inheritDoc}
*/
@Override
public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
if (element instanceof IContainer) {
IContainer folder = (IContainer) element;
boolean select = false;
select = folder.exists(KnimeResourceLabelProvider.WORKFLOW_FILE);
select |= folder.exists(KnimeResourceLabelProvider.METAINFO_FILE);
select |= folder.exists(KnimeResourceLabelProvider.NODE_FILE);
return select;
}
if (element instanceof NodeContainer) {
return true;
}
return false;
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class TimerinfoNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
BufferedDataContainer result = exec.createDataContainer(createSpec());
WorkflowManager wfm = NodeContext.getContext().getWorkflowManager();
for (NodeContainer nc : wfm.getNodeContainers()) {
NodeTimer nt = nc.getNodeTimer();
DataRow row = new DefaultRow(new RowKey("Node " + nc.getID().getIndex()), new StringCell(nc.getName()), nt.getLastExecutionDuration() >= 0 ? new LongCell(nt.getLastExecutionDuration()) : DataType.getMissingCell(), new LongCell(nt.getExecutionDurationSinceReset()), new LongCell(nt.getExecutionDurationSinceStart()), new IntCell(nt.getNrExecsSinceReset()), new IntCell(nt.getNrExecsSinceStart()), new StringCell(nc.getID().toString()), new StringCell(nc instanceof NativeNodeContainer ? ((NativeNodeContainer) nc).getNodeModel().getClass().getName() : "n/a"));
result.addRowToTable(row);
}
result.close();
return new PortObject[] { result.getTable() };
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class SandboxedNodeCreator method deepCopyFilesInWorkflowDir.
/**
* Deep copies data and drop folders contained in the source directory to the target directory.
* @param source Source node
* @param targetParent Target node's parent
*/
private static void deepCopyFilesInWorkflowDir(final NodeContainer source, final WorkflowManager targetParent) {
NodeContainer target = targetParent.getNodeContainer(targetParent.getID().createChild(source.getID().getIndex()));
ReferencedFile sourceDirRef = source.getNodeContainerDirectory();
ReferencedFile targetDirRef = target.getNodeContainerDirectory();
if (sourceDirRef == null) {
// The source node has never been saved, there are no files to copy
return;
}
File sourceDir = sourceDirRef.getFile();
File targetDir = targetDirRef.getFile();
for (String magicFolderName : MAGIC_DATA_FOLDERS) {
File dataSourceDir = new File(sourceDir, magicFolderName);
if (dataSourceDir.isDirectory()) {
File dataTargetDir = new File(targetDir, magicFolderName);
try {
FileUtils.copyDirectory(dataSourceDir, dataTargetDir);
LOGGER.debugWithFormat("Copied directory \"%s\" to \"%s\"", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath());
} catch (IOException ex) {
LOGGER.error(String.format("Could not copy directory \"%s\" to \"%s\": %s", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath(), ex.getMessage()), ex);
}
}
}
Collection<NodeContainer> childrenList = Collections.emptyList();
WorkflowManager childTargetParent = null;
if (source instanceof WorkflowManager) {
childrenList = ((WorkflowManager) source).getNodeContainers();
childTargetParent = (WorkflowManager) target;
} else if (source instanceof SubNodeContainer) {
childrenList = ((SubNodeContainer) source).getWorkflowManager().getNodeContainers();
childTargetParent = ((SubNodeContainer) target).getWorkflowManager();
}
for (NodeContainer child : childrenList) {
deepCopyFilesInWorkflowDir(child, childTargetParent);
}
}
Aggregations