提交 0a6a9131 编写于 作者: J jurgen

Properties model refactoring

Former-commit-id: 3ced7682
上级 54a036f6
......@@ -18,7 +18,6 @@
package org.jkiss.dbeaver.model;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -53,7 +52,7 @@ public interface DBPDataSourceProvider
* @return property group which contains all supported properties
* @throws DBException on any error
*/
IPropertyDescriptor[] getConnectionProperties(
DBPPropertyDescriptor[] getConnectionProperties(
IRunnableContext runnableContext,
DBPDriver driver,
DBPConnectionInfo connectionInfo)
......
......@@ -20,7 +20,6 @@ package org.jkiss.dbeaver.model;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.dbeaver.DBException;
import java.util.Collection;
......@@ -66,7 +65,7 @@ public interface DBPDriver extends DBPObject
boolean isCustomDriverLoader();
Collection<IPropertyDescriptor> getConnectionPropertyDescriptors();
Collection<DBPPropertyDescriptor> getConnectionPropertyDescriptors();
Map<Object, Object> getDefaultConnectionProperties();
......
......@@ -17,12 +17,11 @@
*/
package org.jkiss.dbeaver.model.impl.jdbc;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.ui.properties.PropertyDescriptorEx;
......@@ -50,12 +49,12 @@ public abstract class JDBCDataSourceProvider implements DBPDataSourceProvider {
}
@Override
public IPropertyDescriptor[] getConnectionProperties(
public DBPPropertyDescriptor[] getConnectionProperties(
IRunnableContext runnableContext,
DBPDriver driver,
DBPConnectionInfo connectionInfo)
throws DBException {
Collection<IPropertyDescriptor> props = null;
Collection<DBPPropertyDescriptor> props = null;
Object driverInstance = driver.getDriverInstance(runnableContext);
if (driverInstance instanceof Driver) {
props = readDriverProperties(connectionInfo, (Driver) driverInstance);
......@@ -63,10 +62,10 @@ public abstract class JDBCDataSourceProvider implements DBPDataSourceProvider {
if (props == null) {
return null;
}
return props.toArray(new IPropertyDescriptor[props.size()]);
return props.toArray(new DBPPropertyDescriptor[props.size()]);
}
private Collection<IPropertyDescriptor> readDriverProperties(
private Collection<DBPPropertyDescriptor> readDriverProperties(
DBPConnectionInfo connectionInfo,
Driver driver)
throws DBException {
......@@ -83,7 +82,7 @@ public abstract class JDBCDataSourceProvider implements DBPDataSourceProvider {
return null;
}
List<IPropertyDescriptor> properties = new ArrayList<IPropertyDescriptor>();
List<DBPPropertyDescriptor> properties = new ArrayList<DBPPropertyDescriptor>();
for (DriverPropertyInfo desc : propDescs) {
if (DBConstants.DATA_SOURCE_PROPERTY_USER.equals(desc.name) || DBConstants.DATA_SOURCE_PROPERTY_PASSWORD.equals(desc.name)) {
// Skip user/password properties
......
......@@ -23,11 +23,11 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDataSourceProvider;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.registry.tree.*;
import org.jkiss.dbeaver.ui.DBIcon;
......@@ -58,7 +58,7 @@ public class DataSourceProviderDescriptor extends AbstractDescriptor
private DBXTreeNode treeDescriptor;
private final Map<String, DBXTreeNode> treeNodeMap = new HashMap<String, DBXTreeNode>();
private boolean driversManagable;
private final List<IPropertyDescriptor> driverProperties = new ArrayList<IPropertyDescriptor>();
private final List<DBPPropertyDescriptor> driverProperties = new ArrayList<DBPPropertyDescriptor>();
private final List<DriverDescriptor> drivers = new ArrayList<DriverDescriptor>();
private final List<DataSourceViewDescriptor> views = new ArrayList<DataSourceViewDescriptor>();
private final Map<String, ToolGroupDescriptor> toolGroups = new LinkedHashMap<String, ToolGroupDescriptor>();
......@@ -99,7 +99,11 @@ public class DataSourceProviderDescriptor extends AbstractDescriptor
this.driversManagable = driversElement.getAttribute(RegistryConstants.ATTR_MANAGABLE) == null ||
CommonUtils.getBoolean(driversElement.getAttribute(RegistryConstants.ATTR_MANAGABLE));
for (IConfigurationElement driverElement : driversElement.getChildren(RegistryConstants.TAG_DRIVER)) {
this.drivers.add(loadDriver(driverElement));
try {
this.drivers.add(loadDriver(driverElement));
} catch (Exception e) {
log.error("Error loading driver", e);
}
}
}
}
......@@ -200,14 +204,14 @@ public class DataSourceProviderDescriptor extends AbstractDescriptor
return driversManagable;
}
public List<IPropertyDescriptor> getDriverProperties()
public List<DBPPropertyDescriptor> getDriverProperties()
{
return driverProperties;
}
public IPropertyDescriptor getDriverProperty(String name)
public DBPPropertyDescriptor getDriverProperty(String name)
{
for (IPropertyDescriptor prop : driverProperties) {
for (DBPPropertyDescriptor prop : driverProperties) {
if (prop.getId().equals(name)) {
return prop;
}
......
......@@ -17,7 +17,6 @@
*/
package org.jkiss.dbeaver.registry;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
......@@ -33,12 +32,12 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverActivator;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
......@@ -47,7 +46,6 @@ import org.jkiss.dbeaver.ui.OverlayImageDescriptor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.AcceptLicenseDialog;
import org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog;
import org.jkiss.dbeaver.ui.properties.IPropertyDescriptorEx;
import org.jkiss.dbeaver.ui.properties.PropertyDescriptorEx;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.utils.CommonUtils;
......@@ -109,7 +107,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
private final List<DriverFileDescriptor> files = new ArrayList<DriverFileDescriptor>();
private final List<DriverFileDescriptor> origFiles = new ArrayList<DriverFileDescriptor>();
private final List<DriverPathDescriptor> pathList = new ArrayList<DriverPathDescriptor>();
private final List<IPropertyDescriptor> connectionPropertyDescriptors = new ArrayList<IPropertyDescriptor>();
private final List<DBPPropertyDescriptor> connectionPropertyDescriptors = new ArrayList<DBPPropertyDescriptor>();
private final List<OSDescriptor> supportedSystems = new ArrayList<OSDescriptor>();
private final List<ReplaceInfo> driverReplacements = new ArrayList<ReplaceInfo>();
......@@ -703,7 +701,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
@Override
public List<IPropertyDescriptor> getConnectionPropertyDescriptors()
public List<DBPPropertyDescriptor> getConnectionPropertyDescriptors()
{
return connectionPropertyDescriptors;
}
......@@ -750,11 +748,8 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
public void setDriverParameter(String name, String value, boolean setDefault)
{
Object valueObject = value;
IPropertyDescriptor prop = getProviderDescriptor().getDriverProperty(name);
if (prop instanceof IPropertyDescriptorEx) {
valueObject = RuntimeUtils.convertString(value, ((IPropertyDescriptorEx)prop).getDataType());
}
DBPPropertyDescriptor prop = getProviderDescriptor().getDriverProperty(name);
Object valueObject = prop == null ? value : RuntimeUtils.convertString(value, prop.getDataType());
customParameters.put(name, valueObject);
if (setDefault) {
defaultParameters.put(name, valueObject);
......
......@@ -20,8 +20,8 @@ package org.jkiss.dbeaver.registry.transfer;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.registry.AbstractDescriptor;
import org.jkiss.dbeaver.registry.RegistryConstants;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor;
......@@ -43,7 +43,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor
private final String name;
private final String description;
private final Image icon;
private final List<IPropertyDescriptor> properties = new ArrayList<IPropertyDescriptor>();
private final List<DBPPropertyDescriptor> properties = new ArrayList<DBPPropertyDescriptor>();
public DataTransferProcessorDescriptor(DataTransferNodeDescriptor node, IConfigurationElement config)
{
......@@ -84,7 +84,7 @@ public class DataTransferProcessorDescriptor extends AbstractDescriptor
return icon;
}
public List<IPropertyDescriptor> getProperties() {
public List<DBPPropertyDescriptor> getProperties() {
return properties;
}
......
......@@ -29,6 +29,7 @@ import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPConnectionInfo;
import org.jkiss.dbeaver.model.DBPDriver;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.ui.dialogs.EnterNameDialog;
import org.jkiss.dbeaver.ui.properties.PropertyDescriptorEx;
import org.jkiss.dbeaver.ui.properties.PropertySourceCustom;
......@@ -46,8 +47,8 @@ public class ConnectionPropertiesControl extends PropertyTreeViewer {
public static final String USER_PROPERTIES_CATEGORY = CoreMessages.controls_connection_properties_category_user_properties;
private List<IPropertyDescriptor> driverProvidedProperties;
private List<IPropertyDescriptor> customProperties;
private List<DBPPropertyDescriptor> driverProvidedProperties;
private List<DBPPropertyDescriptor> customProperties;
public ConnectionPropertiesControl(Composite parent, int style)
{
......@@ -120,8 +121,8 @@ public class ConnectionPropertiesControl extends PropertyTreeViewer {
}
}
private List<IPropertyDescriptor> getAllProperties(DBPDriver driver, boolean includeCustom) {
List<IPropertyDescriptor> propertyDescriptors = new ArrayList<IPropertyDescriptor>();
private List<DBPPropertyDescriptor> getAllProperties(DBPDriver driver, boolean includeCustom) {
List<DBPPropertyDescriptor> propertyDescriptors = new ArrayList<DBPPropertyDescriptor>();
propertyDescriptors.addAll(driver.getConnectionPropertyDescriptors());
if (driverProvidedProperties != null) {
propertyDescriptors.addAll(driverProvidedProperties);
......@@ -135,9 +136,9 @@ public class ConnectionPropertiesControl extends PropertyTreeViewer {
private void loadDriverProperties(IRunnableContext runnableContext, DBPDriver driver, DBPConnectionInfo connectionInfo)
{
try {
final IPropertyDescriptor[] connectionsProps =
final DBPPropertyDescriptor[] connectionsProps =
driver.getDataSourceProvider().getConnectionProperties(runnableContext, driver, connectionInfo);
driverProvidedProperties = new ArrayList<IPropertyDescriptor>();
driverProvidedProperties = new ArrayList<DBPPropertyDescriptor>();
if (connectionsProps != null) {
Collections.addAll(driverProvidedProperties, connectionsProps);
}
......@@ -150,12 +151,12 @@ public class ConnectionPropertiesControl extends PropertyTreeViewer {
{
// Collect all driver (and all other) properties
Set<String> propNames = new TreeSet<String>();
List<IPropertyDescriptor> allProperties = getAllProperties(driver, false);
for (IPropertyDescriptor prop : allProperties) {
List<DBPPropertyDescriptor> allProperties = getAllProperties(driver, false);
for (DBPPropertyDescriptor prop : allProperties) {
propNames.add(CommonUtils.toString(prop.getId()));
}
customProperties = new ArrayList<IPropertyDescriptor>();
customProperties = new ArrayList<DBPPropertyDescriptor>();
// Find prop values which are not from driver
for (Object propId : properties.keySet()) {
final String propName = propId.toString();
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.ui.properties;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.utils.CommonUtils;
......@@ -28,7 +29,7 @@ import java.util.*;
*/
public class PropertySourceCustom implements IPropertySourceEx {
private List<IPropertyDescriptor> props = new ArrayList<IPropertyDescriptor>();
private List<DBPPropertyDescriptor> props = new ArrayList<DBPPropertyDescriptor>();
private Map<Object, Object> originalValues = new TreeMap<Object, Object>();
private Map<Object, Object> propValues = new TreeMap<Object, Object>();
......@@ -38,7 +39,7 @@ public class PropertySourceCustom implements IPropertySourceEx {
{
}
public PropertySourceCustom(Collection<? extends IPropertyDescriptor> properties, Map<Object, Object> values)
public PropertySourceCustom(Collection<? extends DBPPropertyDescriptor> properties, Map<Object, Object> values)
{
addProperties(properties);
setValues(values);
......@@ -50,10 +51,10 @@ public class PropertySourceCustom implements IPropertySourceEx {
// Set only allowed properties + transform property types
for (Map.Entry<Object, Object> value : values.entrySet()) {
Object propValue = value.getValue();
for (IPropertyDescriptor prop : props) {
for (DBPPropertyDescriptor prop : props) {
if (prop.getId().equals(value.getKey())) {
if (propValue instanceof String && prop instanceof IPropertyDescriptorEx) {
propValue = RuntimeUtils.convertString((String) value.getValue(), ((IPropertyDescriptorEx) prop).getDataType());
if (propValue instanceof String) {
propValue = RuntimeUtils.convertString((String) value.getValue(), prop.getDataType());
}
originalValues.put(value.getKey(), propValue);
break;
......@@ -81,15 +82,13 @@ public class PropertySourceCustom implements IPropertySourceEx {
return allValues;
}
public void addProperties(Collection<? extends IPropertyDescriptor> properties)
public void addProperties(Collection<? extends DBPPropertyDescriptor> properties)
{
props.addAll(properties);
for (IPropertyDescriptor prop : properties) {
if (prop instanceof IPropertyDescriptorEx) {
final Object defaultValue = ((IPropertyDescriptorEx) prop).getDefaultValue();
if (defaultValue != null) {
defaultValues.put(prop.getId(), defaultValue);
}
for (DBPPropertyDescriptor prop : properties) {
final Object defaultValue = prop.getDefaultValue();
if (defaultValue != null) {
defaultValues.put(prop.getId(), defaultValue);
}
}
}
......
......@@ -18,7 +18,6 @@
package org.jkiss.dbeaver.ext.wmi;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.wmi.model.WMIDataSource;
......@@ -45,7 +44,7 @@ public class WMIDataSourceProvider implements DBPDataSourceProvider {
}
@Override
public IPropertyDescriptor[] getConnectionProperties(
public DBPPropertyDescriptor[] getConnectionProperties(
IRunnableContext runnableContext,
DBPDriver driver,
DBPConnectionInfo connectionInfo) throws DBException
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册