Search in sources :

Example 6 with DBAggregationFunction

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

the class DBPatternAggregationFunctionPanel method createRow.

/**
 * {@inheritDoc}
 */
@Override
protected DBPatternAggregationFunctionRow createRow(final String pattern) {
    final AggregationFunctionProvider<DBAggregationFunction> provider = getTableModel().getAggregationFunctionProvider();
    final DBAggregationFunction defaultFunction = provider.getDefaultFunction(StringCell.TYPE);
    return new DBPatternAggregationFunctionRow(".*", true, defaultFunction);
}
Also used : DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction)

Example 7 with DBAggregationFunction

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

the class DBPatternAggregationFunctionPanel 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 = getTableModel().getAggregationFunctionProvider().getFunctions(true);
    // 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) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) JMenuItem(javax.swing.JMenuItem)

Example 8 with DBAggregationFunction

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

the class DBDataTypeAggregationFunctionPanel method createRow.

/**
 * {@inheritDoc}
 */
@Override
protected DBDataTypeAggregationFunctionRow createRow(final DataType type) {
    AggregationFunctionProvider<DBAggregationFunction> provider = getTableModel().getAggregationFunctionProvider();
    final DBAggregationFunction defaultFunction;
    if (provider != null) {
        defaultFunction = provider.getDefaultFunction(type);
    } else {
        defaultFunction = new CountDBAggregationFunction.Factory().createInstance();
    }
    return new DBDataTypeAggregationFunctionRow(type, 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 9 with DBAggregationFunction

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

the class DBDataTypeAggregationFunctionPanel 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 row 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 10 with DBAggregationFunction

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

the class AbstractDBAggregationFunctionRow method loadFunction.

/**
 * @param tableSpec optional input {@link DataTableSpec}
 * @param functionProvider the {@link DBAggregationFunctionProvider}
 * @param cfg {@link NodeSettingsRO} to read from
 * @return the {@link DBAggregationFunction}
 * @throws InvalidSettingsException if the settings of the function are invalid
 */
public static DBAggregationFunction loadFunction(final DataTableSpec tableSpec, final DBAggregationFunctionProvider functionProvider, final NodeSettingsRO cfg) throws InvalidSettingsException {
    final String functionId = cfg.getString(CNFG_AGGR_COL_SECTION);
    DBAggregationFunction function = functionProvider.getFunction(functionId);
    if (function instanceof InvalidAggregationFunction) {
        final String errMsg = "Exception while loading database aggregation functions. " + ((InvalidAggregationFunction) function).getErrorMessage();
        LOGGER.warn(errMsg);
    } else {
        if (function.hasOptionalSettings()) {
            try {
                final NodeSettingsRO subSettings = cfg.getNodeSettings("functionSettings");
                if (tableSpec != null) {
                    // this method is called from the dialog
                    function.loadSettingsFrom(subSettings, tableSpec);
                } else {
                    // this method is called from the node model where we do not
                    // have the DataTableSpec
                    function.loadValidatedSettings(subSettings);
                }
            } catch (Exception e) {
                final String errMsg = "Exception while loading settings for aggreation function '" + function.getId() + "', reason: " + e.getMessage();
                function = new InvalidDBAggregationFunction(functionId, errMsg, null);
                LOGGER.error(errMsg);
            }
        }
    }
    return function;
}
Also used : InvalidAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidAggregationFunction) InvalidDBAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidDBAggregationFunction) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidDBAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidDBAggregationFunction)

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