Search in sources :

Example 1 with DBPImage

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

the class PrefPageProjectSettings method performDefaults.

@Override
protected void performDefaults() {
    resourceTable.removeAll();
    for (ResourceHandlerDescriptor descriptor : DBeaverCore.getInstance().getProjectRegistry().getResourceHandlers()) {
        if (!descriptor.isManagable()) {
            continue;
        }
        TableItem item = new TableItem(resourceTable, SWT.NONE);
        item.setData(descriptor);
        final DBPImage icon = descriptor.getIcon();
        if (icon != null) {
            item.setImage(DBeaverIcons.getImage(icon));
        }
        item.setText(0, descriptor.getName());
        if (descriptor.getDefaultRoot() != null) {
            item.setText(1, descriptor.getDefaultRoot());
        }
    }
    UIUtils.packColumns(resourceTable, true);
    super.performDefaults();
}
Also used : ResourceHandlerDescriptor(org.jkiss.dbeaver.registry.ResourceHandlerDescriptor) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 2 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.

the class PrefPageProjectSettings method performDefaults.

@Override
protected void performDefaults() {
    resourceTable.removeAll();
    for (ResourceHandlerDescriptor descriptor : DBeaverCore.getInstance().getProjectRegistry().getResourceHandlerDescriptors()) {
        if (!descriptor.isManagable()) {
            continue;
        }
        TableItem item = new TableItem(resourceTable, SWT.NONE);
        item.setData(descriptor);
        final DBPImage icon = descriptor.getIcon();
        if (icon != null) {
            item.setImage(DBeaverIcons.getImage(icon));
        }
        item.setText(0, descriptor.getName());
        String defaultRoot = project == null ? null : descriptor.getDefaultRoot(project);
        if (defaultRoot != null) {
            item.setText(1, defaultRoot);
        }
    }
    UIUtils.packColumns(resourceTable, true);
    super.performDefaults();
}
Also used : ResourceHandlerDescriptor(org.jkiss.dbeaver.registry.ResourceHandlerDescriptor) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 3 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.

the class GridCellRenderer method paint.

public void paint(GC gc, Rectangle bounds, boolean selected, boolean focus, Object col, Object row) {
    boolean drawBackground = true;
    // if (grid.isEnabled()) {
    Color back = grid.getCellBackground(col, row, selected);
    if (back != null) {
        gc.setBackground(back);
    } else {
        drawBackground = false;
    }
    /*} else {
            grid.setDefaultBackground(gc);
        }*/
    gc.setForeground(grid.getCellForeground(col, row, selected));
    if (drawBackground) {
        gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
    }
    String text = grid.getCellText(col, row);
    final int state = grid.getContentProvider().getCellState(col, row, text);
    int x = LEFT_MARGIN;
    Image image;
    Rectangle imageBounds = null;
    if (isLinkState(state)) {
        image = ((state & IGridContentProvider.STATE_LINK) != 0) ? LINK_IMAGE : LINK2_IMAGE;
        imageBounds = LINK_IMAGE_BOUNDS;
    } else {
        DBPImage cellImage = grid.getCellImage(col, row);
        if (cellImage != null) {
            image = DBeaverIcons.getImage(cellImage);
            imageBounds = image.getBounds();
        } else {
            image = null;
        }
    }
    int columnAlign = grid.getContentProvider().getColumnAlign(col);
    if (image != null && columnAlign != IGridContentProvider.ALIGN_RIGHT) {
        int y = bounds.y + (bounds.height - imageBounds.height) / 2;
        gc.drawImage(image, bounds.x + x, y);
        x += imageBounds.width + INSIDE_MARGIN;
    }
    int width = bounds.width - x - RIGHT_MARGIN;
    // Get cell text
    if (text != null && !text.isEmpty()) {
        // Get shortern version of string
        text = TextUtils.getShortString(grid.fontMetrics, text, width);
        // Replace linefeeds with space
        text = TextUtils.getSingleLineString(text);
        gc.setFont(grid.normalFont);
        switch(columnAlign) {
            // Center
            case IGridContentProvider.ALIGN_CENTER:
                break;
            case IGridContentProvider.ALIGN_RIGHT:
                // Right (numbers, datetimes)
                int imageMargin = 0;
                if (image != null) {
                    // Reduce bounds by link image size
                    imageMargin = imageBounds.width + INSIDE_MARGIN;
                    gc.setClipping(bounds.x, bounds.y, bounds.width - imageMargin, bounds.height);
                } else {
                    gc.setClipping(bounds);
                }
                Point textSize = gc.textExtent(text);
                gc.drawString(text, bounds.x + bounds.width - (textSize.x + RIGHT_MARGIN + imageMargin), bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
                gc.setClipping((Rectangle) null);
                break;
            default:
                gc.drawString(text, bounds.x + x, bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
                break;
        }
    }
    if (image != null && columnAlign == IGridContentProvider.ALIGN_RIGHT) {
        int y = bounds.y + (bounds.height - imageBounds.height) / 2;
        gc.drawImage(image, bounds.x + bounds.width - imageBounds.width - RIGHT_MARGIN, y);
    }
    if (grid.isLinesVisible()) {
        if (selected) {
            gc.setForeground(grid.getLineSelectedColor());
        } else {
            gc.setForeground(grid.getLineColor());
        }
        gc.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width, bounds.y + bounds.height);
        gc.drawLine(bounds.x + bounds.width - 1, bounds.y, bounds.x + bounds.width - 1, bounds.y + bounds.height);
    }
    if (focus) {
        gc.setForeground(colorLineFocused);
        gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height);
        if (grid.isFocusControl()) {
            gc.drawRectangle(bounds.x + 1, bounds.y + 1, bounds.width - 3, bounds.height - 2);
        }
    }
}
Also used : DBPImage(org.jkiss.dbeaver.model.DBPImage) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 4 with DBPImage

use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.

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 5 with DBPImage

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

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