Search in sources :

Example 36 with Pair

use of org.knime.core.util.Pair in project knime-core by knime.

the class WorkflowManager method changeMetaNodeOutputPorts.

/**
 * @param subFlowID ID of the subflow
 * @param newPorts The new ports
 * @since 2.6
 */
public void changeMetaNodeOutputPorts(final NodeID subFlowID, final MetaPortInfo[] newPorts) {
    try (WorkflowLock lock = lock()) {
        WorkflowManager subFlowMgr = getNodeContainer(subFlowID, WorkflowManager.class, true);
        if (!haveMetaPortsChanged(newPorts, false, subFlowMgr)) {
            return;
        }
        List<Pair<ConnectionContainer, ConnectionContainer>> changedConnectionsThisFlow = m_workflow.changeSourcePortsForMetaNode(subFlowID, newPorts, false);
        for (Pair<ConnectionContainer, ConnectionContainer> p : changedConnectionsThisFlow) {
            ConnectionContainer old = p.getFirst();
            m_workflow.removeConnection(old);
            notifyWorkflowListeners(new WorkflowEvent(WorkflowEvent.Type.CONNECTION_REMOVED, null, old, null));
        }
        Workflow subFlow = subFlowMgr.m_workflow;
        List<Pair<ConnectionContainer, ConnectionContainer>> changedConnectionsSubFlow = subFlow.changeDestinationPortsForMetaNode(subFlowID, newPorts, false);
        for (Pair<ConnectionContainer, ConnectionContainer> p : changedConnectionsSubFlow) {
            ConnectionContainer old = p.getFirst();
            subFlow.removeConnection(old);
            subFlowMgr.notifyWorkflowListeners(new WorkflowEvent(WorkflowEvent.Type.CONNECTION_REMOVED, null, old, null));
        }
        WorkflowOutPort[] newMNPorts = new WorkflowOutPort[newPorts.length];
        for (int i = 0; i < newPorts.length; i++) {
            final int oldIndex = newPorts[i].getOldIndex();
            if (oldIndex >= 0) {
                newMNPorts[i] = subFlowMgr.getOutPort(oldIndex);
                newMNPorts[i].setPortIndex(i);
            } else {
                newMNPorts[i] = new WorkflowOutPort(i, newPorts[i].getType());
            }
        }
        subFlowMgr.m_outPorts = newMNPorts;
        subFlowMgr.notifyNodePropertyChangedListener(NodeProperty.MetaNodePorts);
        for (Pair<ConnectionContainer, ConnectionContainer> p : changedConnectionsThisFlow) {
            ConnectionContainer newConn = p.getSecond();
            m_workflow.addConnection(newConn);
            notifyWorkflowListeners(new WorkflowEvent(WorkflowEvent.Type.CONNECTION_ADDED, null, null, newConn));
        }
        for (Pair<ConnectionContainer, ConnectionContainer> p : changedConnectionsSubFlow) {
            ConnectionContainer newConn = p.getSecond();
            subFlow.addConnection(newConn);
            subFlowMgr.notifyWorkflowListeners(new WorkflowEvent(WorkflowEvent.Type.CONNECTION_ADDED, null, null, newConn));
        }
        subFlowMgr.setDirty();
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Pair(org.knime.core.util.Pair)

Example 37 with Pair

use of org.knime.core.util.Pair in project knime-core by knime.

the class FlowObjectStackView method update.

/**
 * Updates the view to display the given stack.
 * @param stack Whose values are to be displayed.
 */
public void update(final FlowObjectStack stack) {
    final FontMetrics fontMetrics = m_table.getFontMetrics(m_table.getFont());
    List<Object[]> values;
    // relative width of each column - make important columns wider
    int[] colRelativeWidth = new int[4];
    for (int i = 0; i < colRelativeWidth.length; i++) {
        colRelativeWidth[i] = SwingUtilities.computeStringWidth(fontMetrics, COLUMN_NAMES[i]);
    }
    if (stack != null) {
        values = new ArrayList<Object[]>();
        int loopCount = 0;
        int counter = 0;
        Set<Pair<String, Type>> duplicateElementsSet = new HashSet<Pair<String, Type>>();
        for (FlowObject s : stack) {
            Object[] obj = new Object[4];
            obj[0] = Integer.valueOf(counter);
            obj[1] = s.getOwner();
            if (s instanceof FlowVariable) {
                FlowVariable v = (FlowVariable) s;
                final Pair<String, Type> key = new Pair<String, Type>(v.getName(), v.getType());
                if (!duplicateElementsSet.add(key)) {
                    continue;
                }
                obj[2] = s;
                Object o;
                switch(v.getType()) {
                    case DOUBLE:
                        o = Double.valueOf(v.getDoubleValue());
                        break;
                    case INTEGER:
                        o = Integer.valueOf(v.getIntValue());
                        break;
                    case STRING:
                        o = v.getStringValue();
                        break;
                    case CREDENTIALS:
                        o = v.getCredentialsValue();
                        break;
                    default:
                        o = "Unknown Type: " + v.getType();
                }
                obj[3] = o;
            } else if (s instanceof FlowLoopContext) {
                duplicateElementsSet.clear();
                if (!((FlowLoopContext) s).isInactiveScope()) {
                    obj[2] = "Loop (" + (loopCount++) + ")";
                    obj[3] = null;
                } else {
                    obj[2] = "Inactive Loop Mark";
                    obj[3] = null;
                }
            } else if (s instanceof InnerFlowLoopContext) {
                obj[2] = "Loop-Execute";
                obj[3] = null;
            } else if (s instanceof FlowScopeContext) {
                obj[2] = s.toString() + (((FlowScopeContext) s).isInactiveScope() ? " (inactive)" : "");
                obj[3] = null;
            } else {
                obj[2] = "unknown:" + s.toString();
                obj[3] = null;
            }
            values.add(obj);
            for (int i = 0; i < colRelativeWidth.length; i++) {
                String representation;
                if (obj[i] instanceof FlowVariable) {
                    representation = "ICON" + ((FlowVariable) obj[i]).getName();
                } else {
                    representation = Objects.toString(obj[i], "");
                }
                colRelativeWidth[i] = Math.max(colRelativeWidth[i], SwingUtilities.computeStringWidth(fontMetrics, representation));
            }
        }
    } else {
        values = Collections.emptyList();
    }
    final DefaultTableModel model = (DefaultTableModel) m_table.getModel();
    model.setDataVector(values.toArray(new Object[values.size()][]), COLUMN_NAMES);
    final TableColumnModel columnModel = m_table.getColumnModel();
    for (int i = 0; i < colRelativeWidth.length; i++) {
        columnModel.getColumn(i).setPreferredWidth(colRelativeWidth[i]);
    }
    m_table.setCellSelectionEnabled(true);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableColumnModel(javax.swing.table.TableColumnModel) Type(org.knime.core.node.workflow.FlowVariable.Type) FontMetrics(java.awt.FontMetrics) Pair(org.knime.core.util.Pair) HashSet(java.util.HashSet)

Example 38 with Pair

use of org.knime.core.util.Pair in project knime-core by knime.

the class MetaNodeDialogPane method setQuickformNodes.

/**
 * Set quickform nodes into this dialog; called just before
 * {@link #loadSettingsFrom(NodeSettingsRO,
 * org.knime.core.data.DataTableSpec[])} is called.
 * @param nodes the quickform nodes to show settings for
 */
final void setQuickformNodes(final Map<NodeID, MetaNodeDialogNode> nodes) {
    m_nodes.clear();
    m_quickFormInputNodePanels.clear();
    m_dialogNodePanels.clear();
    // remove all quickform components from current panel
    m_panel.removeAll();
    List<Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>> sortedNodeList = new ArrayList<Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>>();
    for (Map.Entry<NodeID, MetaNodeDialogNode> e : nodes.entrySet()) {
        // only accept old qf nodes for metanodes
        if (!m_usedInSubnode && e.getValue() instanceof QuickFormInputNode) {
            AbstractQuickFormConfiguration<? extends AbstractQuickFormValueInConfiguration> config = ((QuickFormInputNode) e.getValue()).getConfiguration();
            if (config == null) {
                // quickform nodes has no valid configuration
                continue;
            }
            QuickFormConfigurationPanel<? extends AbstractQuickFormValueInConfiguration> quickform = config.createController();
            m_nodes.put(e.getKey(), e.getValue());
            m_quickFormInputNodePanels.put(e.getKey(), quickform);
            Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> weightNodePair = new Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>(config.getWeight(), new Pair<NodeID, MetaNodeDialogNode>(e.getKey(), e.getValue()));
            sortedNodeList.add(weightNodePair);
        // only accept new qf nodes for subnodes
        } else if (m_usedInSubnode && e.getValue() instanceof DialogNode) {
            DialogNodeRepresentation<? extends DialogNodeValue> representation = ((DialogNode) e.getValue()).getDialogRepresentation();
            if (((DialogNode) e.getValue()).isHideInDialog() || representation == null) {
                // no valid representation
                continue;
            }
            try {
                DialogNodePanel dialogPanel = representation.createDialogPanel();
                m_nodes.put(e.getKey(), e.getValue());
                m_dialogNodePanels.put(e.getKey(), dialogPanel);
                Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> weightNodePair = new Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>(Integer.MAX_VALUE, new Pair<NodeID, MetaNodeDialogNode>(e.getKey(), e.getValue()));
                sortedNodeList.add(weightNodePair);
            } catch (Exception ex) {
                LOGGER.error("The dialog pane for node " + e.getKey() + " could not be created.", ex);
            }
        }
    }
    Collections.sort(sortedNodeList, new Comparator<Pair<Integer, Pair<NodeID, MetaNodeDialogNode>>>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int compare(final Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> o1, final Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> o2) {
            return o1.getFirst() - o2.getFirst();
        }
    });
    for (Pair<Integer, Pair<NodeID, MetaNodeDialogNode>> weightNodePair : sortedNodeList) {
        NodeID id = weightNodePair.getSecond().getFirst();
        MetaNodeDialogNode node = weightNodePair.getSecond().getSecond();
        if (node instanceof QuickFormInputNode) {
            final QuickFormConfigurationPanel<?> qconfPanel = m_quickFormInputNodePanels.get(id);
            JPanel qpanel = new JPanel();
            final BoxLayout boxLayout2 = new BoxLayout(qpanel, BoxLayout.Y_AXIS);
            qpanel.setLayout(boxLayout2);
            qpanel.setBorder(BorderFactory.createTitledBorder((String) null));
            JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
            p.add(qconfPanel);
            qpanel.add(p);
            m_panel.add(qpanel);
        } else if (node instanceof DialogNode) {
            DialogNodePanel<? extends DialogNodeValue> nodePanel = m_dialogNodePanels.get(id);
            JPanel dpanel = new JPanel();
            final BoxLayout boxLayout2 = new BoxLayout(dpanel, BoxLayout.Y_AXIS);
            dpanel.setLayout(boxLayout2);
            dpanel.setBorder(BorderFactory.createTitledBorder((String) null));
            JPanel p = new JPanel(new BorderLayout());
            p.add(nodePanel, BorderLayout.CENTER);
            dpanel.add(p);
            m_panel.add(dpanel);
        }
    }
    if (m_nodes.isEmpty()) {
        m_panel.add(new JLabel("No valid Quickform configurations."));
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) BoxLayout(javax.swing.BoxLayout) ArrayList(java.util.ArrayList) DialogNode(org.knime.core.node.dialog.DialogNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) BorderLayout(java.awt.BorderLayout) Pair(org.knime.core.util.Pair) JLabel(javax.swing.JLabel) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode) DialogNodeRepresentation(org.knime.core.node.dialog.DialogNodeRepresentation) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DialogNodePanel(org.knime.core.node.dialog.DialogNodePanel)

Example 39 with Pair

use of org.knime.core.util.Pair in project knime-core by knime.

the class Workflow method changeDestinationPortsForMetaNode.

/**
 * @param metaNodeID ID of the metanode
 * @param newPorts The new ports
 * @param includeUnchanged If connections that will not change should be included
 * @return List of pairs of original (first) and changed (second) connections
 */
List<Pair<ConnectionContainer, ConnectionContainer>> changeDestinationPortsForMetaNode(final NodeID metaNodeID, final MetaPortInfo[] newPorts, final boolean includeUnchanged) {
    // argument node is either a contained metanode or this wfm itself
    // (latter only when updating outgoing connections)
    List<Pair<ConnectionContainer, ConnectionContainer>> result = new ArrayList<Pair<ConnectionContainer, ConnectionContainer>>();
    final Set<ConnectionContainer> connectionsToMetaNode = m_connectionsByDest.get(metaNodeID);
    for (ConnectionContainer cc : connectionsToMetaNode) {
        int destPort = cc.getDestPort();
        boolean hasBeenFound = false;
        for (MetaPortInfo mpi : newPorts) {
            if (mpi.getOldIndex() == destPort) {
                hasBeenFound = true;
                if (mpi.getNewIndex() != destPort || includeUnchanged) {
                    ConnectionContainer newConn = new ConnectionContainer(cc.getSource(), cc.getSourcePort(), metaNodeID, mpi.getNewIndex(), cc.getType(), cc.isFlowVariablePortConnection());
                    newConn.setUIInfo(cc.getUIInfo());
                    result.add(new Pair<ConnectionContainer, ConnectionContainer>(cc, newConn));
                }
                break;
            }
        }
        if (!hasBeenFound) {
            throw new IllegalStateException("New meta port information array " + "does not include currently connected ports, unseen connection: " + cc);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) Pair(org.knime.core.util.Pair)

Example 40 with Pair

use of org.knime.core.util.Pair in project knime-core by knime.

the class BigGroupByTable method createTableRows.

/**
 * Creates and adds the result rows for the members of a data chunk to the
 * given data container. It also handles the row key mapping if hilite
 * translation is enabled.
 *
 * @param dc the {@link DataContainer} to use
 * @param chunkMembers the members of the current data chunk
 * @param groupCounter the number of groups that have been created
 * so fare
 */
private void createTableRows(final BufferedDataContainer dc, final Map<GroupKey, Pair<ColumnAggregator[], Set<RowKey>>> chunkMembers, final MutableInteger groupCounter) {
    if (chunkMembers == null || chunkMembers.isEmpty()) {
        return;
    }
    for (final Entry<GroupKey, Pair<ColumnAggregator[], Set<RowKey>>> e : chunkMembers.entrySet()) {
        final DataCell[] groupVals = e.getKey().getGroupVals();
        final ColumnAggregator[] colAggregators = e.getValue().getFirst();
        final RowKey rowKey = RowKey.createRowKey(groupCounter.intValue());
        groupCounter.inc();
        final DataCell[] rowVals = new DataCell[groupVals.length + colAggregators.length];
        // add the group values first
        int valIdx = 0;
        for (final DataCell groupCell : groupVals) {
            rowVals[valIdx++] = groupCell;
        }
        // add the aggregation values
        for (final ColumnAggregator colAggr : colAggregators) {
            final AggregationOperator operator = colAggr.getOperator(getGlobalSettings());
            rowVals[valIdx++] = operator.getResult();
            if (operator.isSkipped()) {
                // add skipped groups and the column that causes the
                // skipping into the skipped groups map
                addSkippedGroup(colAggr.getOriginalColName(), operator.getSkipMessage(), groupVals);
            }
            m_missingValuesMap.get(colAggr.getOriginalColName()).add(operator.getMissingValuesCount());
        }
        final DataRow newRow = new DefaultRow(rowKey, rowVals);
        dc.addRowToTable(newRow);
        if (isEnableHilite()) {
            final Set<RowKey> oldKeys = e.getValue().getSecond();
            addHiliteMapping(rowKey, oldKeys);
        }
    }
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Pair(org.knime.core.util.Pair)

Aggregations

Pair (org.knime.core.util.Pair)54 ArrayList (java.util.ArrayList)17 DataCell (org.knime.core.data.DataCell)14 DataType (org.knime.core.data.DataType)13 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)13 PortType (org.knime.core.node.port.PortType)13 LinkedHashMap (java.util.LinkedHashMap)11 Map (java.util.Map)10 DataColumnSpec (org.knime.core.data.DataColumnSpec)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 DataTableSpec (org.knime.core.data.DataTableSpec)9 FlowVariable (org.knime.core.node.workflow.FlowVariable)9 DataRow (org.knime.core.data.DataRow)8 StringCell (org.knime.core.data.def.StringCell)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)7 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)6 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)6 DefaultRow (org.knime.core.data.def.DefaultRow)6 DoubleCell (org.knime.core.data.def.DoubleCell)6