use of org.knime.base.node.io.filereader.ColProperty in project knime-core by knime.
the class TableCreator2NodeSettings method readColumnPropsFromConfig.
private void readColumnPropsFromConfig(final NodeSettingsRO cfg) throws InvalidSettingsException {
m_colProps = new TreeMap<Integer, ColProperty>();
for (String key : cfg.keySet()) {
Integer col = Integer.valueOf(key);
m_colProps.put(col, new ColProperty(cfg.getNodeSettings(key)));
}
}
use of org.knime.base.node.io.filereader.ColProperty 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.ColProperty in project knime-core by knime.
the class PropertyColumnsAction method createDefaultColumnProperty.
/**
* Generates a {@link ColProperty} object with default settings.
* @param props Properties of the current columns of the table
* @return a {@link ColProperty} object with default settings
*/
static ColProperty createDefaultColumnProperty(final SortedMap<Integer, ColProperty> props) {
DataColumnSpec firstColSpec = new DataColumnSpecCreator(getUniqueName(props), StringCell.TYPE).createSpec();
ColProperty target = new ColProperty();
target.setColumnSpec(firstColSpec);
// this will cause it to be ignored when re-analyzing:
target.setUserSettings(false);
target.setMissingValuePattern("");
return target;
}
use of org.knime.base.node.io.filereader.ColProperty in project knime-core by knime.
the class PropertyColumnsAction method getUniqueName.
/**
* Generates a name following the pattern: "column <integer>"
*/
private static String getUniqueName(final SortedMap<Integer, ColProperty> props) {
Set<String> names = new HashSet<String>();
for (ColProperty prop : props.values()) {
names.add(prop.getColumnSpec().getName());
}
int i = 1;
String prefix = "column";
String newName = prefix + i;
while (names.contains(newName)) {
i++;
newName = prefix + i;
}
return newName;
}
use of org.knime.base.node.io.filereader.ColProperty in project knime-core by knime.
the class PropertyColumnsAction method actionPerformed.
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(final ActionEvent e) {
int colIdx = m_table.getColumnModel().getSelectionModel().getMinSelectionIndex();
if (colIdx < 0) {
// nothing selected, do not add column with negative index
return;
}
SortedMap<Integer, ColProperty> props = ((SpreadsheetTableModel) m_table.getModel()).getColumnProperties();
ColProperty target = props.get(colIdx);
if (null == target) {
target = createDefaultColumnProperty(props);
}
Vector<ColProperty> colProps = new Vector<ColProperty>();
for (Integer idx : props.keySet()) {
if (idx != colIdx) {
colProps.add(props.get(idx));
}
}
colProps.add(target);
Frame parent = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, m_table);
Vector<ColProperty> result = ColPropertyDialog.openUserDialog(parent, colProps.size() - 1, colProps);
if (null != result) {
// props.put(colIdx, result.get(colProps.size() - 1));
((SpreadsheetTableModel) m_table.getModel()).setColProperty(colIdx, result.get(colProps.size() - 1));
}
m_table.getColumnModel().getSelectionModel().setSelectionInterval(colIdx, colIdx);
}
Aggregations