use of org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor in project dbeaver by serge-rider.
the class AggregateColumnsPanel method saveSettings.
private void saveSettings() {
panelSettings.put(PARAM_GROUP_BY_COLUMNS, groupByColumns);
IDialogSettings functionsSection = UIUtils.getSettingsSection(panelSettings, "functions");
for (AggregateFunctionDescriptor func : FunctionsRegistry.getInstance().getFunctions()) {
IDialogSettings funcSection = UIUtils.getSettingsSection(functionsSection, func.getId());
boolean enabled = enabledFunctions.contains(func);
funcSection.put("enabled", enabled);
if (enabled) {
funcSection.put("index", enabledFunctions.indexOf(func));
} else {
funcSection.put("index", -1);
}
}
}
use of org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor 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);
}
}
}
use of org.jkiss.dbeaver.registry.functions.AggregateFunctionDescriptor in project dbeaver by serge-rider.
the class AggregateColumnsPanel method loadSettings.
private void loadSettings() {
groupByColumns = panelSettings.getBoolean(PARAM_GROUP_BY_COLUMNS);
IDialogSettings functionsSection = panelSettings.getSection("functions");
if (functionsSection != null) {
final Map<AggregateFunctionDescriptor, Integer> funcIndexes = new HashMap<>();
for (IDialogSettings funcSection : functionsSection.getSections()) {
String funcId = funcSection.getName();
if (!funcSection.getBoolean("enabled")) {
continue;
}
AggregateFunctionDescriptor func = FunctionsRegistry.getInstance().getFunction(funcId);
if (func == null) {
log.debug("Function '" + funcId + "' not found");
} else {
funcIndexes.put(func, funcSection.getInt("index"));
enabledFunctions.add(func);
}
}
Collections.sort(enabledFunctions, new Comparator<AggregateFunctionDescriptor>() {
@Override
public int compare(AggregateFunctionDescriptor o1, AggregateFunctionDescriptor o2) {
return funcIndexes.get(o1) - funcIndexes.get(o2);
}
});
}
if (enabledFunctions.isEmpty()) {
loadDefaultFunctions();
}
}
Aggregations