use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class StringManipulationNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
DataTableSpec spec;
if (m_isOnlyVariables) {
spec = new DataTableSpec();
} else {
spec = (DataTableSpec) specs[0];
}
StringManipulationSettings s = new StringManipulationSettings();
s.loadSettingsInDialog(settings, spec);
String exp = s.getExpression();
String defaultNewName = "new " + m_columnOrVariable;
String newName = s.getColName();
boolean isReplace = s.isReplace();
boolean isTestCompilation = s.isTestCompilationOnDialogClose();
boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
m_newNameField.setText("");
final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
if (m_isOnlyVariables) {
DefaultComboBoxModel<FlowVariable> cmbModel = (DefaultComboBoxModel<FlowVariable>) m_replaceVariableCombo.getModel();
cmbModel.removeAllElements();
for (FlowVariable v : availableFlowVariables.values()) {
switch(v.getScope()) {
case Flow:
cmbModel.addElement(v);
break;
default:
}
}
if (availableFlowVariables.containsValue(newName)) {
m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
}
} else {
// will select newColName only if it is in the spec list
try {
m_replaceColumnCombo.update(spec, newName);
} catch (NotConfigurableException e1) {
NodeLogger.getLogger(getClass()).coding("Combo box throws exception although content is not required", e1);
}
}
m_currentSpec = spec;
// whether there are variables or columns available
// -- which of two depends on the customizer
boolean fieldsAvailable;
if (m_isOnlyVariables) {
fieldsAvailable = m_replaceVariableCombo.getItemCount() > 0;
} else {
fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
}
m_replaceRadio.setEnabled(fieldsAvailable);
if (isReplace && fieldsAvailable) {
m_replaceRadio.doClick();
} else {
m_appendRadio.doClick();
String newNameString = (newName != null ? newName : defaultNewName);
m_newNameField.setText(newNameString);
}
m_snippetPanel.update(exp, spec, availableFlowVariables);
m_compileOnCloseChecker.setSelected(isTestCompilation);
m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class StringManipulationNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec inSpec = inData[0].getDataTableSpec();
ColumnRearranger c = createColumnRearranger(inSpec);
m_rowCount = inData[0].size();
try {
BufferedDataTable o = exec.createColumnRearrangeTable(inData[0], c, exec);
return new BufferedDataTable[] { o };
} finally {
m_rowCount = -1L;
}
}
use of org.knime.core.data.DataTableSpec 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.DataTableSpec in project knime-core by knime.
the class ModifyTimeNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
throw new InvalidSettingsException("Node must be configured!");
}
DataTableSpec in = inSpecs[0];
ColumnRearranger r = createColumnRearranger(in);
DataTableSpec out = r.createSpec();
return new DataTableSpec[] { out };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class ModifyDateNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (!m_hasValidatedConfiguration) {
throw new InvalidSettingsException("Node must be configured!");
}
DataTableSpec in = inSpecs[0];
ColumnRearranger r = createColumnRearranger(in);
DataTableSpec out = r.createSpec();
return new DataTableSpec[] { out };
}
Aggregations