Search in sources :

Example 1 with IAggregateFunction

use of org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction in project dbeaver by dbeaver.

the class AggregateColumnsPanel method aggregateValues.

private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
    List<AggregateFunctionDescriptor> functions = enabledFunctions;
    Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
    for (AggregateFunctionDescriptor funcDesc : functions) {
        TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
        funcItem.setData(funcDesc);
        funcItem.setText(0, funcDesc.getLabel());
        DBPImage icon = funcDesc.getIcon();
        if (icon != null) {
            funcItem.setImage(0, DBeaverIcons.getImage(icon));
        }
        try {
            IAggregateFunction func = funcDesc.createFunction();
            funcMap.put(func, funcItem);
        } catch (DBException e) {
            log.error(e);
        }
    }
    IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
    int[] funcCount = new int[funcs.length];
    for (Object element : values) {
        for (int i = 0; i < funcs.length; i++) {
            if (funcs[i].accumulate(element)) {
                funcCount[i]++;
            }
        }
    }
    for (int i = 0; i < funcs.length; i++) {
        if (funcCount[i] <= 0) {
            continue;
        }
        IAggregateFunction func = funcs[i];
        Object result = func.getResult(funcCount[i]);
        if (result != null) {
            TreeItem treeItem = funcMap.get(func);
            String strValue;
            if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
                strValue = DOUBLE_FORMAT.format(result);
            } else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
                strValue = INTEGER_FORMAT.format(result);
            } else {
                strValue = result.toString();
            }
            treeItem.setText(1, strValue);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal) DBPImage(org.jkiss.dbeaver.model.DBPImage) AggregateFunctionDescriptor(org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor) IAggregateFunction(org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction)

Example 2 with IAggregateFunction

use of org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction in project dbeaver by serge-rider.

the class AggregateColumnsPanel method aggregateValues.

private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
    List<AggregateFunctionDescriptor> functions = enabledFunctions;
    Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
    for (AggregateFunctionDescriptor funcDesc : functions) {
        TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
        funcItem.setData(funcDesc);
        funcItem.setText(0, funcDesc.getLabel());
        DBPImage icon = funcDesc.getIcon();
        if (icon != null) {
            funcItem.setImage(0, DBeaverIcons.getImage(icon));
        }
        try {
            IAggregateFunction func = funcDesc.createFunction();
            funcMap.put(func, funcItem);
        } catch (DBException e) {
            log.error(e);
        }
    }
    IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
    int[] funcCount = new int[funcs.length];
    for (Object element : values) {
        for (int i = 0; i < funcs.length; i++) {
            if (funcs[i].accumulate(element, aggregateAsStrings)) {
                funcCount[i]++;
            }
        }
    }
    for (int i = 0; i < funcs.length; i++) {
        if (funcCount[i] <= 0) {
            continue;
        }
        IAggregateFunction func = funcs[i];
        Object result = func.getResult(funcCount[i]);
        if (result != null) {
            TreeItem treeItem = funcMap.get(func);
            String strValue;
            if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
                strValue = DOUBLE_FORMAT.format(result);
            } else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
                strValue = INTEGER_FORMAT.format(result);
            } else {
                strValue = result.toString();
            }
            if (strValue != null) {
                treeItem.setText(1, strValue);
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal) DBPImage(org.jkiss.dbeaver.model.DBPImage) AggregateFunctionDescriptor(org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor) IAggregateFunction(org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction)

Example 3 with IAggregateFunction

use of org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction in project dbeaver by serge-rider.

the class AggregateColumnsPanel method aggregateValues.

private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
    List<AggregateFunctionDescriptor> functions = enabledFunctions;
    Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
    for (AggregateFunctionDescriptor funcDesc : functions) {
        TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
        funcItem.setData(funcDesc);
        funcItem.setText(0, funcDesc.getLabel());
        funcItem.setImage(0, DBeaverIcons.getImage(funcDesc.getIcon()));
        try {
            IAggregateFunction func = funcDesc.createFunction();
            funcMap.put(func, funcItem);
        } catch (DBException e) {
            log.error(e);
        }
    }
    IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
    int[] funcCount = new int[funcs.length];
    for (Object element : values) {
        for (int i = 0; i < funcs.length; i++) {
            if (funcs[i].accumulate(element)) {
                funcCount[i]++;
            }
        }
    }
    for (int i = 0; i < funcs.length; i++) {
        if (funcCount[i] <= 0) {
            continue;
        }
        IAggregateFunction func = funcs[i];
        Object result = func.getResult(funcCount[i]);
        if (result != null) {
            TreeItem treeItem = funcMap.get(func);
            String strValue;
            if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
                strValue = DOUBLE_FORMAT.format(result);
            } else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
                strValue = INTEGER_FORMAT.format(result);
            } else {
                strValue = result.toString();
            }
            treeItem.setText(1, strValue);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal) AggregateFunctionDescriptor(org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor) IAggregateFunction(org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction)

Aggregations

BigDecimal (java.math.BigDecimal)3 Point (org.eclipse.swt.graphics.Point)3 DBException (org.jkiss.dbeaver.DBException)3 IAggregateFunction (org.jkiss.dbeaver.model.data.aggregate.IAggregateFunction)3 AggregateFunctionDescriptor (org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor)3 DBPImage (org.jkiss.dbeaver.model.DBPImage)2