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