use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.
the class DialogComponentAggregationMethod method updateComponent.
/**
* {@inheritDoc}
*/
@Override
protected void updateComponent() {
final SettingsModelAggregationMethod model = getMethodModel();
// remove all listeners
m_valDelimiter.getDocument().removeDocumentListener(this);
m_maxUniqueVals.getDocument().removeDocumentListener(this);
m_aggregationMethod.removeItemListener(this);
m_inclMissing.removeItemListener(this);
m_valDelimiter.setText(model.getValueDelimiter());
m_maxUniqueVals.setText(Integer.toString(model.getMaxUniqueValues()));
final AggregationMethod modelVal = model.getAggregationMethod();
AggregationMethod val = null;
if (modelVal != null) {
for (int i = 0, length = m_aggregationMethod.getItemCount(); i < length; i++) {
final AggregationMethod curVal = m_aggregationMethod.getItemAt(i);
if (curVal.getId().equals(modelVal.getId())) {
// replace the instance in the combobox model with the actual instance from the settings model
// to keep all settings
m_aggregationMethodModel.removeElementAt(i);
m_aggregationMethodModel.insertElementAt(modelVal, i);
m_aggregationMethodModel.setSelectedItem(modelVal);
val = modelVal;
break;
}
}
if (val == null) {
val = modelVal;
}
}
boolean update;
if (val == null) {
update = m_aggregationMethod.getSelectedItem() != null;
} else {
update = !val.equals(m_aggregationMethod.getSelectedItem());
}
if (update) {
m_aggregationMethod.setSelectedItem(val);
}
final AggregationMethod selItem = getSelectedAggregationMethod();
boolean updateModel = (selItem == null && modelVal != null) || (selItem != null && !selItem.equals(modelVal));
if (val != null) {
// check if this has changed
if (m_inclMissing.isSelected() != val.inclMissingCells()) {
// it has changed set the new value and force the model update
updateModel = true;
m_inclMissing.setSelected(val.inclMissingCells());
}
}
// also update the enable status of all components
setEnabledComponents(getModel().isEnabled());
// add all listener
m_valDelimiter.getDocument().addDocumentListener(this);
m_maxUniqueVals.getDocument().addDocumentListener(this);
m_aggregationMethod.addItemListener(this);
m_inclMissing.addItemListener(this);
// make sure the model is in sync (in case model value isn't selected)
if (updateModel) {
// if the (initial) value in the model is not in the list
try {
updateModel();
} catch (InvalidSettingsException e) {
// ignore it here
}
}
}
use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.
the class DialogComponentAggregationMethod method setEnabledComponents.
/**
* {@inheritDoc}
*/
@Override
protected void setEnabledComponents(final boolean enabled) {
m_aggregationMethod.setEnabled(enabled);
final AggregationMethod method = getSelectedAggregationMethod();
m_inclMissing.setEnabled(method != null && method.supportsMissingValueOption() && enabled);
m_parameter.setEnabled(method != null && method.hasOptionalSettings() && enabled);
m_maxUniqueVals.setEnabled(enabled);
m_valDelimiter.setEnabled(enabled);
}
use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.
the class AggregationColumnPanel method getMethods4SelectedItems.
/**
* @return a label list of all supported methods for the currently
* selected rows
*/
protected List<Entry<String, List<AggregationMethod>>> getMethods4SelectedItems() {
final int[] selectedColumns = getSelectedRows();
final Set<DataType> types = new HashSet<>(selectedColumns.length);
for (final int row : selectedColumns) {
final ColumnAggregator aggregator = getTableModel().getRow(row);
types.add(aggregator.getOriginalDataType());
}
final DataType superType = CollectionCellFactory.getElementType(types.toArray(new DataType[0]));
final List<Entry<String, List<AggregationMethod>>> list = AggregationMethods.getCompatibleMethodGroupList(superType);
return list;
}
use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.
the class PatternAggregationTableModel method updateMethod.
/**
* @param row the row to update
* @param method the {@link AggregationMethod} to use
*/
private void updateMethod(final int row, final AggregationMethod method) {
final PatternAggregator old = getRow(row);
if (old.getMethodTemplate().getId().equals(method.getId())) {
// check if the method has changed
return;
}
// create a new operator each time it is updated to guarantee that
// each column has its own operator instance
final AggregationMethod methodClone = AggregationMethods.getMethod4Id(method.getId());
final PatternAggregator newRow = new PatternAggregator(old.getInputPattern(), old.isRegex(), methodClone, old.inclMissingCells());
newRow.setValid(old.isValid());
updateRow(row, newRow);
}
use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.
the class PatternAggregationTableModel method setValue.
/**
* {@inheritDoc}
*/
@Override
protected void setValue(final Object aValue, final int row, final int columnIdx) {
if (aValue == null) {
return;
}
switch(columnIdx) {
case 0:
updateRegexPattern(row, aValue.toString());
break;
case 1:
if (aValue instanceof Boolean) {
updateIsRegex(row, ((Boolean) aValue).booleanValue());
}
case 2:
if (aValue instanceof AggregationMethod) {
final AggregationMethod newMethod = (AggregationMethod) aValue;
updateMethod(row, newMethod);
}
break;
}
}
Aggregations