Search in sources :

Example 6 with DBVColorOverride

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

the class ColorSettingsDialog method createAttributeSettingsArea.

private void createAttributeSettingsArea(Composite composite) {
    Composite mainGroup = UIUtils.createComposite(composite, 1);
    mainGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
    {
        Composite colorsGroup = UIUtils.createComposite(mainGroup, 2);
        colorsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
        // UIUtils.createControlLabel(colorsGroup, "Cell conditions");
        colorsTable = new Table(colorsGroup, SWT.BORDER | SWT.FULL_SELECTION);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 300;
        gd.heightHint = 100;
        colorsTable.setLayoutData(gd);
        colorsTable.addListener(SWT.EraseItem, event -> {
            if ((event.detail & SWT.SELECTED) != 0) {
                // event.detail &= ~SWT.SELECTED;
                Color bgColor = getColorTableBackground((DBVColorOverride) event.item.getData());
                if (bgColor != null) {
                    event.gc.setBackground(bgColor);
                } else {
                    event.gc.setBackground(colorsTable.getBackground());
                }
                event.gc.fillRectangle(event.x, event.y, event.width, event.height);
                event.gc.drawRectangle(event.x, event.y, event.width - 1, event.height - 1);
            }
        });
        /*
            colorsTable.addListener(SWT.PaintItem, event -> {
                if ((event.detail & SWT.SELECTED) == 0) {
                    return;
                }
                event.gc.drawText(((TableItem) event.item).getText(), event.x, event.y);
            });
*/
        // UIUtils.createTableColumn(colorsTable, SWT.LEFT, "Operator");
        UIUtils.createTableColumn(colorsTable, SWT.RIGHT, "Value(s)");
        UIUtils.executeOnResize(colorsTable, () -> UIUtils.packColumns(colorsTable, true));
        colorsTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = colorsTable.getSelectionIndex();
                curOverride = selectionIndex < 0 ? null : (DBVColorOverride) colorsTable.getItem(selectionIndex).getData();
                btnDelete.setEnabled(selectionIndex >= 0);
                updateControlsState();
            }
        });
        {
            ToolBar buttonsPanel = new ToolBar(colorsGroup, SWT.FLAT | SWT.VERTICAL);
            buttonsPanel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
            UIUtils.createToolItem(buttonsPanel, "Add", UIIcon.ROW_ADD, new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    curOverride = new DBVColorOverride(attribute.getName(), DBCLogicalOperator.EQUALS, null, null, null);
                    vEntity.addColorOverride(curOverride);
                    TableItem tableItem = new TableItem(colorsTable, SWT.NONE);
                    tableItem.setData(curOverride);
                    colorsTable.setSelection(tableItem);
                    updateColorItem(tableItem);
                    updateControlsState();
                }
            });
            btnDelete = UIUtils.createToolItem(buttonsPanel, "Delete", UIIcon.ROW_DELETE, new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    if (curOverride != null) {
                        colorsTable.getItem(colorsTable.getSelectionIndex()).dispose();
                        vEntity.removeColorOverride(curOverride);
                        curOverride = null;
                        updateControlsState();
                    }
                }
            });
            btnDelete.setEnabled(false);
        }
    }
    {
        settingsGroup = new Composite(mainGroup, SWT.NONE);
        settingsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
        settingsGroup.setLayout(new GridLayout(3, false));
        GridData gd = new GridData();
        gd.horizontalSpan = 3;
        UIUtils.createControlLabel(settingsGroup, "Settings").setLayoutData(gd);
        rangeCheck = UIUtils.createCheckbox(settingsGroup, "Range / gradient", "Use value range / color gradient", false, 3);
        rangeCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (curOverride != null) {
                    curOverride.setRange(rangeCheck.getSelection());
                }
                updateControlsState();
            }
        });
        singleColumnCheck = UIUtils.createCheckbox(settingsGroup, "Apply colors to this column only", "Apply colors to this column only, otherwise color full row", false, 3);
        singleColumnCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (curOverride != null) {
                    curOverride.setSingleColumn(singleColumnCheck.getSelection());
                }
            }
        });
        UIUtils.createControlLabel(settingsGroup, "Value(s)");
        editorPlaceholder1 = new Composite(settingsGroup, SWT.NONE);
        editorPlaceholder1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorPlaceholder1.setLayout(new FillLayout());
        editorPlaceholder2 = new Composite(settingsGroup, SWT.NONE);
        editorPlaceholder2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorPlaceholder2.setLayout(new FillLayout());
        valueEditor1 = createValueEditor(editorPlaceholder1, 0);
        valueEditor2 = createValueEditor(editorPlaceholder2, 1);
        UIUtils.createControlLabel(settingsGroup, "Background");
        bgColorSelector1 = new ColorSelector(settingsGroup);
        bgColorSelector1.addListener(event -> {
            curOverride.setColorBackground(StringConverter.asString(bgColorSelector1.getColorValue()));
            updateCurrentTreeItem();
        });
        bgColorSelector2 = new ColorSelector(settingsGroup);
        bgColorSelector2.addListener(event -> {
            curOverride.setColorBackground2(StringConverter.asString(bgColorSelector2.getColorValue()));
            updateCurrentTreeItem();
        });
        UIUtils.createControlLabel(settingsGroup, "Foreground");
        fgColorSelector1 = new ColorSelector(settingsGroup);
        fgColorSelector1.addListener(event -> {
            curOverride.setColorForeground(StringConverter.asString(fgColorSelector1.getColorValue()));
            updateCurrentTreeItem();
        });
        fgColorSelector2 = new ColorSelector(settingsGroup);
        fgColorSelector2.addListener(event -> {
            curOverride.setColorForeground2(StringConverter.asString(fgColorSelector2.getColorValue()));
            updateCurrentTreeItem();
        });
        UIUtils.createInfoLabel(settingsGroup, "To use gradient set minimum and maximum\ncolumn values and two\ncolors for gradient range. ", GridData.FILL_HORIZONTAL, 3);
    }
}
Also used : Arrays(java.util.Arrays) SashForm(org.eclipse.swt.custom.SashForm) IValueManager(org.jkiss.dbeaver.ui.data.IValueManager) ControlEnableState(org.eclipse.jface.dialogs.ControlEnableState) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) Nullable(org.jkiss.code.Nullable) Point(org.eclipse.swt.graphics.Point) NotNull(org.jkiss.code.NotNull) ColorSelector(org.eclipse.jface.preference.ColorSelector) ArrayList(java.util.ArrayList) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBDDisplayFormat(org.jkiss.dbeaver.model.data.DBDDisplayFormat) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) Log(org.jkiss.dbeaver.Log) RGB(org.eclipse.swt.graphics.RGB) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) ResultSetUtils(org.jkiss.dbeaver.ui.controls.resultset.ResultSetUtils) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) DBCLogicalOperator(org.jkiss.dbeaver.model.exec.DBCLogicalOperator) DBValueFormatting(org.jkiss.dbeaver.model.DBValueFormatting) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ArrayUtils(org.jkiss.utils.ArrayUtils) List(java.util.List) Color(org.eclipse.swt.graphics.Color) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) StringConverter(org.eclipse.jface.resource.StringConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ValueManagerRegistry(org.jkiss.dbeaver.ui.data.registry.ValueManagerRegistry) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride)

