提交 80d7e7b9 编写于 作者: S Serge Rider

#6379 Data viewer: color settings dialog

上级 e47d4700
......@@ -110,10 +110,7 @@ public class PrefPageProjectNetworkProfiles extends AbstractPrefPage implements
{
ToolBar toolbar = new ToolBar(profilesGroup, SWT.HORIZONTAL);
ToolItem createItem = new ToolItem(toolbar, SWT.NONE);
createItem.setToolTipText("Create new profile");
createItem.setImage(DBeaverIcons.getImage(UIIcon.ROW_ADD));
createItem.addSelectionListener(new SelectionAdapter() {
UIUtils.createToolItem(toolbar, "Create new profile", UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String profileName = "";
......@@ -145,10 +142,7 @@ public class PrefPageProjectNetworkProfiles extends AbstractPrefPage implements
}
});
ToolItem deleteItem = new ToolItem(toolbar, SWT.NONE);
deleteItem.setToolTipText("Delete profile");
deleteItem.setImage(DBeaverIcons.getImage(UIIcon.ROW_DELETE));
deleteItem.addSelectionListener(new SelectionAdapter() {
UIUtils.createToolItem(toolbar, "Delete profile", UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (selectedProfile != null) {
......
......@@ -27,6 +27,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.DBUtils;
......@@ -124,7 +125,7 @@ public class DashboardManagerDialog extends BaseDialog {
DashboardDescriptor dashboardDescriptor = (DashboardDescriptor) element;
DBPImage icon;
if (dashboardDescriptor.isCustom()) {
icon = UIIcon.ACTION_OBJECT;
icon = DBIcon.TYPE_OBJECT;
} else {
icon = dashboardDescriptor.getDefaultViewType().getIcon();
}
......
......@@ -18,12 +18,13 @@ package org.jkiss.dbeaver.ui.controls.resultset;
import org.eclipse.jface.dialogs.ControlEnableState;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
......@@ -36,11 +37,11 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBValueFormatting;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueDefaultGenerator;
import org.jkiss.dbeaver.model.exec.DBCLogicalOperator;
import org.jkiss.dbeaver.model.virtual.DBVColorOverride;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.data.IValueEditor;
......@@ -57,15 +58,17 @@ import java.util.List;
class ColorSettingsDialog extends BaseDialog {
private static final Log log = Log.getLog(ColorSettingsDialog.class);
private static final String DIALOG_ID = "DBeaver.ColorSettingsDialog";//$NON-NLS-1$
private static final String DIALOG_ID = "DBeaver.ColorSettingsDialog2";//$NON-NLS-1$
private static RGB DEFAULT_RGB;
@NotNull
private final ResultSetViewer resultSetViewer;
@NotNull
private final DBDAttributeBinding attribute;
@Nullable
private final ResultSetRow row;
private DBDAttributeBinding attribute;
@Nullable
private ResultSetRow row;
private Table colorsTable;
private Button rangeCheck;
......@@ -82,10 +85,12 @@ class ColorSettingsDialog extends BaseDialog {
private Button singleColumnCheck;
private DBVColorOverride curOverride;
private ToolItem btnDelete;
private Table attributeTable;
public ColorSettingsDialog(
@NotNull ResultSetViewer resultSetViewer,
@NotNull final DBDAttributeBinding attr,
@Nullable final DBDAttributeBinding attr,
@Nullable final ResultSetRow row) {
super(resultSetViewer.getControl().getShell(), "Customize colors for [" + attr.getName() + "]", UIIcon.PALETTE);
this.resultSetViewer = resultSetViewer;
......@@ -95,83 +100,137 @@ class ColorSettingsDialog extends BaseDialog {
DEFAULT_RGB = resultSetViewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB();
}
/*
@Override
protected IDialogSettings getDialogBoundsSettings() {
return UIUtils.getDialogSettings(DIALOG_ID);
}
*/
@Override
protected Composite createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Composite mainGroup = new Composite(composite, SWT.NONE);
mainGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
mainGroup.setLayout(new GridLayout(2, false));
Composite composite = super.createDialogArea(parent);
GridData gd;
/*
gd.horizontalSpan = 2;
Composite titlePanel = UIUtils.createComposite(mainGroup, 2);
titlePanel.setLayoutData(gd);
UIUtils.createLabelText(titlePanel, "Attribute", attribute.getName(), SWT.BORDER | SWT.READ_ONLY);
*/
SashForm divider = new SashForm(composite, SWT.HORIZONTAL);
divider.setLayoutData(new GridData(GridData.FILL_BOTH));
createAttributeSelectorArea(divider);
createAttributeSettingsArea(divider);
{
Composite colorsGroup = new Composite(mainGroup, SWT.NONE);
colorsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
colorsGroup.setLayout(new GridLayout(1, false));
updateAttributeSelection();
return parent;
}
UIUtils.createControlLabel(colorsGroup, "Cell conditions");
private void createAttributeSelectorArea(Composite composite) {
Composite panel = UIUtils.createComposite(composite, 1);
colorsTable = new Table(colorsGroup, SWT.BORDER | SWT.FULL_SELECTION);
//colorsTable.setHeaderVisible(true);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
colorsTable.setLayoutData(gd);
UIUtils.createTableColumn(colorsTable, SWT.LEFT, "Operator");
UIUtils.createTableColumn(colorsTable, SWT.RIGHT, "Value(s)");
UIUtils.executeOnResize(colorsTable, () -> UIUtils.packColumns(colorsTable, true));
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.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
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
} else {
DBVEntity vEntity = DBVUtils.getVirtualEntity(attribute, true);
//DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(attribute, true);
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);
updateTreeItem(tableItem);
updateColorItem(tableItem);
}
if (!colorOverrides.isEmpty()) {
curOverride = colorOverrides.get(0);
colorsTable.setSelection(0);
}
}
//ToolBar toolbar = new ToolBar(colorsGroup, SWT.FLAT | SWT.HORIZONTAL);
Composite buttonsPanel = UIUtils.createComposite(colorsGroup, 2);
Button btnAdd = createButton(buttonsPanel, 1000, "Add", false);
btnAdd.addSelectionListener(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);
updateTreeItem(tableItem);
updateSettingsValues();
updateControlsState();
updateControlsState();
}
private void createAttributeSettingsArea(Composite composite) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(attribute, true);
Composite mainGroup = UIUtils.createComposite(composite, 1);
mainGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
{
Composite colorsGroup = new Composite(mainGroup, SWT.NONE);
colorsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH));
colorsGroup.setLayout(new GridLayout(2, false));
//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((TableItem) event.item);
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);
}
});
Button btnDelete = createButton(buttonsPanel, 1001, "Delete", false);
btnDelete.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (curOverride != null) {
colorsTable.getItem(colorsTable.getSelectionIndex()).dispose();
vEntity.removeColorOverride(curOverride);
curOverride = null;
updateSettingsValues();
updateControlsState();
}
/*
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
......@@ -183,13 +242,43 @@ class ColorSettingsDialog extends BaseDialog {
updateControlsState();
}
});
{
ToolBar buttonsPanel = new ToolBar(colorsGroup, SWT.FLAT | SWT.VERTICAL);
buttonsPanel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
ToolItem btnAdd = 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_BOTH));
settingsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL ));
settingsGroup.setLayout(new GridLayout(3, false));
gd = new GridData();
GridData gd = new GridData();
gd.horizontalSpan = 3;
UIUtils.createControlLabel(settingsGroup, "Settings").setLayoutData(gd);
......@@ -197,10 +286,10 @@ class ColorSettingsDialog extends BaseDialog {
rangeCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateControlsState();
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);
......@@ -244,10 +333,6 @@ class ColorSettingsDialog extends BaseDialog {
"To use gradient set minimum and maximum\ncolumn values and two\ncolors for gradient range. ",
GridData.FILL_HORIZONTAL, 3);
}
updateControlsState();
return parent;
}
private void updateSettingsValues() {
......@@ -301,7 +386,9 @@ class ColorSettingsDialog extends BaseDialog {
private void updateControlsState() {
if (curOverride == null) {
settingsEnableState = ControlEnableState.disable(settingsGroup);
if (settingsEnableState == null) {
settingsEnableState = ControlEnableState.disable(settingsGroup);
}
} else if (settingsEnableState != null) {
settingsEnableState.restore();
settingsEnableState = null;
......@@ -313,6 +400,10 @@ class ColorSettingsDialog extends BaseDialog {
}
bgColorSelector2.setEnabled(isRange);
fgColorSelector2.setEnabled(isRange);
colorsTable.setEnabled(attribute != null);
updateSettingsValues();
}
private IValueEditor createValueEditor(Composite panel, int index) {
......@@ -380,26 +471,57 @@ class ColorSettingsDialog extends BaseDialog {
}
private void updateCurrentTreeItem() {
updateTreeItem(colorsTable.getItem(colorsTable.getSelectionIndex()));
int itemIndex = colorsTable.getSelectionIndex();
if (itemIndex >= 0) {
updateColorItem(colorsTable.getItem(itemIndex));
}
//colorsTable.getColumn(0).setWidth(colorsTable.getSize().x);
}
private void updateTreeItem(TableItem tableItem) {
private void updateColorItem(TableItem tableItem) {
DBVColorOverride co = (DBVColorOverride) tableItem.getData();
tableItem.setText(0, co.getOperator().getStringValue());
String text;
Object[] values = co.getAttributeValues();
if (ArrayUtils.isEmpty(values)) {
tableItem.setText(1, "");
text = co.getOperator().getStringValue() + " ?";
} else if (values.length == 1) {
tableItem.setText(1, DBValueFormatting.getDefaultValueDisplayString(values[0], DBDDisplayFormat.UI));
text = co.getOperator().getStringValue() + " " + DBValueFormatting.getDefaultValueDisplayString(values[0], DBDDisplayFormat.UI);
} else {
tableItem.setText(1, Arrays.toString(values));
}
if (!CommonUtils.isEmpty(co.getColorBackground())) {
tableItem.setBackground(UIUtils.getSharedColor(co.getColorBackground()));
if (co.isRange()) {
text = "In " + Arrays.toString(values);
} else {
text = co.getOperator().getStringValue() + " " + Arrays.toString(values);
}
}
tableItem.setText(0, text);
tableItem.setForeground(getColorTableForeground(tableItem));
tableItem.setBackground(getColorTableBackground(tableItem));
}
private Color getColorTableForeground(TableItem tableItem) {
DBVColorOverride co = (DBVColorOverride) tableItem.getData();
if (!CommonUtils.isEmpty(co.getColorForeground())) {
tableItem.setForeground(UIUtils.getSharedColor(co.getColorForeground()));
return UIUtils.getSharedColor(co.getColorForeground());
}
return null;
}
private Color getColorTableBackground(TableItem tableItem) {
DBVColorOverride co = (DBVColorOverride) tableItem.getData();
if (!co.isRange()) {
if (!CommonUtils.isEmpty(co.getColorBackground())) {
return UIUtils.getSharedColor(co.getColorBackground());
}
} else {
String bg1 = co.getColorBackground();
String bg2 = co.getColorBackground2();
if (!CommonUtils.isEmpty(bg1) && !CommonUtils.isEmpty(bg2)) {
Color bg1Color = UIUtils.getSharedColor(bg1);
Color bg2Color = UIUtils.getSharedColor(bg2);
return UIUtils.getSharedColor(ResultSetUtils.makeGradientValue(bg1Color.getRGB(), bg2Color.getRGB(), 1, 100, 50));
}
}
return null;
}
@Override
......
......@@ -210,9 +210,8 @@ public class UIIcon {
public static final DBIcon ACTION_USER_ADD = new DBIcon("action_user_add", "actions/user_add.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon ACTION_USER_DELETE = new DBIcon("action_user_delete", "actions/user_delete.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon ACTION_OBJECT = new DBIcon("action_object", "actions/object.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon ACTION_OBJECT_ADD = new DBIcon("action_object_add", "actions/object_add.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon ACTION_OBJECT_DELETE = new DBIcon("action_object_delete", "actions/object_delete.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon ACTION_OBJECT_ADD = new DBIcon("action_object_add", "misc/object_add.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon ACTION_OBJECT_DELETE = new DBIcon("action_object_delete", "misc/object_remove.png"); //$NON-NLS-1$ //$NON-NLS-2$
public static final DBIcon DRIVER_MANAGER = new DBIcon("driver_manager.png"); //$NON-NLS-1$
......
......@@ -727,6 +727,19 @@ public class UIUtils {
return button;
}
public static ToolItem createToolItem(ToolBar parent, String text, DBPImage icon, SelectionListener selectionListener)
{
ToolItem button = new ToolItem(parent, SWT.PUSH);
button.setToolTipText(text);
if (icon != null) {
button.setImage(DBeaverIcons.getImage(icon));
}
if (selectionListener != null) {
button.addSelectionListener(selectionListener);
}
return button;
}
public static void updateContributionItems(IContributionManager manager) {
for (IContributionItem item : manager.getItems()) {
item.update();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册