Search in sources :

Example 1 with NodeOutPort

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();
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) DataCell(org.knime.core.data.DataCell) TableColumn(org.eclipse.swt.widgets.TableColumn) PortObject(org.knime.core.node.port.PortObject) DataRow(org.knime.core.data.DataRow) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

Example 2 with NodeOutPort

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();
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) PortObject(org.knime.core.node.port.PortObject) Point(org.eclipse.swt.graphics.Point) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

Example 3 with NodeOutPort

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
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) OptionalInt(java.util.OptionalInt)

Example 4 with NodeOutPort

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);
}
Also used : FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FlowVariable(org.knime.core.node.workflow.FlowVariable) ObjectInputStream(java.io.ObjectInputStream) ObjectStreamClass(java.io.ObjectStreamClass) HashMap(java.util.HashMap) NodeSettings(org.knime.core.node.NodeSettings) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) DataCellSerializer(org.knime.core.data.DataCellSerializer) System.identityHashCode(java.lang.System.identityHashCode) ExecutionContext(org.knime.core.node.ExecutionContext) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) Node(org.knime.core.node.Node) ByteArrayInputStream(java.io.ByteArrayInputStream) DataTypeRegistry(org.knime.core.data.DataTypeRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) BlobDataCell(org.knime.core.data.container.BlobDataCell) PortObjectInNodeModel(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel) Scope(org.knime.core.node.workflow.FlowVariable.Scope) ObjectOutputStream(java.io.ObjectOutputStream) DataCell(org.knime.core.data.DataCell) OutputStream(java.io.OutputStream) DefaultRow(org.knime.core.data.def.DefaultRow) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) NodeFactory(org.knime.core.node.NodeFactory) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) UUID(java.util.UUID) NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Collectors(java.util.stream.Collectors) DataRow(org.knime.core.data.DataRow) SandboxedNodeCreator(org.knime.core.node.exec.SandboxedNodeCreator) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCellDataInput(org.knime.core.data.DataCellDataInput) DataCellDataOutput(org.knime.core.data.DataCellDataOutput) NodeID(org.knime.core.node.workflow.NodeID) Optional(java.util.Optional) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) InputStream(java.io.InputStream) NodeID(org.knime.core.node.workflow.NodeID) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 5 with NodeOutPort

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;
}
Also used : NodeInPort(org.knime.core.node.workflow.NodeInPort) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Point(org.eclipse.draw2d.geometry.Point) HashSet(java.util.HashSet) PortType(org.knime.core.node.port.PortType)

Aggregations

NodeOutPort (org.knime.core.node.workflow.NodeOutPort)6 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 PortObject (org.knime.core.node.port.PortObject)3 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)3 Map (java.util.Map)2 DataCell (org.knime.core.data.DataCell)2 DataRow (org.knime.core.data.DataRow)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ObjectStreamClass (java.io.ObjectStreamClass)1 OutputStream (java.io.OutputStream)1 System.identityHashCode (java.lang.System.identityHashCode)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1