Search in sources :

Example 21 with AggregationMethod

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

the class AggregationMethodComboBox method update.

/**
 * @param type the {@link DataType} used to initialize this combobox
 * @param compatibleMethods {@link List} of {@link AggregationMethod}s the user can choose from
 * @param selectedMethod the current selected method
 * @since 2.11
 */
public void update(final DataType type, final List<AggregationMethod> compatibleMethods, final AggregationMethod selectedMethod) {
    if (m_type == null || !m_type.equals(type)) {
        // recreate the combo box if the type has change
        removeAllItems();
        for (final AggregationMethod method : compatibleMethods) {
            addItem(method);
        }
        // save the current type for comparison
        m_type = type;
    }
    // select the previous selected item
    setSelectedItem(selectedMethod);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod)

Example 22 with AggregationMethod

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

the class DialogComponentAggregationMethod method replaceListItems.

/**
 * @param select the selected method
 * @param newItems the list of new {@link AggregationMethod}s to select from
 */
public void replaceListItems(final AggregationMethod select, final AggregationMethod... newItems) {
    if (newItems == null || newItems.length < 1) {
        throw new NullPointerException("The container with the new items can't be null or empty.");
    }
    final AggregationMethod sel;
    if (select == null) {
        sel = ((SettingsModelAggregationMethod) getModel()).getAggregationMethod();
    } else {
        sel = select;
    }
    m_aggregationMethod.removeItemListener(this);
    m_aggregationMethodModel.removeAllElements();
    AggregationMethod selOption = null;
    for (final AggregationMethod option : newItems) {
        if (option == null) {
            throw new NullPointerException("Options in the selection list can't be null");
        }
        if (option.getId().equals(sel.getId())) {
            // in order to not loose the method specific settings we have to use the given method instance
            selOption = option;
            m_aggregationMethodModel.addElement(option);
        } else {
            m_aggregationMethodModel.addElement(option);
        }
    }
    m_aggregationMethod.addItemListener(this);
    if (selOption == null) {
        m_aggregationMethod.setSelectedIndex(0);
    } else {
        m_aggregationMethod.setSelectedItem(selOption);
    }
    // update the size of the comboBox and force the repainting
    // of the whole panel
    m_aggregationMethod.setSize(m_aggregationMethod.getPreferredSize());
    getComponentPanel().validate();
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod)

Example 23 with AggregationMethod

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

the class OperatorSettingsButtonCellRenderer method openSettingsDialog.

private void openSettingsDialog() {
    final JTable table = m_rootPanel.getTable();
    final int row = table.convertRowIndexToModel(table.getEditingRow());
    fireEditingStopped();
    final AggregationMethod aggr = (AggregationMethod) m_rootPanel.getTableModel().getRow(row);
    if (!aggr.hasOptionalSettings()) {
        // the operator has no additional settings
        return;
    }
    // figure out the parent to be able to make the dialog modal
    Frame f = null;
    Container c = m_rootPanel.getComponentPanel().getParent();
    while (c != null) {
        if (c instanceof Frame) {
            f = (Frame) c;
            break;
        }
        c = c.getParent();
    }
    try {
        final AggregationParameterDialog dialog = new AggregationParameterDialog(f, aggr, m_rootPanel.getInputTableSpec());
        // center the dialog
        dialog.setLocationRelativeTo(c);
        dialog.pack();
        // show it
        dialog.setVisible(true);
    } catch (NotConfigurableException e) {
        // show the error message
        JOptionPane.showMessageDialog(m_rootPanel.getComponentPanel(), e.getMessage(), "Unable to open dialog", JOptionPane.ERROR_MESSAGE);
        return;
    }
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) NotConfigurableException(org.knime.core.node.NotConfigurableException) Frame(java.awt.Frame) Container(java.awt.Container) JTable(javax.swing.JTable)

Example 24 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 25 with AggregationMethod

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

the class DataTypeAggregator method loadAggregators.

/**
 * Creates a {@link List} with all {@link DataTypeAggregator}s that were
 * stored in the settings.
 *
 * @param settings the settings object to read from
 * @param key the unique settings key
 * @param spec {@link DataTableSpec} of the input table if available
 * @return {@link List} with the {@link DataTypeAggregator}s
 * @throws InvalidSettingsException if the settings are invalid
 */
public static List<DataTypeAggregator> loadAggregators(final NodeSettingsRO settings, final String key, final DataTableSpec spec) throws InvalidSettingsException {
    if (settings == null) {
        throw new IllegalArgumentException("settings must not be null");
    }
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("key must not be empty");
    }
    if (!settings.containsKey(key)) {
        return Collections.EMPTY_LIST;
    }
    final NodeSettingsRO root = settings.getNodeSettings(key);
    final Set<String> settingsKeys = root.keySet();
    final List<DataTypeAggregator> aggrList = new ArrayList<>(settingsKeys.size());
    for (String settingsKey : settingsKeys) {
        final NodeSettingsRO cfg = root.getNodeSettings(settingsKey);
        final DataType colType = cfg.getDataType(CNFG_DATA_TYPE);
        final boolean inclMissing = cfg.getBoolean(CNFG_INCL_MISSING_VALS);
        final AggregationMethod method = AggregationMethodDecorator.loadMethod(spec, cfg);
        aggrList.add(new DataTypeAggregator(colType, method, inclMissing));
    }
    return aggrList;
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) ArrayList(java.util.ArrayList) DataType(org.knime.core.data.DataType) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

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