提交 17de1b7c 编写于 作者: J jurgen

Remove SWT colors from model (replace with RGB strings)

Former-commit-id: 5d7a9203
上级 9138711b
......@@ -17,7 +17,6 @@
*/
package org.jkiss.dbeaver.model;
import org.eclipse.swt.graphics.Color;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
import org.jkiss.dbeaver.model.runtime.DBRShellCommand;
......@@ -42,7 +41,7 @@ public class DBPConnectionInfo implements DBPObject
private final Map<DBPConnectionEventType, DBRShellCommand> events;
private final List<DBWHandlerConfiguration> handlers;
private DBPConnectionType connectionType;
private Color connectionColor;
private String connectionColor;
public DBPConnectionInfo()
{
......@@ -232,23 +231,16 @@ public class DBPConnectionInfo implements DBPObject
this.connectionType = connectionType;
}
public Color getColor()
{
Color color = connectionColor != null ? connectionColor : connectionType.getColor();
if (color.getBlue() == 255 && color.getRed() == 255 && color.getGreen() == 255) {
// For white color return just null to avoid explicit color set.
// It is important for dark themes
return null;
}
return color;
}
public Color getConnectionColor()
/**
* Color in RGB format
* @return RGB color or null
*/
public String getConnectionColor()
{
return connectionColor;
}
public void setConnectionColor(Color color)
public void setConnectionColor(String color)
{
this.connectionColor = color;
}
......
package org.jkiss.dbeaver.model;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.jkiss.dbeaver.core.DBeaverUI;
/**
* Connection type
*/
public class DBPConnectionType implements IAdaptable {
public static final DBPConnectionType DEV = new DBPConnectionType("dev", "Development", new RGB(0xFF, 0xFF, 0xFF), "Regular development database", true, false, true);
public static final DBPConnectionType TEST = new DBPConnectionType("test", "Test", new RGB(0xC4, 0xFF, 0xB5), "Test (QA) database", true, false, true);
public static final DBPConnectionType PROD = new DBPConnectionType("prod", "Production", new RGB(0xF7, 0x9F, 0x81), "Production database", false, true, true);
public static final DBPConnectionType DEV = new DBPConnectionType("dev", "Development", "255,255,255", "Regular development database", true, false, true);
public static final DBPConnectionType TEST = new DBPConnectionType("test", "Test", "196,255,181", "Test (QA) database", true, false, true);
public static final DBPConnectionType PROD = new DBPConnectionType("prod", "Production", "247,159,129", "Production database", false, true, true);
public static final DBPConnectionType[] SYSTEM_TYPES = { DEV, TEST, PROD };
public static final DBPConnectionType DEFAULT_TYPE = DEV;
private String id;
private String name;
private RGB color;
private String color;
private String description;
private boolean autocommit;
private boolean confirmExecute;
......@@ -30,16 +27,16 @@ public class DBPConnectionType implements IAdaptable {
this(source.id, source.name, source.color, source.description, source.autocommit, source.confirmExecute, source.predefined);
}
public DBPConnectionType(String id, String name, RGB rgb, String description, boolean autocommit, boolean confirmExecute)
public DBPConnectionType(String id, String name, String color, String description, boolean autocommit, boolean confirmExecute)
{
this(id, name, rgb, description, autocommit, confirmExecute, false);
this(id, name, color, description, autocommit, confirmExecute, false);
}
private DBPConnectionType(String id, String name, RGB rgb, String description, boolean autocommit, boolean confirmExecute, boolean predefined)
private DBPConnectionType(String id, String name, String color, String description, boolean autocommit, boolean confirmExecute, boolean predefined)
{
this.id = id;
this.name = name;
this.color = rgb;
this.color = color;
this.description = description;
this.autocommit = autocommit;
this.confirmExecute = confirmExecute;
......@@ -66,14 +63,14 @@ public class DBPConnectionType implements IAdaptable {
this.name = name;
}
public Color getColor()
public String getColor()
{
return DBeaverUI.getSharedTextColors().getColor(color);
return color;
}
public void setColor(Color color)
public void setColor(String color)
{
this.color = color.getRGB();
this.color = color;
}
public String getDescription()
......
......@@ -17,13 +17,12 @@
*/
package org.jkiss.dbeaver.registry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.DBPConnectionType;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDriver;
......@@ -309,7 +308,7 @@ public class DataSourceProviderRegistry
xml.startElement(RegistryConstants.TAG_TYPE);
xml.addAttribute(RegistryConstants.ATTR_ID, connectionType.getId());
xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(connectionType.getName()));
xml.addAttribute(RegistryConstants.ATTR_COLOR, StringConverter.asString(connectionType.getColor().getRGB()));
xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionType.getColor());
xml.addAttribute(RegistryConstants.ATTR_DESCRIPTION, CommonUtils.toString(connectionType.getDescription()));
xml.addAttribute(RegistryConstants.ATTR_AUTOCOMMIT, connectionType.isAutocommit());
xml.addAttribute(RegistryConstants.ATTR_CONFIRM_EXECUTE, connectionType.isConfirmExecute());
......@@ -373,7 +372,7 @@ public class DataSourceProviderRegistry
DBPConnectionType connectionType = new DBPConnectionType(
atts.getValue(RegistryConstants.ATTR_ID),
atts.getValue(RegistryConstants.ATTR_NAME),
StringConverter.asRGB(atts.getValue(RegistryConstants.ATTR_COLOR)),
atts.getValue(RegistryConstants.ATTR_COLOR),
atts.getValue(RegistryConstants.ATTR_DESCRIPTION),
CommonUtils.getBoolean(atts.getValue(RegistryConstants.ATTR_AUTOCOMMIT)),
CommonUtils.getBoolean(atts.getValue(RegistryConstants.ATTR_CONFIRM_EXECUTE)));
......
......@@ -21,10 +21,8 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.resource.StringConverter;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
......@@ -419,7 +417,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
xml.addAttribute(RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
}
if (connectionInfo.getConnectionColor() != null) {
xml.addAttribute(RegistryConstants.ATTR_COLOR, StringConverter.asString(connectionInfo.getConnectionColor().getRGB()));
xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
}
if (connectionInfo.getProperties() != null) {
......@@ -654,9 +652,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
);
String colorValue = atts.getValue(RegistryConstants.ATTR_COLOR);
if (!CommonUtils.isEmpty(colorValue)) {
curDataSource.getConnectionInfo().setConnectionColor(
DBeaverUI.getSharedTextColors().getColor(
StringConverter.asRGB(colorValue)));
curDataSource.getConnectionInfo().setConnectionColor(colorValue);
}
curDataSource.refreshConnectionInfo();
}
......
......@@ -24,6 +24,7 @@ import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.window.IShellProvider;
......@@ -54,10 +55,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverConstants;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.*;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertySource;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.RunnableWithResult;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
......@@ -1350,4 +1348,29 @@ public class UIUtils {
}
}
}
public static Color getConnectionColor(DBPConnectionInfo connectionInfo) {
String rgbString = connectionInfo.getConnectionColor();
if (CommonUtils.isEmpty(rgbString)) {
rgbString = connectionInfo.getConnectionType().getColor();
}
if (CommonUtils.isEmpty(rgbString)) {
return null;
}
Color connectionColor = DBeaverUI.getSharedTextColors().getColor(StringConverter.asRGB(rgbString));
if (connectionColor.getBlue() == 255 && connectionColor.getRed() == 255 && connectionColor.getGreen() == 255) {
// For white color return just null to avoid explicit color set.
// It is important for dark themes
return null;
}
return connectionColor;
}
public static Color getConnectionTypeColor(DBPConnectionType connectionType) {
String rgbString = connectionType.getColor();
if (CommonUtils.isEmpty(rgbString)) {
return null;
}
return DBeaverUI.getSharedTextColors().getColor(StringConverter.asRGB(rgbString));
}
}
......@@ -441,7 +441,7 @@ class ConnectionPageGeneral extends ActiveWizardPage<ConnectionWizard> {
{
connectionTypeCombo.removeAll();
for (DBPConnectionType ct : DataSourceProviderRegistry.getInstance().getConnectionTypes()) {
connectionTypeCombo.add(null, ct.getName(), ct.getColor(), ct);
connectionTypeCombo.add(null, ct.getName(), UIUtils.getConnectionTypeColor(ct), ct);
}
}
......
......@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.IDataSourceContainerProvider;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
import org.jkiss.dbeaver.ui.UIUtils;
/**
* DB editor utils
......@@ -49,12 +50,12 @@ public class DatabaseEditorUtils {
if (editor instanceof IDataSourceContainerProvider) {
DBSDataSourceContainer container = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
if (container != null) {
bgColor = container.getConnectionInfo().getColor();
bgColor = UIUtils.getConnectionColor(container.getConnectionInfo());
}
} else if (editor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
if (context != null) {
bgColor = context.getDataSource().getContainer().getConnectionInfo().getColor();
bgColor = UIUtils.getConnectionColor(context.getDataSource().getContainer().getConnectionInfo());
}
}
if (bgColor == null) {
......
......@@ -357,12 +357,12 @@ public class DataSourceManagementToolbar implements DBPRegistryListener, DBPEven
connectionCombo.add(
dsNode == null ? DBIcon.TREE_DATABASE.getImage() : dsNode.getNodeIconDefault(),
ds.getName(),
ds.getConnectionInfo().getColor(),
UIUtils.getConnectionColor(ds.getConnectionInfo()),
ds);
} else {
TableItem item = connectionCombo.getItem(i + 1);
item.setText(ds.getName());
item.setBackground(ds.getConnectionInfo().getColor());
item.setBackground(UIUtils.getConnectionColor(ds.getConnectionInfo()));
}
if (dataSourceContainer == ds) {
selectionIndex = i + 1;
......@@ -527,7 +527,7 @@ public class DataSourceManagementToolbar implements DBPRegistryListener, DBPEven
databaseCombo.add(
dbNode.getNodeIconDefault(),
database.getName(),
dataSource.getContainer().getConnectionInfo().getColor(),
UIUtils.getConnectionColor(dataSource.getContainer().getConnectionInfo()),
database);
}
}
......
......@@ -20,6 +20,7 @@ package org.jkiss.dbeaver.ui.preferences;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Color;
......@@ -110,7 +111,7 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
DBPConnectionType newType = new DBPConnectionType(
SecurityUtils.generateUniqueId(),
name,
new RGB(0xFF, 0xFF, 0xFF),
"255,255,255",
"New type",
true,
false);
......@@ -180,7 +181,7 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
@Override
public void widgetSelected(SelectionEvent e)
{
getSelectedType().setColor(colorPicker.getItem(colorPicker.getSelectionIndex()).getBackground());
getSelectedType().setColor(StringConverter.asString(colorPicker.getItem(colorPicker.getSelectionIndex()).getBackground().getRGB()));
updateTableInfo();
}
});
......@@ -192,7 +193,7 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
{
DBPConnectionType connectionType = getSelectedType();
ColorDialog colorDialog = new ColorDialog(parent.getShell());
colorDialog.setRGB(connectionType.getColor().getRGB());
colorDialog.setRGB(StringConverter.asRGB(connectionType.getColor()));
RGB rgb = colorDialog.open();
if (rgb != null) {
Color color = null;
......@@ -209,7 +210,7 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
colorPicker.add(null, COLOR_TEXT, color, color);
}
colorPicker.select(color);
getSelectedType().setColor(color);
getSelectedType().setColor(StringConverter.asString(color.getRGB()));
updateTableInfo();
}
}
......@@ -251,7 +252,7 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
private void showSelectedType(DBPConnectionType connectionType)
{
colorPicker.select(connectionType.getColor());
colorPicker.select(UIUtils.getConnectionTypeColor(connectionType));
typeName.setText(connectionType.getName());
typeDescription.setText(connectionType.getDescription());
autocommitCheck.setSelection(connectionType.isAutocommit());
......@@ -267,8 +268,9 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
if (item.getData() == connectionType) {
item.setText(0, connectionType.getName());
item.setText(1, connectionType.getDescription());
item.setBackground(0, connectionType.getColor());
item.setBackground(1, connectionType.getColor());
Color connectionColor = UIUtils.getConnectionTypeColor(connectionType);
item.setBackground(0, connectionColor);
item.setBackground(1, connectionColor);
break;
}
}
......@@ -319,9 +321,10 @@ public class PrefPageConnectionTypes extends PreferencePage implements IWorkbenc
item.setText(0, connectionType.getName());
item.setText(1, CommonUtils.toString(connectionType.getDescription()));
if (connectionType.getColor() != null) {
item.setBackground(0, connectionType.getColor());
item.setBackground(1, connectionType.getColor());
colorPicker.add(null, COLOR_TEXT, connectionType.getColor(), connectionType.getColor());
Color connectionColor = UIUtils.getConnectionTypeColor(connectionType);
item.setBackground(0, connectionColor);
item.setBackground(1, connectionColor);
colorPicker.add(null, COLOR_TEXT, connectionColor, connectionColor);
}
item.setData(connectionType);
}
......
......@@ -134,7 +134,7 @@ class DatabaseNavigatorLabelProvider extends LabelProvider implements IFontProvi
if (element instanceof DBNDataSource) {
DataSourceDescriptor ds = ((DBNDatabaseNode) element).getDataSourceContainer();
if (ds != null) {
return ds.getConnectionInfo().getColor();
return UIUtils.getConnectionColor(ds.getConnectionInfo());
}
}
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册