Example 7 with DBVColorOverride

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

the class ResultSetModel method updateColorMapping.

public void updateColorMapping(boolean reset) {
    colorMapping.clear();
    DBSDataContainer dataContainer = getDataContainer();
    if (dataContainer == null) {
        return;
    }
    DBVEntity virtualEntity = DBVUtils.getVirtualEntity(dataContainer, false);
    if (virtualEntity == null) {
        return;
    }
    {
        List<DBVColorOverride> coList = virtualEntity.getColorOverrides();
        if (!CommonUtils.isEmpty(coList)) {
            for (DBVColorOverride co : coList) {
                DBDAttributeBinding binding = DBUtils.findObject(attributes, co.getAttributeName());
                if (binding != null) {
                    List<AttributeColorSettings> cmList = colorMapping.computeIfAbsent(binding, k -> new ArrayList<>());
                    cmList.add(new AttributeColorSettings(co));
                } else {
                    log.debug("Attribute '" + co.getAttributeName() + "' not found in bindings. Skip colors.");
                }
            }
        }
    }
    if (reset) {
        updateRowColors(true, curRows);
    }
}
Also used : CommonUtils(org.jkiss.utils.CommonUtils) DBPDataKind(org.jkiss.dbeaver.model.DBPDataKind) java.util(java.util) org.jkiss.dbeaver.model.struct(org.jkiss.dbeaver.model.struct) DBUtils(org.jkiss.dbeaver.model.DBUtils) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) org.jkiss.dbeaver.model.data(org.jkiss.dbeaver.model.data) Nullable(org.jkiss.code.Nullable) ArrayUtils(org.jkiss.utils.ArrayUtils) NotNull(org.jkiss.code.NotNull) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBVUtils(org.jkiss.dbeaver.model.virtual.DBVUtils) DataSourceJob(org.jkiss.dbeaver.runtime.jobs.DataSourceJob) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBCTrace(org.jkiss.dbeaver.model.exec.trace.DBCTrace) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity) Color(org.eclipse.swt.graphics.Color) DBException(org.jkiss.dbeaver.DBException) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) RGB(org.eclipse.swt.graphics.RGB) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) 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