Search in sources :

Example 11 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.

the class GridColumn method computeCellWidth.

private int computeCellWidth(Object col, Object row) {
    int x = 0;
    x += leftMargin;
    String cellText = grid.getCellText(col, row);
    int state = grid.getContentProvider().getCellState(col, row, cellText);
    Rectangle imageBounds;
    if (GridCellRenderer.isLinkState(state)) {
        imageBounds = GridCellRenderer.LINK_IMAGE_BOUNDS;
    } else {
        DBPImage image = grid.getContentProvider().getCellImage(col, row);
        imageBounds = image == null ? null : DBeaverIcons.getImage(image).getBounds();
    }
    if (imageBounds != null) {
        x += imageBounds.width + insideMargin;
    }
    x += grid.sizingGC.textExtent(cellText).x + rightMargin;
    return x;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 12 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.

the class DataSourceProviderDescriptor method loadTreeIcon.

private void loadTreeIcon(DBXTreeNode node, IConfigurationElement config) {
    String defaultIcon = config.getAttribute(RegistryConstants.ATTR_ICON);
    IConfigurationElement[] iconElements = config.getChildren(RegistryConstants.ATTR_ICON);
    if (!ArrayUtils.isEmpty(iconElements)) {
        for (IConfigurationElement iconElement : iconElements) {
            String icon = iconElement.getAttribute(RegistryConstants.ATTR_ICON);
            String expr = iconElement.getAttribute(RegistryConstants.ATTR_IF);
            boolean isDefault = CommonUtils.getBoolean(iconElement.getAttribute(RegistryConstants.ATTR_DEFAULT));
            if (isDefault && CommonUtils.isEmpty(expr)) {
                defaultIcon = icon;
            } else {
                DBPImage iconImage = iconToImage(icon);
                if (iconImage != null) {
                    node.addIcon(new DBXTreeIcon(expr, iconImage));
                }
            }
        }
    }
    if (defaultIcon != null) {
        DBPImage defaultImage = iconToImage(defaultIcon);
        if (defaultImage != null) {
            node.setDefaultIcon(defaultImage);
        }
    }
}
Also used : IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 13 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage 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 14 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.

the class RecentTasksMenuContributor method fillContributionItems.

@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
    DBPProject project = NavigatorUtils.getSelectedProject();
    if (project == null) {
        return;
    }
    DBTTask[] tasks = project.getTaskManager().getAllTasks();
    Arrays.sort(tasks, (o1, o2) -> {
        DBTTaskRun lr1 = o1.getLastRun();
        DBTTaskRun lr2 = o1.getLastRun();
        if (lr1 == lr2)
            return o1.getCreateTime().compareTo(o2.getCreateTime());
        else if (lr1 == null)
            return -1;
        else if (lr2 == null)
            return 1;
        else
            return lr1.getStartTime().compareTo(lr2.getStartTime());
    });
    for (int i = 0; i < tasks.length && i <= MAX_ITEMS; i++) {
        DBTTask task = tasks[i];
        DBPImage taskIcon = task.getType().getIcon();
        if (taskIcon == null)
            taskIcon = DBIcon.TREE_TASK;
        menuItems.add(ActionUtils.makeActionContribution(new Action(task.getName(), DBeaverIcons.getImageDescriptor(taskIcon)) {

            @Override
            public void run() {
                TaskHandlerRun.runTask(task);
            }
        }, false));
    }
}
Also used : DBTTaskRun(org.jkiss.dbeaver.model.task.DBTTaskRun) Action(org.eclipse.jface.action.Action) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 15 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.

the class TaskHandlerRun method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    String taskId = CommonUtils.toString(parameters.get("task"));
    if (!CommonUtils.isEmpty(taskId)) {
        DBTTask task = NavigatorUtils.getSelectedProject().getTaskManager().getTaskById(taskId);
        if (task != null) {
            DBPImage taskIcon = task.getType().getIcon();
            if (taskIcon == null)
                taskIcon = DBIcon.TREE_TASK;
            element.setIcon(DBeaverIcons.getImageDescriptor(taskIcon));
            element.setText(task.getName());
        }
    }
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Aggregations

DBPImage (org.jkiss.dbeaver.model.DBPImage)21 GridData (org.eclipse.swt.layout.GridData)5 Composite (org.eclipse.swt.widgets.Composite)5 DBException (org.jkiss.dbeaver.DBException)5 Point (org.eclipse.swt.graphics.Point)4 List (java.util.List)3 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)3 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)3 SWT (org.eclipse.swt.SWT)3 Shell (org.eclipse.swt.widgets.Shell)3 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)3 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)3 CommonUtils (org.jkiss.utils.CommonUtils)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 BigDecimal (java.math.BigDecimal)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 Action (org.eclipse.jface.action.Action)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 Control (org.eclipse.swt.widgets.Control)2