Search in sources :

Example 16 with DBAggregationFunction

use of org.knime.core.node.port.database.aggregation.DBAggregationFunction in project knime-core by knime.

the class DBPatternAggregationFunctionRow method saveFunctions.

/**
 * @param settings {@link NodeSettingsWO}
 * @param key the config key
 * @param rows the {@link DBPatternAggregationFunctionRow}s to save
 */
public static void saveFunctions(final NodeSettingsWO settings, final String key, final List<DBPatternAggregationFunctionRow> rows) {
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("key must not be empty");
    }
    if (settings == null) {
        throw new NullPointerException("settings must not be null");
    }
    if (rows == null) {
        return;
    }
    final NodeSettingsWO root = settings.addNodeSettings(key);
    for (int i = 0, length = rows.size(); i < length; i++) {
        final NodeSettingsWO cfg = root.addNodeSettings("f_" + i);
        final DBPatternAggregationFunctionRow row = rows.get(i);
        final String inputPattern = row.getInputPattern();
        final boolean isRegex = row.isRegex();
        cfg.addString(CNFG_INPUT_PATTERN, inputPattern);
        cfg.addBoolean(CNFG_IS_REGEX, isRegex);
        DBAggregationFunction function = row.getFunction();
        AbstractDBAggregationFunctionRow.saveFunction(cfg, function);
    }
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction)

Example 17 with DBAggregationFunction

use of org.knime.core.node.port.database.aggregation.DBAggregationFunction in project knime-core by knime.

the class DBColumnAggregationFunctionPanel method getMethods4SelectedItems.

/**
 * @return a label list of all supported methods for the currently
 * selected rows
 */
protected List<DBAggregationFunction> getMethods4SelectedItems() {
    final int[] selectedColumns = getSelectedRows();
    final Set<DataType> types = new HashSet<>(selectedColumns.length);
    for (final int row : selectedColumns) {
        final DBColumnAggregationFunctionRow aggregator = getTableModel().getRow(row);
        types.add(aggregator.getColumnSpec().getType());
    }
    final DataType superType = CollectionCellFactory.getElementType(types.toArray(new DataType[0]));
    final List<DBAggregationFunction> list = getTableModel().getAggregationFunctionProvider().getCompatibleFunctions(superType, true);
    return list;
}
Also used : CountDBAggregationFunction(org.knime.core.node.port.database.aggregation.function.CountDBAggregationFunction) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet)

Example 18 with DBAggregationFunction

use of org.knime.core.node.port.database.aggregation.DBAggregationFunction in project knime-core by knime.

the class DBColumnAggregationFunctionPanel method createRow.

/**
 * {@inheritDoc}
 */
@Override
protected DBColumnAggregationFunctionRow createRow(final DataColumnSpec colSpec) {
    AggregationFunctionProvider<DBAggregationFunction> provider = getTableModel().getAggregationFunctionProvider();
    final DBAggregationFunction defaultFunction;
    if (provider != null) {
        defaultFunction = provider.getDefaultFunction(colSpec.getType());
    } else {
        defaultFunction = new CountDBAggregationFunction.Factory().createInstance();
    }
    return new DBColumnAggregationFunctionRow(colSpec, defaultFunction);
}
Also used : CountDBAggregationFunction(org.knime.core.node.port.database.aggregation.function.CountDBAggregationFunction) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) CollectionCellFactory(org.knime.core.data.collection.CollectionCellFactory)

Example 19 with DBAggregationFunction

use of org.knime.core.node.port.database.aggregation.DBAggregationFunction in project knime-core by knime.

the class DBColumnAggregationFunctionPanel 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<DBAggregationFunction> methodList = getMethods4SelectedItems();
    // we need no sub menu for a single group
    for (final DBAggregationFunction method : methodList) {
        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);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) CountDBAggregationFunction(org.knime.core.node.port.database.aggregation.function.CountDBAggregationFunction) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) JMenuItem(javax.swing.JMenuItem)

Example 20 with DBAggregationFunction

use of org.knime.core.node.port.database.aggregation.DBAggregationFunction in project knime-core by knime.

the class DBPatternAggregationFunctionTableModel method updateRow.

private void updateRow(final int row, final String pattern, final boolean isRegex, final String functionId, final boolean isValid) {
    // create a new operator each time it is updated to guarantee that
    // each column has its own operator instance
    final DBAggregationFunction methodClone = getAggregationFunctionProvider().getFunction(functionId);
    final DBPatternAggregationFunctionRow regexAggregator = new DBPatternAggregationFunctionRow(pattern, isRegex, methodClone);
    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);
        }
    }
    regexAggregator.setValid(isValid);
    updateRow(row, regexAggregator);
}
Also used : DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) Component(java.awt.Component) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

DBAggregationFunction (org.knime.core.node.port.database.aggregation.DBAggregationFunction)25 ArrayList (java.util.ArrayList)8 DataType (org.knime.core.data.DataType)7 DatabaseUtility (org.knime.core.node.port.database.DatabaseUtility)6 CountDBAggregationFunction (org.knime.core.node.port.database.aggregation.function.CountDBAggregationFunction)6 DataColumnSpec (org.knime.core.data.DataColumnSpec)5 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)5 HashSet (java.util.HashSet)4 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)4 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)4 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JMenuItem (javax.swing.JMenuItem)3 DBAggregationFunctionProvider (org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider)3 DBColumnAggregationFunctionRow (org.knime.base.node.io.database.groupby.dialog.column.DBColumnAggregationFunctionRow)3 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)3 DataTableSpec (org.knime.core.data.DataTableSpec)3 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)3 SQLException (java.sql.SQLException)2