Search in sources :

Example 6 with ColProperty

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

Example 7 with ColProperty

use of org.knime.base.node.io.filereader.ColProperty in project knime-core by knime.

the class SpreadsheetTable method addColumn.

/**
 * {@inheritDoc}
 */
@Override
public void addColumn(final TableColumn aColumn) {
    int idx = aColumn.getModelIndex();
    // not that prop can be null
    ColProperty prop = getSpreadsheetModel().getColumnProperties().get(idx);
    aColumn.setHeaderValue(prop);
    aColumn.setPreferredWidth(aColumn.getPreferredWidth() + 5);
    super.addColumn(aColumn);
    if (null == m_colHeaderRenderer) {
        m_colHeaderRenderer = new ColumnHeaderRenderer(this);
    }
    aColumn.setHeaderRenderer(m_colHeaderRenderer);
}
Also used : ColProperty(org.knime.base.node.io.filereader.ColProperty)

Example 8 with ColProperty

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

Example 9 with ColProperty

use of org.knime.base.node.io.filereader.ColProperty in project knime-core by knime.

the class PasteAction method actionPerformed.

/**
 * {@inheritDoc}
 */
public void actionPerformed(final ActionEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    int startRow = m_table.getFocusedRow();
    int startCol = m_table.getFocusedColumn();
    m_endRow = startRow;
    m_endCol = startCol;
    m_tempModel = new SpreadsheetTableModel();
    try {
        String trstring = (String) (clipboard.getContents(this).getTransferData(DataFlavor.stringFlavor));
        StringTokenizer rows = new StringTokenizer(trstring, "\n", true);
        for (int i = 0; rows.hasMoreTokens(); i++) {
            String row = rows.nextToken();
            if (!row.equals("\n")) {
                StringTokenizer cells = new StringTokenizer(row, "\t", true);
                for (int j = 0; cells.hasMoreTokens(); j++) {
                    String value = cells.nextToken();
                    if (!value.equals("\t")) {
                        setValueAt(value, startRow + i, startCol + j);
                        if (cells.hasMoreTokens()) {
                            cells.nextToken();
                            // When row ends with a delimiter
                            if (!cells.hasMoreTokens()) {
                                setValueAt("", startRow + i, startCol + j + 1);
                            }
                        }
                    } else {
                        // a empty cell
                        setValueAt("", startRow + i, startCol + j);
                        // When row ends with a delimiter
                        if (!cells.hasMoreTokens()) {
                            setValueAt("", startRow + i, startCol + j + 1);
                        }
                    }
                }
                if (rows.hasMoreTokens()) {
                    rows.nextToken();
                }
            } else {
                // a empty row
                m_table.setValueAt("", startRow + i, startCol);
            }
        }
        m_table.getSpreadsheetModel().addValues(m_tempModel.getTableValues());
        m_tempModel.setData(new HashMap<Integer, ColProperty>(), new int[0], new int[0], new String[0]);
        m_tempModel = null;
        m_table.getSelectionModel().setSelectionInterval(startRow, m_endRow);
        m_table.getColumnModel().getSelectionModel().setSelectionInterval(startCol, m_endCol);
    } catch (Exception ex) {
        throw new IllegalArgumentException(ex.getMessage());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Clipboard(java.awt.datatransfer.Clipboard) ColProperty(org.knime.base.node.io.filereader.ColProperty)

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