use of org.knime.base.node.io.filereader.DataCellFactory in project knime-core by knime.
the class ColumnAutoTypeCasterNodeModel method createNumberConverter.
private SingleCellFactory createNumberConverter(final int colIdx, final DataType type, final DataColumnSpec colSpec) {
return new SingleCellFactory(colSpec) {
private final DataCellFactory m_fac = new DataCellFactory();
@Override
public DataCell getCell(final DataRow row) {
m_fac.setMissingValuePattern(m_missValPat);
DataCell cell = row.getCell(colIdx);
if (!cell.isMissing()) {
String str = cell.toString();
if (str == null) {
return DataType.getMissingCell();
}
// create String-, Int- or DoubleCell
DataCell c = m_fac.createDataCellOfType(type, str);
if (c == null) {
throw new NumberFormatException("Can't convert '" + str + "' to " + type.toString() + ". In " + row.getKey() + " Column" + colIdx + ". Disable " + "quickscan and try again.");
}
return c;
} else {
// create MissingCell
return DataType.getMissingCell();
}
}
};
}
use of org.knime.base.node.io.filereader.DataCellFactory in project knime-core by knime.
the class TableCreator2NodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec outSpec = createSpec();
BufferedDataContainer cont = exec.createDataContainer(outSpec, true);
int numColProps = m_settings.getColumnProperties().size();
ColProperty[] colProps = new ColProperty[numColProps];
for (int i = 0; i < numColProps; i++) {
colProps[i] = m_settings.getColumnProperties().get(i);
}
int cc = 0;
int[] notSkippedMap = new int[numColProps];
for (int i = 0; i < numColProps; i++) {
notSkippedMap[i] = cc;
if (!colProps[i].getSkipThisColumn()) {
cc++;
}
}
int numRows = max(m_settings.getRowIndices()) + 1;
String rowIdPrefix = m_settings.getRowIdPrefix();
String rowIdSuffix = m_settings.getRowIdSuffix();
int rowIdStartWidth = m_settings.getRowIdStartValue();
int c = 0;
// fix for bug #2969
Set<Integer> toRemove = new HashSet<Integer>();
DataCellFactory cellFactory = new DataCellFactory();
for (int i = 0; i < numRows; i++) {
DataCell[] cells = new DataCell[outSpec.getNumColumns()];
for (int k = 0; k < numColProps; k++) {
// fix for bug #2969
while (c < m_settings.getRowIndices().length && (m_settings.getRowIndices()[c] < 0 || m_settings.getColumnIndices()[c] < 0)) {
toRemove.add(c);
c++;
}
String value = "";
if (c < m_settings.getRowIndices().length && m_settings.getRowIndices()[c] == i && m_settings.getColumnIndices()[c] == k) {
value = m_settings.getValues()[c];
c++;
}
if (colProps[k].getSkipThisColumn()) {
continue;
}
String missValPattern = colProps[k].getMissingValuePattern();
cellFactory.setMissingValuePattern(missValPattern);
cellFactory.setFormatParameter(colProps[k].getFormatParameter().orElse(null));
DataCell result = cellFactory.createDataCellOfType(colProps[k].getColumnSpec().getType(), value);
if (null != result) {
cells[notSkippedMap[k]] = result;
} else {
throw new InvalidSettingsException(cellFactory.getErrorMessage());
}
}
StringBuilder rowId = new StringBuilder();
rowId.append(rowIdPrefix);
rowId.append(Integer.toString(i + rowIdStartWidth));
rowId.append(rowIdSuffix);
DataRow row = new DefaultRow(rowId.toString(), cells);
cont.addRowToTable(row);
}
cont.close();
BufferedDataTable out = cont.getTable();
return new BufferedDataTable[] { out };
}
use of org.knime.base.node.io.filereader.DataCellFactory in project knime-core by knime.
the class Cell method getValue.
/**
* @return the value
*/
final DataCell getValue() {
if (m_value == null) {
DataCellFactory cellFactory = new DataCellFactory();
cellFactory.setMissingValuePattern(m_missingValuePattern);
m_value = null != m_text ? cellFactory.createDataCellOfType(m_type, m_text) : DataType.getMissingCell();
m_errorMessage = cellFactory.getErrorMessage() == null ? "" : cellFactory.getErrorMessage();
}
return m_value;
}
use of org.knime.base.node.io.filereader.DataCellFactory in project knime-core by knime.
the class Spreadsheet method hasParseErrors.
/**
* @return true when not every cell can be parsed
*/
public boolean hasParseErrors() {
SpreadsheetTableModel model = m_table.getSpreadsheetModel();
int colCount = model.getMaxColumn();
int rowCount = model.getMaxRow();
for (int k = 0; k < colCount; k++) {
ColProperty colProperty = model.getColumnProperties().get(k);
for (int i = 0; i < rowCount; i++) {
Object value = model.getValueAt(i, k);
if (value instanceof Cell) {
Cell cell = (Cell) value;
if (cell.getValue() == null) {
return true;
}
} else {
// value is an empty string
if (null != colProperty) {
DataCellFactory cellFactory = new DataCellFactory();
cellFactory.setMissingValuePattern(colProperty.getMissingValuePattern());
cellFactory.setFormatParameter(colProperty.getFormatParameter().orElse(null));
DataCell dataCell = cellFactory.createDataCellOfType(colProperty.getColumnSpec().getType(), value.toString());
if (null == dataCell) {
return true;
}
}
}
}
}
return false;
}
use of org.knime.base.node.io.filereader.DataCellFactory in project knime-core by knime.
the class CellRenderer method getTableCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
setForeground(table.getForeground());
setBackground(table.getBackground());
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (m_showOutputTable && (!isInFilledArea(row, column) || isSkipped(column))) {
if (isSelected) {
setForeground(m_notInOutputSelForeground);
setBackground(m_notInOutputSelBackground);
} else {
setForeground(m_notInOutputForeground);
setBackground(m_notInOutputBackground);
}
}
ColProperty colProperty = m_tableModel.getColumnProperties().get(column);
if (value instanceof Cell) {
Cell cell = (Cell) value;
if (cell.getValue() == null) {
setBackground(reddishBackground());
setForeground(table.getForeground());
}
} else {
// value is an empty string
if (null != colProperty && isInFilledArea(row, column)) {
DataCellFactory cellFactory = new DataCellFactory();
cellFactory.setMissingValuePattern(colProperty.getMissingValuePattern());
cellFactory.setFormatParameter(colProperty.getFormatParameter().orElse(null));
DataCell dataCell = cellFactory.createDataCellOfType(colProperty.getColumnSpec().getType(), value.toString());
if (null == dataCell) {
setBackground(reddishBackground());
setForeground(table.getForeground());
}
}
}
return this;
}
Aggregations