use of org.knime.core.node.util.dialog.field.OutColumnField in project knime-core by knime.
the class OutFieldsTable method updateData.
/**
* Set the table data.
*
* @param fields the fields
* @param spec the input spec
* @param flowVars the flow variables
*/
public void updateData(final FieldCollection fields, final DataTableSpec spec, final Map<String, FlowVariable> flowVars) {
m_spec = spec;
m_flowVars = flowVars;
m_model.clear();
for (int r = 0; r < fields.getOutColumnList().size(); r++) {
OutColumnField field = fields.getOutColumnList().get(r);
addRow(field);
}
for (int r = 0; r < fields.getOutFlowVariableList().size(); r++) {
OutFlowVariableField field = fields.getOutFlowVariableList().get(r);
addRow(field);
}
JTable table = getTable();
table.getColumnModel().getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellRenderer(new BooleanRenderer());
table.getColumnModel().getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellEditor(new DefaultCellEditor(new JCheckBox()));
if (!m_flowVarsOnly) {
table.getColumnModel().getColumn(m_model.getIndex(Column.FIELD_TYPE)).setCellEditor(createFieldTypeCellEditor());
}
table.getColumnModel().getColumn(m_model.getIndex(Column.COLUMN)).setCellRenderer(new InputTableCellRenderer());
table.getColumnModel().getColumn(m_model.getIndex(Column.COLUMN)).setCellEditor(new InputTableCellEditor(this, m_spec, m_flowVars));
table.getColumnModel().getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellRenderer(new DataTypeTableCellRenderer());
table.getColumnModel().getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellEditor(new DataTypeTableCellEditor(this, m_spec, m_flowVars));
if (!m_flowVarsOnly) {
table.getColumnModel().getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellRenderer(new BooleanRenderer() {
/**
* {@inheritDoc}
*/
@Override
public Component getTableCellRendererComponent(final JTable fooTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
Component comp = super.getTableCellRendererComponent(fooTable, value, isSelected, hasFocus, row, column);
FieldType fieldType = getFieldType(row);
comp.setEnabled(fieldType.equals(FieldType.Column));
return comp;
}
});
table.getColumnModel().getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellEditor(new DefaultCellEditor(new JCheckBox()) {
/**
* {@inheritDoc}
*/
@Override
public boolean isCellEditable(final EventObject anEvent) {
int row = getTable().rowAtPoint(((MouseEvent) anEvent).getPoint());
FieldType fieldType = getFieldType(row);
return fieldType.equals(FieldType.Column);
}
});
}
if (m_defineDefaultValues) {
table.getColumnModel().getColumn(m_model.getIndex(Column.DEFAULT_VALUE)).setCellRenderer(new DefaultFieldTableCellRenderer());
}
}
use of org.knime.core.node.util.dialog.field.OutColumnField in project knime-core by knime.
the class AddOutFieldDialog method takeOverSettings.
/**
* Save settings in field m_result.
*/
@SuppressWarnings("rawtypes")
private AbstractField takeOverSettings() {
if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
OutColumnField outCol = new OutColumnField();
boolean isReplacing = m_replace.isSelected();
outCol.setReplaceExisting(isReplacing);
String colName = isReplacing ? ((DataColumnSpec) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
outCol.setKnimeName(colName);
DataType elemType = (DataType) m_knimeType.getSelectedItem();
boolean isCollection = m_isArray.isSelected();
DataType dataType = isCollection ? ListCell.getCollectionType(elemType) : elemType;
TypeProvider typeProvider = TypeProvider.getDefault();
if (!typeProvider.getColumnTypes().contains(elemType)) {
elemType = new StringCell("").getType();
isCollection = false;
}
outCol.setKnimeType(dataType);
return outCol;
} else {
// flow variable
OutFlowVariableField outVar = m_defineDefaultValue ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
boolean isReplacing = m_replace.isSelected();
outVar.setReplaceExisting(isReplacing);
String colName = isReplacing ? ((FlowVariable) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
outVar.setKnimeName(colName);
FlowVariable.Type type = (FlowVariable.Type) m_knimeType.getSelectedItem();
outVar.setKnimeType(type);
if (m_defineDefaultValue) {
DefaultOutFlowVariableField dFVar = (DefaultOutFlowVariableField) outVar;
switch(type) {
case INTEGER:
dFVar.setDefaultValue(Integer.parseInt(m_defaultValue.getText()));
break;
case DOUBLE:
dFVar.setDefaultValue(Double.parseDouble(m_defaultValue.getText()));
break;
default:
dFVar.setDefaultValue(m_defaultValue.getText());
}
}
return outVar;
}
}
use of org.knime.core.node.util.dialog.field.OutColumnField in project knime-core by knime.
the class OutFieldsTable method getOutColFields.
/**
* Get the field definitions representing output columns.
*
* @return fields representing output columns.
*/
public OutColumnList getOutColFields() {
OutColumnList outCols = new OutColumnList();
for (int r = 0; r < m_model.getRowCount(); r++) {
if (!m_model.validateValues(r)) {
// there are errors in this row
continue;
}
Object fieldTypeValue = getFieldType(r);
if (null == fieldTypeValue) {
continue;
}
boolean isColumn = fieldTypeValue.equals(FieldType.Column);
if (isColumn) {
OutColumnField outCol = new OutColumnField();
outCol.setReplaceExisting((Boolean) m_model.getValueAt(r, Column.REPLACE_EXISTING));
Object colColValue = m_model.getValueAt(r, Column.COLUMN);
if (colColValue instanceof DataColumnSpec) {
DataColumnSpec colSpec = (DataColumnSpec) colColValue;
outCol.setKnimeName(colSpec.getName());
} else if (colColValue instanceof String) {
outCol.setKnimeName(colColValue.toString());
} else {
continue;
}
Object dataTypeValue = m_model.getValueAt(r, Column.DATA_TYPE);
boolean isArray = (Boolean) m_model.getValueAt(r, Column.IS_COLLECTION);
if (dataTypeValue instanceof DataType) {
DataType type = (DataType) dataTypeValue;
if (isArray) {
type = ListCell.getCollectionType(type);
}
outCol.setKnimeType(type);
} else {
continue;
}
outCols.add(outCol);
}
}
return outCols;
}
Aggregations