Search in sources :

Example 1 with DBVColorOverride

use of org.jkiss.dbeaver.model.virtual.DBVColorOverride in project dbeaver by dbeaver.

the class ResultSetModel method updateColorMapping.

void updateColorMapping() {
    colorMapping.clear();
    DBSEntity entity = getSingleSource();
    if (entity == null) {
        return;
    }
    DBVEntity virtualEntity = DBVUtils.findVirtualEntity(entity, false);
    if (virtualEntity != null) {
        List<DBVColorOverride> coList = virtualEntity.getColorOverrides();
        if (!CommonUtils.isEmpty(coList)) {
            for (DBVColorOverride co : coList) {
                DBDAttributeBinding binding = getAttributeBinding(entity, co.getAttributeName());
                if (binding != null) {
                    List<AttributeColorSettings> cmList = colorMapping.get(binding);
                    if (cmList == null) {
                        cmList = new ArrayList<>();
                        colorMapping.put(binding, cmList);
                    }
                    cmList.add(new AttributeColorSettings(co));
                }
            }
        }
    }
    updateRowColors(curRows);
}
Also used : DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 2 with DBVColorOverride

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

the class ColorSettingsDialog method updateAttributeSelection.

private void updateAttributeSelection() {
    TableItem[] selection = attributeTable.getSelection();
    if (selection.length == 0) {
        attribute = null;
    } else {
        attribute = (DBDAttributeBinding) selection[0].getData();
    }
    colorsTable.removeAll();
    if (attribute == null) {
        // Nothing to load
        curOverride = null;
        colorOverrides = null;
    } else {
        colorOverrides = vEntity.getColorOverrides(attribute.getName());
        if (colorOverrides == null) {
            colorOverrides = new ArrayList<>();
        }
        for (DBVColorOverride co : colorOverrides) {
            TableItem tableItem = new TableItem(colorsTable, SWT.NONE);
            tableItem.setData(co);
            updateColorItem(tableItem);
        }
        if (!colorOverrides.isEmpty()) {
            curOverride = colorOverrides.get(0);
            colorsTable.setSelection(0);
        } else {
            curOverride = null;
        }
    }
    updateControlsState();
}
Also used : DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride)

Example 3 with DBVColorOverride

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

the class ColorSettingsDialog method createAttributeSelectorArea.

private void createAttributeSelectorArea(Composite composite) {
    Composite panel = UIUtils.createComposite(composite, 1);
    attributeTable = new Table(panel, SWT.FULL_SELECTION | SWT.BORDER);
    attributeTable.setHeaderVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    attributeTable.setLayoutData(gd);
    UIUtils.executeOnResize(attributeTable, () -> UIUtils.packColumns(attributeTable, true));
    UIUtils.createTableColumn(attributeTable, SWT.LEFT, "Name");
    UIUtils.createTableColumn(attributeTable, SWT.LEFT, "Colors");
    for (DBDAttributeBinding attr : resultSetViewer.getModel().getVisibleAttributes()) {
        TableItem attrItem = new TableItem(attributeTable, SWT.NONE);
        attrItem.setData(attr);
        attrItem.setText(0, attr.getName());
        attrItem.setImage(0, DBeaverIcons.getImage(DBValueFormatting.getObjectImage(attr, true)));
        if (this.attribute == attr) {
            attributeTable.setSelection(attrItem);
        }
    // updateColumnItem(attrItem);
    }
    attributeTable.addListener(SWT.PaintItem, event -> {
        if (event.index == 1) {
            int x = event.x + 4;
            DBDAttributeBinding attr = (DBDAttributeBinding) event.item.getData();
            List<DBVColorOverride> coList = vEntity.getColorOverrides(attr.getName());
            if (!coList.isEmpty()) {
                for (DBVColorOverride co : coList) {
                    List<String> coStrings = new ArrayList<>();
                    if (co.getAttributeValues() != null) {
                        for (Object value : co.getAttributeValues()) {
                            coStrings.add(CommonUtils.toString(value));
                        }
                    }
                    // String colorSettings = "   ";//String.join(", ", coStrings);
                    // Point textSize = event.gc.stringExtent(colorSettings);
                    int boxSize = attributeTable.getItemHeight() - 4;
                    Point textSize = new Point(boxSize, boxSize);
                    // getColorTableForeground(co);
                    Color fg = attributeTable.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
                    Color bg = getColorTableBackground(co);
                    if (fg != null)
                        event.gc.setForeground(fg);
                    if (bg != null)
                        event.gc.setBackground(bg);
                    event.gc.fillRectangle(x, event.y + 2, textSize.x, textSize.y);
                    event.gc.drawRectangle(x, event.y + 2, textSize.x - 1, textSize.y - 1);
                    // event.gc.drawText(colorSettings, x, event.y);
                    x += textSize.x + 4;
                }
            }
        }
    });
    attributeTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateAttributeSelection();
        }
    });
}
Also used : Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) Point(org.eclipse.swt.graphics.Point) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride)

