Search in sources :

Example 6 with AggregationMethod

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
        }
    }
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 7 with AggregationMethod

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);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod)

Example 8 with AggregationMethod

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;
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) Entry(java.util.Map.Entry) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet)

Example 9 with AggregationMethod

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);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod)

Example 10 with AggregationMethod

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;
    }
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod)

Aggregations

AggregationMethod (org.knime.base.data.aggregation.AggregationMethod)27 ColumnAggregator (org.knime.base.data.aggregation.ColumnAggregator)8 ArrayList (java.util.ArrayList)6 Entry (java.util.Map.Entry)4 DataType (org.knime.core.data.DataType)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 Component (java.awt.Component)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 List (java.util.List)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)2 Container (java.awt.Container)1 Frame (java.awt.Frame)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 JTable (javax.swing.JTable)1 AggregationOperator (org.knime.base.data.aggregation.AggregationOperator)1