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);
}
}
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);
}
}
Aggregations