Search in sources :

Example 1 with MissingValue

use of org.knime.core.data.MissingValue in project knime-core by knime.

the class RuleEngine2PortsSimpleNodeDialog method createSettingsPanel.

/**
 * @param settingsType The kind of the dialog.
 * @return The "Settings" panel.
 */
protected JPanel createSettingsPanel(final RuleNodeSettings settingsType) {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.ipadx = 4;
    gbc.ipady = 4;
    gbc.insets = new Insets(1, 2, 0, 2);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    panel.add(new JLabel("Rules column:"), gbc);
    gbc.gridx++;
    gbc.weightx = 1;
    panel.add(m_ruleColumn, gbc);
    gbc.gridx++;
    gbc.weightx = 0;
    panel.add(new JLabel("=>"), gbc);
    gbc.gridx++;
    gbc.weightx = 1;
    panel.add(m_outcomeColumn, gbc);
    gbc.weightx = 0;
    gbc.gridx++;
    panel.add(m_outcomeType, gbc);
    gbc.gridy++;
    gbc.gridx--;
    panel.add(m_treatOutcomesWithDollarAsReferences, gbc);
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.gridwidth = 1;
    addAppendOrReplace(panel, gbc);
    gbc.gridx = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weighty = 1;
    gbc.gridwidth = 5;
    m_errorPanel = new JScrollPane(m_errors);
    m_errorPanel.setBorder(new TitledBorder("Errors"));
    panel.add(m_errorPanel, gbc);
    panel.add(m_noErrors, gbc);
    m_errors.getColumnModel().getColumn(0).setMaxWidth(1000);
    m_errors.getColumnModel().getColumn(0).setPreferredWidth(44);
    final TableColumn contentColumn = m_errors.getColumnModel().getColumn(1);
    final DefaultTableCellRenderer origRenderer = new DefaultTableCellRenderer();
    contentColumn.setCellRenderer(new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
            Component ret = origRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof MissingValue) {
                MissingValue mv = (MissingValue) value;
                if (ret instanceof JLabel) {
                    JLabel retLabel = (JLabel) ret;
                    retLabel.setText(mv.getError());
                }
                ret.setBackground(Color.RED);
            }
            return ret;
        }
    });
    gbc.gridy++;
    gbc.weighty = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    JScrollPane warningPanel = new JScrollPane(m_warnings);
    warningPanel.setBorder(new TitledBorder("Warnings"));
    m_warnings.setFont(UIManager.getFont("TextField.font"));
    panel.add(warningPanel, gbc);
    return panel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) MissingValue(org.knime.core.data.MissingValue) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) PortObject(org.knime.core.node.port.PortObject) Component(java.awt.Component)

Example 2 with MissingValue

use of org.knime.core.data.MissingValue in project knime-core by knime.

the class DefaultDataValueRenderer method getMissingValueRendererComponent.

/**
 * Manly to avoid code duplication. Method used by
 * {@link #getTableMissingValueRendererComponent(JTable, Object, boolean, boolean, int, int)} and
 * {@link #getListMissingValueRendererComponent(JList, Object, int, boolean, boolean)}.
 *
 * @param value
 * @return returns <code>this</code> since the {@link DefaultDataValueRenderer} is a {@link Component} by itself
 * @since 3.3
 */
protected Component getMissingValueRendererComponent(final Object value) {
    setForeground(Color.RED);
    MissingValue val = (MissingValue) value;
    setToolTipText("Missing Value" + (val.getError() != null ? " (" + val.getError() + ")" : ""));
    setValue("?");
    return this;
}
Also used : MissingValue(org.knime.core.data.MissingValue)

Example 3 with MissingValue

use of org.knime.core.data.MissingValue in project knime-core by knime.

the class ExpressionFactory method compare.

/**
 * {@inheritDoc}
 */
