Search in sources :

Example 1 with ColProperty

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)));
    }
}
Also used : ColProperty(org.knime.base.node.io.filereader.ColProperty)

Example 2 with ColProperty

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataCellFactory(org.knime.base.node.io.filereader.DataCellFactory) ColProperty(org.knime.base.node.io.filereader.ColProperty) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) HashSet(java.util.HashSet)

Example 3 with ColProperty

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;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ColProperty(org.knime.base.node.io.filereader.ColProperty)

Example 4 with ColProperty

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;
}
Also used : ColProperty(org.knime.base.node.io.filereader.ColProperty) HashSet(java.util.HashSet)

Example 5 with ColProperty

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);
}
Also used : Frame(java.awt.Frame) ColProperty(org.knime.base.node.io.filereader.ColProperty) Vector(java.util.Vector)

Aggregations

ColProperty (org.knime.base.node.io.filereader.ColProperty)9 DataCellFactory (org.knime.base.node.io.filereader.DataCellFactory)3 DataCell (org.knime.core.data.DataCell)3 HashSet (java.util.HashSet)2 Frame (java.awt.Frame)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringTokenizer (java.util.StringTokenizer)1 Vector (java.util.Vector)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DataRow (org.knime.core.data.DataRow)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1