Example 4 with DBVColorOverride

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

the class ColorSettingsDialog method updateColorItem.

private void updateColorItem(TableItem tableItem) {
    DBVColorOverride co = (DBVColorOverride) tableItem.getData();
    String text;
    Object[] values = co.getAttributeValues();
    if (ArrayUtils.isEmpty(values)) {
        text = co.getOperator().getStringValue() + " ?";
    } else if (values.length == 1) {
        text = co.getOperator().getStringValue() + " " + DBValueFormatting.getDefaultValueDisplayString(values[0], DBDDisplayFormat.UI);
    } else {
        if (co.isRange()) {
            text = "In " + Arrays.toString(values);
        } else {
            text = co.getOperator().getStringValue() + " " + Arrays.toString(values);
        }
    }
    tableItem.setText(0, text);
    tableItem.setForeground(getColorTableForeground((DBVColorOverride) tableItem.getData()));
    tableItem.setBackground(getColorTableBackground((DBVColorOverride) tableItem.getData()));
}
Also used : DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride)

Example 5 with DBVColorOverride

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

the class ResultSetModel method updateColorMapping.

void updateColorMapping() {
    colorMapping.clear();
    DBSEntity entity = getSingleSource();
    if (entity == null) {
        return;
    }
    DBVEntity virtualEntity = DBVUtils.findVirtualEntity(entity, false);
    if (virtualEntity != null) {
        List<DBVColorOverride> coList = virtualEntity.getColorOverrides();
        if (!CommonUtils.isEmpty(coList)) {
            for (DBVColorOverride co : coList) {
                DBDAttributeBinding binding = getAttributeBinding(entity, co.getAttributeName());
                if (binding != null) {
                    List<AttributeColorSettings> cmList = colorMapping.get(binding);
                    if (cmList == null) {
                        cmList = new ArrayList<>();
                        colorMapping.put(binding, cmList);
                    }
                    cmList.add(new AttributeColorSettings(co));
                }
            }
        }
    }
    updateRowColors(curRows);
}
Also used : DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Aggregations

DBVColorOverride (org.jkiss.dbeaver.model.virtual.DBVColorOverride)7 DBVEntity (org.jkiss.dbeaver.model.virtual.DBVEntity)4 Color (org.eclipse.swt.graphics.Color)3 ArrayList (java.util.ArrayList)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Point (org.eclipse.swt.graphics.Point)2 RGB (org.eclipse.swt.graphics.RGB)2 GridData (org.eclipse.swt.layout.GridData)2 NotNull (org.jkiss.code.NotNull)2 Nullable (org.jkiss.code.Nullable)2 DBException (org.jkiss.dbeaver.DBException)2 Log (org.jkiss.dbeaver.Log)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 UIUtils (org.jkiss.dbeaver.ui.UIUtils)2 ArrayUtils (org.jkiss.utils.ArrayUtils)2 CommonUtils (org.jkiss.utils.CommonUtils)2 java.util (java.util)1 Arrays (java.util.Arrays)1 List (java.util.List)1