Search in sources :

Example 6 with DBPImage

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

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

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

the class GenericConnectionPage method getImage.

@Override
public Image getImage() {
    DBPDriver driver = getSite().getDriver();
    DBPImage iconBig = driver.getIconBig();
    if (iconBig != null) {
        try {
            Image image = DBeaverIcons.getImage(iconBig);
            if (image.getImageData().width >= 64) {
                return image;
            }
        } catch (Exception e) {
            log.error(e);
        }
    }
    return super.getImage();
}
Also used : DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) Image(org.eclipse.swt.graphics.Image) DBPImage(org.jkiss.dbeaver.model.DBPImage) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 8 with DBPImage

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

the class DataTransferPagePipes method createInputsTable.

private void createInputsTable(Composite composite) {
    Composite panel = UIUtils.createComposite(composite, 1);
    // UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
    inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    inputsTable.getTable().setLinesVisible(true);
    inputsTable.getTable().setHeaderVisible(true);
    inputsTable.setContentProvider(new ListContentProvider());
    UIUtils.createTableContextMenu(inputsTable.getTable(), null);
    DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
    CellLabelProvider labelProvider = new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DBSObject element = (DBSObject) cell.getElement();
            if (cell.getColumnIndex() == 0) {
                DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
                DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
                cell.setImage(DBeaverIcons.getImage(icon));
                cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
            } else if (element.getDescription() != null) {
                cell.setText(element.getDescription());
            }
        }
    };
    {
        TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
        columnName.setLabelProvider(labelProvider);
        columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
        TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
        columnDesc.setLabelProvider(labelProvider);
        columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 9 with DBPImage

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

the class GridCellRenderer method isOverLink.

boolean isOverLink(GridColumn column, int row, int x, int y) {
    IGridContentProvider contentProvider = grid.getContentProvider();
    Object colElement = column.getElement();
    Object rowElement = grid.getRowElement(row);
    int state = contentProvider.getCellState(colElement, rowElement, null);
    boolean isToggle = (state & IGridContentProvider.STATE_TOGGLE) != 0;
    if (isToggle) {
        if (contentProvider.isElementReadOnly(colElement)) {
            return false;
        }
    }
    if (isLinkState(state) || isToggle) {
        int columnAlign = contentProvider.getColumnAlign(colElement);
        Point origin = grid.getOrigin(column, row);
        Rectangle imageBounds;
        if (isToggle) {
            String cellText = grid.getCellText(colElement, rowElement);
            Point textSize = grid.sizingGC.textExtent(cellText);
            imageBounds = new Rectangle(0, 0, textSize.x, textSize.y);
        } else {
            DBPImage cellImage = grid.getCellImage(colElement, rowElement);
            Image image;
            if (cellImage == null) {
                image = ((state & IGridContentProvider.STATE_LINK) != 0) ? LINK_IMAGE : LINK2_IMAGE;
            } else {
                image = DBeaverIcons.getImage(cellImage);
            }
            imageBounds = image.getBounds();
        }
        int verMargin = (grid.getItemHeight() - imageBounds.height) / 2;
        switch(columnAlign) {
            case IGridContentProvider.ALIGN_LEFT:
                if (x >= origin.x + LEFT_MARGIN && x <= origin.x + LEFT_MARGIN + imageBounds.width && y >= origin.y + verMargin && y <= origin.y + verMargin + imageBounds.height) {
                    return true;
                }
                break;
            case IGridContentProvider.ALIGN_RIGHT:
                int width = column.getWidth();
                if (x >= origin.x + width - (LEFT_MARGIN + imageBounds.width) && x <= origin.x + width - RIGHT_MARGIN && y >= origin.y + verMargin && y <= origin.y + verMargin + imageBounds.height) {
                    return true;
                }
                break;
            case IGridContentProvider.ALIGN_CENTER:
                int leftIndent = (column.getWidth() - imageBounds.width - RIGHT_MARGIN - LEFT_MARGIN) / 2;
                if (x >= origin.x + LEFT_MARGIN + leftIndent && x <= origin.x + LEFT_MARGIN + leftIndent + imageBounds.width && y >= origin.y + verMargin && y <= origin.y + verMargin + imageBounds.height) {
                    return true;
                }
                break;
        }
    }
    return false;
}
Also used : DBPImage(org.jkiss.dbeaver.model.DBPImage) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 10 with DBPImage

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

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;
    {
        DBPImage cellImage = grid.getCellImage(col, row);
        if (cellImage != null) {
            image = DBeaverIcons.getImage(cellImage);
            imageBounds = image.getBounds();
        } else {
            image = null;
        }
        if (image == null && isLinkState(state)) {
            image = ((state & IGridContentProvider.STATE_LINK) != 0) ? LINK_IMAGE : LINK2_IMAGE;
            imageBounds = LINK_IMAGE_BOUNDS;
        }
    }
    int columnAlign = grid.getContentProvider().getColumnAlign(col);
    if (image != null && columnAlign != IGridContentProvider.ALIGN_RIGHT) {
        int y = bounds.y + (bounds.height - imageBounds.height) / 2;
        if (columnAlign == IGridContentProvider.ALIGN_CENTER) {
            x += (bounds.width - imageBounds.width - RIGHT_MARGIN - LEFT_MARGIN) / 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 = UITextUtils.getShortString(grid.fontMetrics, text, width);
        // Replace linefeeds with space
        text = CommonUtils.getSingleLineString(text);
        gc.setFont(grid.normalFont);
        switch(columnAlign) {
            // Center
            case IGridContentProvider.ALIGN_CENTER:
                {
                    Point textSize = gc.textExtent(text);
                    gc.drawString(text, bounds.x + (bounds.width - textSize.x) / 2, bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
                    break;
                }
            case IGridContentProvider.ALIGN_RIGHT:
                {
                    // Right (numbers, datetimes)
                    Point textSize = gc.textExtent(text);
                    boolean useClipping = textSize.x > bounds.width;
                    int imageMargin = 0;
                    if (image != null) {
                        // Reduce bounds by link image size
                        imageMargin = imageBounds.width + INSIDE_MARGIN;
                        if (useClipping) {
                            gc.setClipping(bounds.x, bounds.y, bounds.width - imageMargin, bounds.height);
                        }
                    } else {
                        if (useClipping) {
                            gc.setClipping(bounds);
                        }
                    }
                    gc.drawString(text, bounds.x + bounds.width - (textSize.x + RIGHT_MARGIN + imageMargin), bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
                    if (useClipping) {
                        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 (focus) {
        gc.setForeground(colorLineFocused);
        gc.drawRectangle(bounds.x + 1, bounds.y, bounds.width - 2, bounds.height - 1);
        if (grid.isFocusControl()) {
            gc.drawRectangle(bounds.x + 2, bounds.y + 1, bounds.width - 4, bounds.height - 3);
        }
    }
}
Also used : DBPImage(org.jkiss.dbeaver.model.DBPImage) 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