@Override
public Expression compare(final Expression left, final Expression right, final DataValueComparator cmp, final int... possibleValues) {
    return new Expression.Base(left, right) {

        /**
         * {@inheritDoc}
         */
        @Override
        public List<DataType> getInputArgs() {
            return Arrays.asList(left.getOutputType(), right.getOutputType());
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public DataType getOutputType() {
            return BooleanCell.TYPE;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public ExpressionValue evaluate(final DataRow row, final VariableProvider provider) {
            ExpressionValue leftValue = left.evaluate(row, provider);
            ExpressionValue rightValue = right.evaluate(row, provider);
            Map<String, Map<String, String>> mergedObjects = Util.mergeObjects(leftValue.getMatchedObjects(), rightValue.getMatchedObjects());
            DataCell leftCell = leftValue.getValue();
            DataCell rightCell = rightValue.getValue();
            final boolean leftMissing = leftCell.isMissing(), rightMissing = rightCell.isMissing();
            // Priority over NaNs
            if (!m_missingMatch && (leftMissing || rightMissing)) {
                boolean bothMissingAndAllowEquals = leftMissing && rightMissing && Arrays.binarySearch(possibleValues, 0) >= 0;
                if (bothMissingAndAllowEquals) {
                    if (leftCell instanceof MissingValue) {
                        MissingValue lmc = (MissingValue) leftCell;
                        if (rightCell instanceof MissingValue) {
                            MissingValue rmc = (MissingValue) rightCell;
                            // If the errors differ we do not consider them equal
                            bothMissingAndAllowEquals = lmc.equals(rmc);
                        }
                    }
                }
                return new ExpressionValue(BooleanCellFactory.create(bothMissingAndAllowEquals), mergedObjects);
            }
            // No missing values
            final boolean leftNaN = isNaN(leftCell), rightNaN = isNaN(rightCell);
            if (!m_nanMatch && (leftNaN || rightNaN)) {
                // NaNs are considered equals to each other even if it is not by the IEEE spec.
                boolean bothNaNAndAllowEquals = leftNaN && rightNaN && Arrays.binarySearch(possibleValues, 0) >= 0;
                return new ExpressionValue(BooleanCellFactory.create(bothNaNAndAllowEquals), mergedObjects);
            }
            boolean found = false;
            int compareResult = Util.signum(cmp.compare(leftCell, rightCell));
            for (int possibleValue : possibleValues) {
                found |= possibleValue == compareResult;
            }
            return new ExpressionValue(BooleanCellFactory.create(found), mergedObjects);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean isConstant() {
            return left.isConstant() && right.isConstant();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            String rel = "???";
            if (Arrays.equals(possibleValues, LT)) {
                rel = "<";
            } else if (Arrays.equals(possibleValues, LE)) {
                rel = "<=";
            } else if (Arrays.equals(possibleValues, GT)) {
                rel = ">";
            } else if (Arrays.equals(possibleValues, GE)) {
                rel = ">=";
            } else if (Arrays.equals(possibleValues, EQ)) {
                rel = "=";
            }
            return left + rel + right;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public ASTType getTreeType() {
            if (Arrays.equals(possibleValues, LT)) {
                return ASTType.Less;
            }
            if (Arrays.equals(possibleValues, LE)) {
                return ASTType.LessOrEquals;
            }
            if (Arrays.equals(possibleValues, GT)) {
                return ASTType.Greater;
            }
            if (Arrays.equals(possibleValues, GE)) {
                return ASTType.GreaterOrEquals;
            }
            if (Arrays.equals(possibleValues, EQ)) {
                return ASTType.Equals;
            }
            throw new IllegalStateException("" + Arrays.toString(possibleValues));
        }
    };
}
Also used : MissingValue(org.knime.core.data.MissingValue) DataRow(org.knime.core.data.DataRow) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MissingValue (org.knime.core.data.MissingValue)3 Component (java.awt.Component)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 TitledBorder (javax.swing.border.TitledBorder)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 TableColumn (javax.swing.table.TableColumn)1 DataCell (org.knime.core.data.DataCell)1 DataRow (org.knime.core.data.DataRow)1 DataType (org.knime.core.data.DataType)1 PortObject (org.knime.core.node.port.PortObject)1