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);
}
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations