use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class InFieldsTable method createInputCellEditor.
/**
* Create cell editor for for the input columns / flow variables.
*/
private TableCellEditor createInputCellEditor() {
JComboBox comboBox = new JComboBox();
comboBox.setRenderer(new InputListCellRenderer());
if (null != m_spec) {
for (DataColumnSpec colSpec : m_spec) {
comboBox.addItem(colSpec);
}
}
if (null != m_flowVars) {
for (FlowVariable flowVar : m_flowVars.values()) {
comboBox.addItem(flowVar);
}
}
DefaultCellEditor editor = new DefaultCellEditor(comboBox);
editor.setClickCountToStart(2);
return editor;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class InFieldsTable method updateData.
/**
* Set the table data.
*
* @param fields the fields
* @param spec the input spec might be null
* @param flowVars the flow variables
*/
void updateData(final JavaSnippetFields fields, final DataTableSpec spec, final Map<String, FlowVariable> flowVars) {
m_spec = spec;
m_flowVars = flowVars;
m_model.clear();
for (int r = 0; r < fields.getInColFields().size(); r++) {
InCol field = fields.getInColFields().get(r);
m_model.addRow();
String colName = field.getKnimeName();
DataColumnSpec colSpec = spec.getColumnSpec(colName);
Object value = null != colSpec ? colSpec : colName;
m_model.setValueAt(value, r, Column.COLUMN);
m_model.setValueAt(field.getJavaName(), r, Column.JAVA_FIELD);
Optional<?> factory = ConverterUtil.getDataCellToJavaConverterFactory(field.getConverterFactoryId());
if (!factory.isPresent()) {
// seems to be missing.
if (field.getJavaType() != null) {
factory = ConverterUtil.getConverterFactory(field.getDataType(), field.getJavaType());
}
}
if (factory.isPresent()) {
m_model.setValueAt(factory.get(), r, Column.JAVA_TYPE);
} else {
final Class<?> type = field.getJavaType();
if (type != null) {
m_model.setValueAt(type, r, Column.JAVA_TYPE);
} else {
m_model.setValueAt(field.getJavaTypeName(), r, Column.JAVA_TYPE);
}
}
}
int offset = m_model.getRowCount();
for (int r = 0; r < fields.getInVarFields().size(); r++) {
InVar field = fields.getInVarFields().get(r);
m_model.addRow();
String name = field.getKnimeName();
FlowVariable flowVar = m_flowVars.get(name);
Object value = null != flowVar ? flowVar : name;
m_model.setValueAt(value, offset + r, Column.COLUMN);
m_model.setValueAt(field.getJavaName(), offset + r, Column.JAVA_FIELD);
m_model.setValueAt(field.getJavaType(), offset + r, Column.JAVA_TYPE);
}
JTable table = getTable();
final TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellRenderer(new InputTableCellRenderer());
columnModel.getColumn(m_model.getIndex(Column.COLUMN)).setCellEditor(createInputCellEditor());
columnModel.getColumn(m_model.getIndex(Column.JAVA_FIELD)).setCellRenderer(FieldsTableUtil.createJavaFieldTableCellRenderer());
columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellRenderer(FieldsTableUtil.createJavaTypeTableCellRenderer());
columnModel.getColumn(m_model.getIndex(Column.JAVA_TYPE)).setCellEditor(FieldsTableUtil.createJavaTypeTableCellEditor());
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class JSnippetFieldsController method getFieldReadStatement.
/**
* Get a statement to inserted in the document of a java snippet to read
* the given column.
* @param colSpec the column to be read
* @return the statement
*/
public String getFieldReadStatement(final DataColumnSpec colSpec) {
FieldsTableModel model = (FieldsTableModel) m_inFieldsTable.getTable().getModel();
int index = -1;
for (int r = 0; r < model.getRowCount(); r++) {
Object value = model.getValueAt(r, Column.COLUMN);
if (value instanceof DataColumnSpec) {
DataColumnSpec foo = (DataColumnSpec) value;
if (foo.getName().equals(colSpec.getName())) {
index = r;
break;
}
}
}
if (index >= 0) {
// return java field name
return (String) model.getValueAt(index, Column.JAVA_FIELD);
} else {
// try to add a row for the colSpec
boolean success = m_inFieldsTable.addRow(colSpec);
if (success) {
TableModel tableModel = m_inFieldsTable.getTable().getModel();
m_inFieldsTable.firePropertyChange(InFieldsTable.PROP_FIELD_ADDED, tableModel.getRowCount() - 1, tableModel.getRowCount());
// return java field name
return (String) model.getValueAt(model.getRowCount() - 1, Column.JAVA_FIELD);
} else {
// return generic code
String name = colSpec.getName();
final Collection<DataCellToJavaConverterFactory<?, ?>> factories = ConverterUtil.getFactoriesForSourceType(colSpec.getType());
return "getCell(\"" + name + "\", " + Type.getIdentifierFor(factories.stream().findFirst().get().getDestinationType()) + ")";
}
}
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class ModifyTimeNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) {
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
// determine the data type of output
DataType dataType;
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_REMOVE)) {
dataType = LocalDateCellFactory.TYPE;
} else {
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = LocalDateTimeCellFactory.TYPE;
} else {
if (m_timeZone.useZone()) {
dataType = ZonedDateTimeCellFactory.TYPE;
} else {
dataType = LocalDateTimeCellFactory.TYPE;
}
}
}
int i = 0;
for (final String includedCol : includeList) {
if (inSpec.getColumnSpec(includedCol).getType().equals(ZonedDateTimeCellFactory.TYPE) && m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = ZonedDateTimeCellFactory.TYPE;
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, dataType);
final SingleCellFactory cellFac = createCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++], m_timeZone.getZone());
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], m_timeZone.getZone());
rearranger.append(cellFac);
}
}
return rearranger;
}
use of org.knime.core.data.DataColumnSpec in project knime-core by knime.
the class ModifyDateNodeModel method createColumnRearranger.
/**
* @param inSpec table input spec
* @return the CR describing the output
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec inSpec) {
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndices = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
// determine the data type of output
DataType dataType;
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_REMOVE)) {
dataType = LocalTimeCellFactory.TYPE;
} else {
if (m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = LocalDateTimeCellFactory.TYPE;
} else {
if (m_timeZone.useZone()) {
dataType = ZonedDateTimeCellFactory.TYPE;
} else {
dataType = LocalDateTimeCellFactory.TYPE;
}
}
}
final ZoneId zone = m_timeZone.getZone();
int i = 0;
for (final String includedCol : includeList) {
if (inSpec.getColumnSpec(includedCol).getType().equals(ZonedDateTimeCellFactory.TYPE) && m_modifyAction.getStringValue().equals(MODIFY_OPTION_CHANGE)) {
dataType = ZonedDateTimeCellFactory.TYPE;
}
if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includedCol, dataType);
final SingleCellFactory cellFac = createCellFactory(dataColumnSpecCreator.createSpec(), includeIndices[i++], zone);
rearranger.replace(cellFac, includedCol);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includedCol + m_suffix.getStringValue(), dataType);
final SingleCellFactory cellFac = createCellFactory(dataColSpec, includeIndices[i++], zone);
rearranger.append(cellFac);
}
}
return rearranger;
}
Aggregations