use of org.knime.core.node.workflow.NodeOutPort in project knime-core by knime.
the class NodeMonitorView method updateDataTable.
/*
* Put (static and simple) content of one output port table into table.
*/
private void updateDataTable(final NodeContainer nc, final int port) {
assert Display.getCurrent().getThread() == Thread.currentThread();
m_info.setText("Port Output");
m_table.removeAll();
for (TableColumn tc : m_table.getColumns()) {
tc.dispose();
}
// check if we can display something at all:
int index = port;
if (nc instanceof SingleNodeContainer) {
// we don't care about (hidden) variable OutPort
index++;
}
if (nc.getNrOutPorts() <= index) {
// no (real) port available
TableItem item = new TableItem(m_table, SWT.NONE);
item.setText(0, "No output ports");
return;
}
NodeOutPort nop = nc.getOutPort(index);
PortObject po = nop.getPortObject();
if ((po == null) || !(po instanceof BufferedDataTable)) {
// no table in port - ignore.
TableItem item = new TableItem(m_table, SWT.NONE);
item.setText(0, "Unknown or no PortObject");
return;
}
// retrieve table
BufferedDataTable bdt = (BufferedDataTable) po;
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText("ID");
for (int i = 0; i < bdt.getDataTableSpec().getNumColumns(); i++) {
column = new TableColumn(m_table, SWT.NONE);
column.setText(bdt.getDataTableSpec().getColumnSpec(i).getName());
}
int rowIndex = 0;
Iterator<DataRow> rowIt = bdt.iteratorFailProve();
while (rowIndex < 42 && rowIt.hasNext()) {
DataRow thisRow = rowIt.next();
TableItem item = new TableItem(m_table, SWT.NONE);
item.setText(0, thisRow.getKey().getString());
for (int i = 0; i < thisRow.getNumCells(); i++) {
DataCell c = thisRow.getCell(i);
String s = c.toString().replaceAll("\\p{Cntrl}", "_");
item.setText(i + 1, s);
}
rowIndex++;
}
for (int i = 0; i < m_table.getColumnCount(); i++) {
m_table.getColumn(i).pack();
}
}
use of org.knime.core.node.workflow.NodeOutPort in project knime-core by knime.
the class NodeOutputView method updateDataTable.
/*
* Put (static and simple) content of one output port table into table.
*/
private void updateDataTable(final NodeContainer nc, final int port) {
assert Display.getCurrent().getThread() == Thread.currentThread();
// display data table
((StackLayout) m_stackPanel.getLayout()).topControl = m_tableViewPanel;
m_stackPanel.layout();
m_info.setText("Port Output");
m_tableView.setDataTable(null);
// check if we can display something at all:
int index = port;
if (nc instanceof SingleNodeContainer) {
// we don't care about (hidden) variable OutPort
index++;
}
if (nc.getNrOutPorts() <= index) {
// no (real) port available
m_errorLabel.setText("No output ports");
((StackLayout) m_stackPanel.getLayout()).topControl = m_errorLabel;
m_stackPanel.layout();
return;
}
NodeOutPort nop = nc.getOutPort(index);
PortObject po = nop.getPortObject();
if ((po == null) || !(po instanceof BufferedDataTable)) {
// no table in port - ignore.
m_errorLabel.setText("Unknown or no PortObject");
((StackLayout) m_stackPanel.getLayout()).topControl = m_errorLabel;
m_stackPanel.layout();
return;
}
// retrieve table
m_tableView.setDataTable((DataTable) po);
m_tableView.repaint();
}
use of org.knime.core.node.workflow.NodeOutPort in project knime-core by knime.
the class OpenFirstOutPortViewAction method runOnNodes.
/**
* This opens the first view of all the selected nodes.
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating open first out-port view job for " + nodeParts.length + " node(s)...");
for (NodeContainerEditPart p : nodeParts) {
final NodeContainerUI cont = p.getNodeContainer();
final java.awt.Rectangle knimeWindowBounds = OpenViewAction.getAppBoundsAsAWTRec();
// first port is flow var port
final OptionalInt portIndex = getPortIndex(cont);
if (portIndex.isPresent()) {
SwingUtilities.invokeLater(new Runnable() {
/**
* {inheritDoc}
*/
@Override
public void run() {
NodeOutPort port = Wrapper.unwrapNC(cont).getOutPort(portIndex.getAsInt());
LOGGER.debug("Open First Out-Port View " + cont.getName() + " on port " + port.getPortName());
port.openPortView(port.getPortName(), knimeWindowBounds);
}
});
}
}
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.NodeOutPort in project knime-core by knime.
the class PortObjectRepository method addPortObjectReferenceReaderWithNodeReference.
/**
* Adds a "Port Object Reference Reader" node to the workflow, which will read the object passed in as argument.
*
* The added reference reader node references the data (i.e. port object) by referencing the port (original node id
* plus port index).
*
* @param outport the outport to get the port object and flow variables from that the to be added node will provide,
* too (the port object is just referenced by the original node id and port index)
* @param srcParentID the id of the workflow manager the referenced node (port) is part of
* @param wfm the workflow manager the new node should be added to
* @param nodeIDSuffix the id the to be added node will have (will be ignored if there is a node with the id
* already!)
* @return the id of the newly added node
*/
// TODO we might have to revisit this when implementing AP-13335
public static NodeID addPortObjectReferenceReaderWithNodeReference(final NodeOutPort outport, final NodeID srcParentID, final WorkflowManager wfm, final int nodeIDSuffix) {
NodeID sourceNodeID = outport.getConnectedNodeContainer().getID();
int portIndex = outport.getConnectedOutport().orElseThrow(() -> new IllegalStateException("Node is set, but no port"));
List<FlowVariable> variables = outport.getFlowObjectStack().getAllAvailableFlowVariables().values().stream().filter(f -> f.getScope() == Scope.Flow).collect(Collectors.toList());
PortObjectIDSettings portObjectIDSettings = new PortObjectIDSettings();
portObjectIDSettings.setNodeReference(NodeIDSuffix.create(srcParentID, sourceNodeID), portIndex);
portObjectIDSettings.setFlowVariables(variables);
boolean isTable = outport.getPortType().equals(BufferedDataTable.TYPE);
return addPortObjectReferenceReader(wfm, portObjectIDSettings, isTable, nodeIDSuffix);
}
use of org.knime.core.node.workflow.NodeOutPort in project knime-core by knime.
the class AbstractCreateNewConnectedNodeCommand method getMatchingPorts.
private Map<Integer, Integer> getMatchingPorts(final NodeContainer left, final NodeContainer right) {
// don't auto connect to flow var ports - start with port index 1
int leftFirst = (left instanceof WorkflowManagerUI) ? 0 : 1;
int rightFirst = (right instanceof WorkflowManagerUI) ? 0 : 1;
Map<Integer, Integer> matchingPorts = new TreeMap<Integer, Integer>();
Map<Integer, Integer> possibleMatches = new TreeMap<Integer, Integer>();
Set<Integer> assignedRight = new HashSet<Integer>();
for (int rightPidx = rightFirst; rightPidx < right.getNrInPorts(); rightPidx++) {
for (int leftPidx = leftFirst; leftPidx < left.getNrOutPorts(); leftPidx++) {
NodeOutPort leftPort = left.getOutPort(leftPidx);
NodeInPort rightPort = right.getInPort(rightPidx);
PortType leftPortType = leftPort.getPortType();
PortType rightPortType = rightPort.getPortType();
if (leftPortType.isSuperTypeOf(rightPortType)) {
if (getHostWFM().getOutgoingConnectionsFor(left.getID(), leftPidx).size() == 0) {
if (!matchingPorts.containsKey(leftPidx) && !assignedRight.contains(rightPidx)) {
// output not connected: use it.
matchingPorts.put(leftPidx, rightPidx);
assignedRight.add(rightPidx);
}
} else {
// port already connected - we MAY use it
if (!possibleMatches.containsKey(leftPidx) && !assignedRight.contains(rightPidx)) {
possibleMatches.put(leftPidx, rightPidx);
}
}
}
}
}
for (Map.Entry<Integer, Integer> entry : possibleMatches.entrySet()) {
Integer pl = entry.getKey();
Integer pr = entry.getValue();
if (!matchingPorts.containsKey(pl) && !assignedRight.contains(pr)) {
matchingPorts.put(pl, pr);
assignedRight.add(pr);
}
}
return matchingPorts;
}
Aggregations