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;
}
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;
}
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));
}
};
}
Aggregations