Search in sources :

Example 11 with AggregationMethod

use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.

the class PatternAggregationTableModel method updateRegex.

private void updateRegex(final int row, final String pattern, final boolean isRegex, final PatternAggregator old) {
    // create a new operator each time it is updated to guarantee that
    // each column has its own operator instance
    final AggregationMethod methodClone = AggregationMethods.getMethod4Id(old.getMethodTemplate().getId());
    final PatternAggregator regexAggregator = new PatternAggregator(pattern, isRegex, methodClone, old.inclMissingCells());
    if (!regexAggregator.isValid()) {
        try {
            Pattern.compile(pattern);
        } catch (PatternSyntaxException e) {
            final Component root = SwingUtilities.getRoot(m_panel);
            JOptionPane.showMessageDialog(root, "<html><body><p>Invalid regular expression:</p><p>" + pattern + "</p><p>" + e.getDescription() + " at position " + e.getIndex() + "</p>", "Invalid regular expression", JOptionPane.ERROR_MESSAGE);
        }
    }
    updateRow(row, regexAggregator);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) Component(java.awt.Component) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 12 with AggregationMethod

use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.

the class AggregationColumnPanel method createAggregationSection.

/**
 * Adds the aggregation method section to the given menu.
 * This section allows the user to set an aggregation method for
 * all selected columns.
 * @param menu the menu to append the aggregation section
 */
private void createAggregationSection(final JPopupMenu menu) {
    if (getSelectedRows().length <= 0) {
        final JMenuItem noneSelected = new JMenuItem("Select a column to change method");
        noneSelected.setEnabled(false);
        menu.add(noneSelected);
        return;
    }
    final List<Entry<String, List<AggregationMethod>>> methodList = getMethods4SelectedItems();
    if (methodList.size() == 1) {
        // we need no sub menu for a single group
        for (final AggregationMethod method : methodList.get(0).getValue()) {
            final JMenuItem methodItem = new JMenuItem(method.getLabel());
            methodItem.setToolTipText(method.getDescription());
            methodItem.addActionListener(new ActionListener() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void actionPerformed(final ActionEvent e) {
                    changeAggregationMethod(method.getId());
                }
            });
            menu.add(methodItem);
        }
    } else {
        for (final Entry<String, List<AggregationMethod>> entry : methodList) {
            final String type = entry.getKey();
            final List<AggregationMethod> methods = entry.getValue();
            final JMenu menuItem = new JMenu(type + " Methods");
            final JMenuItem subMenu = menu.add(menuItem);
            for (final AggregationMethod method : methods) {
                final JMenuItem methodItem = new JMenuItem(method.getLabel());
                methodItem.setToolTipText(method.getDescription());
                methodItem.addActionListener(new ActionListener() {

                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        changeAggregationMethod(method.getId());
                    }
                });
                subMenu.add(methodItem);
            }
        }
    }
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) Entry(java.util.Map.Entry) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 13 with AggregationMethod

use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.

the class DataTypeAggregationTableModel method setValue.

/**
 * {@inheritDoc}
 */
@Override
protected void setValue(final Object aValue, final int row, final int columnIdx) {
    if (aValue == null) {
        return;
    }
    if (aValue instanceof AggregationMethod) {
        assert columnIdx == 1;
        final AggregationMethod newMethod = (AggregationMethod) aValue;
        updateMethod(row, newMethod);
    }
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod)

Example 14 with AggregationMethod

use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.

the class SettingsModelAggregationMethod method createClone.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected SettingsModelAggregationMethod createClone() {
    AggregationOperator operator = (AggregationOperator) m_method;
    final AggregationMethod clone;
    if (!operator.hasOptionalSettings()) {
        clone = operator;
    } else {
        clone = operator.createInstance(operator.getGlobalSettings(), operator.getOperatorColumnSettings());
    }
    return new SettingsModelAggregationMethod(m_configName, m_inputPortIndex, m_valueDelimiter, m_maxUniqueValues, clone);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) AggregationOperator(org.knime.base.data.aggregation.AggregationOperator)

Example 15 with AggregationMethod

use of org.knime.base.data.aggregation.AggregationMethod in project knime-core by knime.

the class AggregationColumnTableModel method addColumn.

/**
 * @param specs the {@link DataColumnSpec}s of the columns to add
 * @see #add(List)
 */
@Deprecated
protected void addColumn(final DataColumnSpec... specs) {
    if (specs == null || specs.length < 1) {
        return;
    }
    final List<ColumnAggregator> aggregators = new ArrayList<>(specs.length);
    for (final DataColumnSpec spec : specs) {
        final AggregationMethod defaultMethod = AggregationMethods.getDefaultMethod(spec);
        aggregators.add(new ColumnAggregator(spec, defaultMethod));
    }
    add(aggregators);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) ArrayList(java.util.ArrayList)

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