Search in sources :

Example 11 with ColumnAggregator

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

the class AggregationColumnTableModel method removeColumns.

/**
 * @param colNames the names of the columns to remove
 */
@Deprecated
protected void removeColumns(final Collection<String> colNames) {
    if (colNames == null || colNames.isEmpty()) {
        return;
    }
    final Set<String> colNameSet = new HashSet<>(colNames);
    final Collection<ColumnAggregator> colAggr2Remove = new LinkedList<>();
    for (final ColumnAggregator colAggr : getRows()) {
        if (colNameSet.contains(colAggr.getOriginalColName())) {
            colAggr2Remove.add(colAggr);
        }
    }
    remove(colAggr2Remove);
}
Also used : ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 12 with ColumnAggregator

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

the class AggregationColumnTableModel method updateMethod.

/**
 * @param row the row to update
 * @param method the {@link AggregationMethod} to use
 */
private void updateMethod(final int row, final AggregationMethod method) {
    final ColumnAggregator old = getRow(row);
    if (old.getMethodTemplate().equals(method)) {
        // check if the method has changed
        return;
    }
    // create a new operator each time it is updated to guarantee that
    // each column has its own operator instance
    AggregationMethod methodClone = AggregationMethods.getMethod4Id(method.getId());
    updateRow(row, new ColumnAggregator(old.getOriginalColSpec(), methodClone, old.inclMissingCells()));
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator)

Example 13 with ColumnAggregator

use of org.knime.base.data.aggregation.ColumnAggregator 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)

Example 14 with ColumnAggregator

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

the class AggregationColumnPanel method adaptTableColumnModel.

/**
 * {@inheritDoc}
 */
@Override
protected void adaptTableColumnModel(final TableColumnModel columnModel) {
    columnModel.getColumn(0).setCellRenderer(new AggregationFunctionRowTableCellRenderer<>(new ValueRenderer<ColumnAggregator>() {

        @Override
        public void renderComponent(final DefaultTableCellRenderer c, final ColumnAggregator row) {
            final DataColumnSpec spec = row.getOriginalColSpec();
            c.setText(spec.getName());
            c.setIcon(spec.getType().getIcon());
        }
    }, true, "Double click to remove column. Right mouse click for context menu."));
    columnModel.getColumn(1).setCellEditor(new ColumnAggregatorTableCellEditor());
    columnModel.getColumn(1).setCellRenderer(new AggregationFunctionAndRowTableCellRenderer());
    columnModel.getColumn(0).setPreferredWidth(170);
    columnModel.getColumn(1).setPreferredWidth(150);
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) AggregationFunctionAndRowTableCellRenderer(org.knime.base.data.aggregation.dialogutil.AggregationFunctionAndRowTableCellRenderer) ValueRenderer(org.knime.base.data.aggregation.dialogutil.AggregationFunctionRowTableCellRenderer.ValueRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 15 with ColumnAggregator

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

the class AggregationColumnPanel method getMethods4SelectedItems.

/**
 * @return a label list of all supported methods for the currently
 * selected rows
 */
protected List<Entry<String, List<AggregationMethod>>> getMethods4SelectedItems() {
    final int[] selectedColumns = getSelectedRows();
    final Set<DataType> types = new HashSet<>(selectedColumns.length);
    for (final int row : selectedColumns) {
        final ColumnAggregator aggregator = getTableModel().getRow(row);
        types.add(aggregator.getOriginalDataType());
    }
    final DataType superType = CollectionCellFactory.getElementType(types.toArray(new DataType[0]));
    final List<Entry<String, List<AggregationMethod>>> list = AggregationMethods.getCompatibleMethodGroupList(superType);
    return list;
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) Entry(java.util.Map.Entry) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet)

Aggregations

ColumnAggregator (org.knime.base.data.aggregation.ColumnAggregator)33 DataColumnSpec (org.knime.core.data.DataColumnSpec)14 HashSet (java.util.HashSet)9 LinkedList (java.util.LinkedList)9 ArrayList (java.util.ArrayList)8 AggregationMethod (org.knime.base.data.aggregation.AggregationMethod)8 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)5 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)5 DataCell (org.knime.core.data.DataCell)4 DataRow (org.knime.core.data.DataRow)4 DataTableSpec (org.knime.core.data.DataTableSpec)4 RowKey (org.knime.core.data.RowKey)4 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 GlobalSettings (org.knime.base.data.aggregation.GlobalSettings)3 PatternAggregator (org.knime.base.data.aggregation.dialogutil.pattern.PatternAggregator)3 DataTypeAggregator (org.knime.base.data.aggregation.dialogutil.type.DataTypeAggregator)3 GroupByTable (org.knime.base.node.preproc.groupby.GroupByTable)3 DataType (org.knime.core.data.DataType)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)3