提交 6526a0d2 编写于 作者: S serge-rider

#6745 FDW output page. FDW registry.

上级 cbb05f83
......@@ -16,11 +16,17 @@
*/
package org.jkiss.dbeaver.ext.postgresql.tools.fdw;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper;
import org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.navigator.DBNDataSource;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNModel;
......@@ -31,11 +37,12 @@ import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey;
import org.jkiss.dbeaver.model.virtual.DBVModel;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.properties.PropertySourceCustom;
import org.jkiss.dbeaver.ui.dialogs.ActiveWizard;
import java.util.*;
class PostgreFDWConfigWizard extends ActiveWizard {
class PostgreFDWConfigWizard extends ActiveWizard implements DBPContextProvider {
private static final Log log = Log.getLog(PostgreFDWConfigWizard.class);
......@@ -47,23 +54,62 @@ class PostgreFDWConfigWizard extends ActiveWizard {
private List<DBSEntity> proposedEntities = null;
private List<DBNDatabaseNode> selectedEntities;
private DBPDataSourceContainer selectedDataSource;
private FDWInfo selectedFDW;
private String fdwServerId;
private PropertySourceCustom fdwPropertySource;
static class FDWInfo {
PostgreForeignDataWrapper installedFDW;
FDWConfigDescriptor fdwDescriptor;
String getId() {
return installedFDW != null ? installedFDW.getName() : fdwDescriptor.getFdwId();
}
String getDescription() {
return installedFDW != null ? installedFDW.getDescription() : fdwDescriptor.getDescription();
}
}
PostgreFDWConfigWizard(PostgreDatabase database) {
setWindowTitle("Foreign Data Wrappers configurator");
this.database = database;
setNeedsProgressMonitor(true);
this.fdwPropertySource = new PropertySourceCustom();
this.fdwPropertySource.setDefValueResolver(database.getDataSource().getContainer().getVariablesResolver());
}
public PostgreDatabase getDatabase() {
return database;
}
public FDWInfo getSelectedFDW() {
return selectedFDW;
}
public void setSelectedFDW(FDWInfo selectedFDW) {
this.selectedFDW = selectedFDW;
}
public String getFdwServerId() {
return fdwServerId;
}
public void setFdwServerId(String fdwServerId) {
this.fdwServerId = fdwServerId;
}
public PropertySourceCustom getFdwPropertySource() {
return fdwPropertySource;
}
@Override
public void addPages() {
inputPage = new PostgreFDWConfigWizardPageInput(this);
configPage = new PostgreFDWConfigWizardPageConfig(this);
addPage(inputPage);
addPage(configPage);
addPage(new PostgreFDWConfigWizardPageFinal(this));
super.addPages();
}
......@@ -167,4 +213,9 @@ class PostgreFDWConfigWizard extends ActiveWizard {
return false;
}
@Nullable
@Override
public DBCExecutionContext getExecutionContext() {
return DBUtils.getDefaultContext(database, true);
}
}
......@@ -24,6 +24,9 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper;
import org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor;
import org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigRegistry;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.impl.PropertyDescriptor;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
......@@ -35,6 +38,8 @@ import org.jkiss.dbeaver.ui.properties.PropertyTreeViewer;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfigWizard> {
......@@ -44,9 +49,11 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
private boolean activated;
private Table entityTable;
private Combo fdwCombo;
private Text fdwServerText;
private PropertyTreeViewer propsEditor;
private Text targetDataSourceText;
private Text targetDriverText;
private List<PostgreFDWConfigWizard.FDWInfo> fdwList;
protected PostgreFDWConfigWizardPageConfig(PostgreFDWConfigWizard wizard)
{
......@@ -59,7 +66,7 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
@Override
public boolean isPageComplete()
{
return false;
return activated;
}
@Override
......@@ -72,13 +79,21 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
fdwGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fdwCombo = UIUtils.createLabelCombo(fdwGroup, "Foreign Data Wrapper", SWT.DROP_DOWN | SWT.READ_ONLY);
fdwCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getWizard().setSelectedFDW(fdwList.get(fdwCombo.getSelectionIndex()));
refreshFDWProperties();
}
});
UIUtils.createEmptyLabel(fdwGroup, 1, 1);
UIUtils.createLink(fdwGroup, "If you don't see right data wrapper in the list then try to <a>install it</a>", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
}
});
fdwServerText = UIUtils.createLabelText(fdwGroup, "Server ID", "", SWT.BORDER);
fdwServerText.addModifyListener(e -> getWizard().setFdwServerId(fdwServerText.getText()));
}
SashForm sashForm = new SashForm(composite, SWT.HORIZONTAL);
......@@ -88,6 +103,8 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
//UIUtils.createControlLabel(settingsGroup, "Options", 2);
propsEditor = new PropertyTreeViewer(settingsGroup, SWT.BORDER);
propsEditor.setNamesEditable(true);
propsEditor.setNewPropertiesAllowed(true);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
propsEditor.getControl().setLayoutData(gd);
......@@ -112,6 +129,26 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
setControl(composite);
}
private void refreshFDWProperties() {
{
// Fill options
DBPDataSourceContainer targetDataSource = getWizard().getSelectedDataSource();
PostgreFDWConfigWizard.FDWInfo selectedFDW = getWizard().getSelectedFDW();
PropertySourceCustom propertySource = new PropertySourceCustom();
propertySource.setDefValueResolver(targetDataSource.getVariablesResolver());
if (selectedFDW != null && selectedFDW.fdwDescriptor != null) {
propertySource.addProperties(selectedFDW.fdwDescriptor.getProperties());
} else if (selectedFDW != null) {
// Add some default props
propertySource.addProperty(new PropertyDescriptor(null, "host", "host", "Remote database host", false, String.class, "${host}", null));
propertySource.addProperty(new PropertyDescriptor(null, "port", "port", "Remote database port", false, String.class, "${port}", null));
propertySource.addProperty(new PropertyDescriptor(null, "dbname", "dbname", "Remote database name", false, String.class, "${database}", null));
}
propsEditor.loadProperties(propertySource);
}
}
@Override
public void activatePage() {
if (!activated) {
......@@ -132,7 +169,37 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
try {
getWizard().getRunnableContext().run(false, true, monitor -> {
try {
getWizard().getDatabase().getForeignDataWrappers(monitor);
// Fill from both installed FDW and pre-configured FDW
fdwList = new ArrayList<>();
for (PostgreForeignDataWrapper fdw : CommonUtils.safeCollection(getWizard().getDatabase().getForeignDataWrappers(monitor))) {
PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
fdwInfo.installedFDW = fdw;
fdwList.add(fdwInfo);
}
for (FDWConfigDescriptor fdw : FDWConfigRegistry.getInstance().getConfigDescriptors()) {
boolean found = false;
for (PostgreFDWConfigWizard.FDWInfo fdwInfo : fdwList) {
if (fdwInfo.getId().equals(fdw.getFdwId())) {
fdwInfo.fdwDescriptor = fdw;
found = true;
break;
}
}
if (!found) {
PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
fdwInfo.fdwDescriptor = fdw;
fdwList.add(fdwInfo);
}
}
fdwCombo.removeAll();
for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
String fdwName = fdw.getId();
if (!CommonUtils.isEmpty(fdw.getDescription())) {
fdwName += " (" + fdw.getDescription() + ")";
}
fdwCombo.add(fdwName);
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
......@@ -146,18 +213,31 @@ class PostgreFDWConfigWizardPageConfig extends ActiveWizardPage<PostgreFDWConfig
}
setErrorMessage(null);
String hostName = CommonUtils.notEmpty(targetDataSource.getConnectionConfiguration().getHostName());
String hostPort = CommonUtils.notEmpty(targetDataSource.getConnectionConfiguration().getHostPort());
String databaseName = CommonUtils.notEmpty(targetDataSource.getConnectionConfiguration().getDatabaseName());
// Detect FDW from target container
if (CommonUtils.isEmpty(fdwServerText.getText())) {
String fdwServerId = targetDataSource.getDriver().getId() + "_srv";
getWizard().setFdwServerId(fdwServerId);
fdwServerText.setText(fdwServerId);
}
{
// Fill options
PropertySourceCustom propertySource = new PropertySourceCustom();
propertySource.addProperty(new PropertyDescriptor(null, "host", "host", "Remote database host", false, String.class, hostName, null));
propertySource.addProperty(new PropertyDescriptor(null, "port", "port", "Remote database port", false, String.class, hostPort, null));
propertySource.addProperty(new PropertyDescriptor(null, "dbname", "dbname", "Remote database name", false, String.class, databaseName, null));
propsEditor.loadProperties(propertySource);
PostgreFDWConfigWizard.FDWInfo fdwInfo = getWizard().getSelectedFDW();
if (fdwInfo == null) {
FDWConfigDescriptor fdwConfig = FDWConfigRegistry.getInstance().findFirstMatch(targetDataSource);
if (fdwConfig != null) {
for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
if (fdw.fdwDescriptor == fdwConfig) {
fdwInfo = fdw;
break;
}
}
}
}
if (fdwInfo != null) {
getWizard().setSelectedFDW(fdwInfo);
fdwCombo.setText(fdwInfo.getId());
}
refreshFDWProperties();
// Fill entities
targetDataSourceText.setText(targetDataSource.getName());
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.tools.fdw;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.ui.UIServiceSQL;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage;
import java.lang.reflect.InvocationTargetException;
class PostgreFDWConfigWizardPageFinal extends ActiveWizardPage<PostgreFDWConfigWizard> {
private static final Log log = Log.getLog(PostgreFDWConfigWizardPageFinal.class);
private boolean activated;
private Object sqlPanel;
protected PostgreFDWConfigWizardPageFinal(PostgreFDWConfigWizard wizard)
{
super("Script");
setTitle("Foreign wrappers mapping SQL script");
setDescription("Preview script and perform install");
setWizard(wizard);
}
@Override
public boolean isPageComplete()
{
return activated && getErrorMessage() == null;
}
@Override
public void createControl(Composite parent)
{
Composite composite = UIUtils.createComposite(parent, 1);
{
Group settingsGroup = UIUtils.createControlGroup(composite, "Script", 2, GridData.FILL_BOTH, 0);
settingsGroup.setLayout(new FillLayout());
UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
if (service != null) {
try {
sqlPanel = service.createSQLPanel(
UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(),
settingsGroup,
getWizard(),
"FDW Script",
true,
"");
} catch (DBException e) {
log.debug(e);
setErrorMessage(e.getMessage());
}
}
}
setControl(composite);
}
@Override
public void activatePage() {
if (!activated) {
activated = true;
}
generateScript();
super.activatePage();
}
private void generateScript() {
// Fill FDW list
try {
getWizard().getRunnableContext().run(false, true, monitor -> {
try {
throw new DBCException("Not implemented yet");
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
log.debug(e.getTargetException());
setErrorMessage(e.getTargetException().getMessage());
return;
} catch (InterruptedException e) {
return;
}
setErrorMessage(null);
String sql = "CREATE FOREIGN SERVER";
UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
if (service != null) {
service.setSQLPanelText(sqlPanel, sql);
}
}
}
......@@ -20,6 +20,7 @@ Export-Package: org.jkiss.dbeaver.ext.postgresql,
org.jkiss.dbeaver.ext.postgresql.edit,
org.jkiss.dbeaver.ext.postgresql.model,
org.jkiss.dbeaver.ext.postgresql.model.data,
org.jkiss.dbeaver.ext.postgresql.model.fdw,
org.jkiss.dbeaver.ext.postgresql.model.impls,
org.jkiss.dbeaver.ext.postgresql.model.jdbc,
org.jkiss.dbeaver.ext.postgresql.model.lock,
......
......@@ -21,6 +21,7 @@
<plugin>
<extension-point id="org.jkiss.dbeaver.postgresql.serverType" name="PostgreSQL Server Type" schema="schema/org.jkiss.dbeaver.postgresql.serverType.exsd"/>
<extension-point id="org.jkiss.dbeaver.postgresql.fdw.config" name="PostgreSQL Foreign Data Wrappers Config" schema="schema/org.jkiss.dbeaver.postgresql.fdw.config.exsd"/>
<extension point="org.jkiss.dbeaver.postgresql.serverType">
<serverType id="postgresql" name="PostgreSQL" class="org.jkiss.dbeaver.ext.postgresql.model.impls.PostgreServerPostgreSQL" logo="icons/postgresql_logo.png" customURL="true"/>
......@@ -31,6 +32,23 @@
<serverType id="cockroach" name="CockroachDB" class="org.jkiss.dbeaver.ext.postgresql.model.impls.PostgreServerCockroachDB" logo="icons/cockroach_logo.png" defaultDatbase="system" defaultUser="root" customURL="true"/>
</extension>
<extension point="org.jkiss.dbeaver.postgresql.fdw.config">
<fdw id="postgresql" fdwId="postgres_fdw" databases="postgres" name="PostgreSQL" description="Default FDW for PostgreSQL servers" docURL="https://www.postgresql.org/docs/current/postgres-fdw.html">
<propertyGroup label="Options">
<property id="host" description="Host name" defaultValue="${host}"/>
<property id="port" description="Port number" defaultValue="${port}"/>
<property id="dbname" description="Database name" defaultValue="${database}"/>
</propertyGroup>
</fdw>
<fdw id="clickhouse" fdwId="clickhousedb_fdw" databases="clickhouse" name="Yandex Clickhouse" description="Clickhouse FDW by Percona Labs" docURL="https://github.com/Percona-Lab/clickhousedb_fdw">
<propertyGroup label="Options">
<property id="host" description="Host name" defaultValue="${host}"/>
<property id="port" description="Port number" defaultValue="${port}"/>
<property id="dbname" description="Database name" defaultValue="${database}"/>
</propertyGroup>
</fdw>
</extension>
<!--
PostgreSQL extension
-->
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.ext.postgresql" id="org.jkiss.dbeaver.postgresql.fdw.config" name="FDW Config"/>
</appInfo>
<documentation>
FDW Config
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="fdw" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="fdw">
<complexType>
<attribute name="id" type="string">
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -3,7 +3,7 @@
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.pluginService" name="Plugin Service"/>
<meta.schema plugin="org.jkiss.dbeaver.ext.postgresql" id="org.jkiss.dbeaver.postgresql.serverType" name="PG Server Type"/>
</appInfo>
<documentation>
Plugin Service
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.model.fdw;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.impl.PropertyDescriptor;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
* FDWConfigDescriptor
*/
public class FDWConfigDescriptor extends AbstractDescriptor
{
private static final Log log = Log.getLog(FDWConfigDescriptor.class);
@NotNull
private final String id;
@NotNull
private final String fdwId;
@NotNull
private final String name;
private final String description;
private final List<DBPPropertyDescriptor> properties = new ArrayList<>();
private final String[] foreignDatabases;
public FDWConfigDescriptor(IConfigurationElement config)
{
super(config);
this.id = config.getAttribute("id");
this.fdwId = config.getAttribute("fdwId");
this.name = config.getAttribute("label");
this.description = config.getAttribute("description");
this.foreignDatabases = CommonUtils.notEmpty(config.getAttribute("databases")).split(",");
for (IConfigurationElement prop : ArrayUtils.safeArray(config.getChildren(PropertyDescriptor.TAG_PROPERTY_GROUP))) {
properties.addAll(PropertyDescriptor.extractProperties(prop));
}
}
@NotNull
public String getId() {
return id;
}
@NotNull
public String getFdwId() {
return fdwId;
}
@NotNull
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String[] getForeignDatabases() {
return foreignDatabases;
}
public List<DBPPropertyDescriptor> getProperties() {
return properties;
}
public boolean matches(DBPDataSourceContainer dataSource) {
for (String dbId : foreignDatabases) {
if (!dbId.isEmpty() && dataSource.getDriver().getId().contains(dbId)) {
return true;
}
}
return false;
}
@Override
public String toString() {
return id;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.model.fdw;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import java.util.ArrayList;
import java.util.List;
/**
* DataTransferRegistry
*/
public class FDWConfigRegistry {
public static final String EXTENSION_ID = "org.jkiss.dbeaver.postgresql.fdw.config"; //$NON-NLS-1$
private static FDWConfigRegistry instance = null;
private static final Log log = Log.getLog(FDWConfigRegistry.class);
public synchronized static FDWConfigRegistry getInstance()
{
if (instance == null) {
instance = new FDWConfigRegistry(Platform.getExtensionRegistry());
}
return instance;
}
private List<FDWConfigDescriptor> configDescriptors = new ArrayList<>();
private FDWConfigRegistry(IExtensionRegistry registry)
{
// Load datasource providers from external plugins
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(EXTENSION_ID);
for (IConfigurationElement ext : extElements) {
// Load main configDescriptors
if ("fdw".equals(ext.getName())) {
configDescriptors.add(new FDWConfigDescriptor(ext));
}
}
}
public List<FDWConfigDescriptor> getConfigDescriptors() {
return configDescriptors;
}
public FDWConfigDescriptor findFirstMatch(DBPDataSourceContainer dataSource) {
for (FDWConfigDescriptor desc : configDescriptors) {
if (desc.matches(dataSource)) {
return desc;
}
}
return null;
}
}
......@@ -23,14 +23,13 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
import org.jkiss.dbeaver.model.app.DBPPlatform;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation;
import org.jkiss.dbeaver.model.data.DBDPreferences;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.net.DBWNetworkHandler;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.runtime.DBRProgressListener;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectFilter;
......@@ -39,7 +38,6 @@ import org.jkiss.dbeaver.utils.GeneralUtils;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
* DBPDataSourceContainer
......
......@@ -125,6 +125,7 @@ public class PropertyDescriptor implements DBPPropertyDescriptor, IPropertyValue
this.category = category;
this.id = config.getAttribute(ATTR_ID);
this.name = config.getAttribute(ATTR_LABEL);
if (CommonUtils.isEmpty(this.name)) this.name = CommonUtils.toString(this.id);
this.description = config.getAttribute(ATTR_DESCRIPTION);
this.required = CommonUtils.getBoolean(config.getAttribute(ATTR_REQUIRED));
String typeString = config.getAttribute(ATTR_TYPE);
......
......@@ -35,6 +35,7 @@ public class PropertySourceCustom implements DBPPropertySource {
private Map<Object, Object> originalValues = new TreeMap<>();
private Map<Object, Object> propValues = new TreeMap<>();
private Map<Object,Object> defaultValues = new TreeMap<>();
private GeneralUtils.IVariableResolver defValueResolver = null;
public PropertySourceCustom()
{
......@@ -46,6 +47,10 @@ public class PropertySourceCustom implements DBPPropertySource {
setValues(values);
}
public void setDefValueResolver(GeneralUtils.IVariableResolver defValueResolver) {
this.defValueResolver = defValueResolver;
}
public void setValues(Map<?, ?> values)
{
this.originalValues = new HashMap<>();
......@@ -98,8 +103,7 @@ public class PropertySourceCustom implements DBPPropertySource {
}
}
public void addProperties(Collection<? extends DBPPropertyDescriptor> properties)
{
public void addProperties(Collection<? extends DBPPropertyDescriptor> properties) {
props.addAll(properties);
for (DBPPropertyDescriptor prop : properties) {
final Object defaultValue = prop.getDefaultValue();
......@@ -109,6 +113,13 @@ public class PropertySourceCustom implements DBPPropertySource {
}
}
private Object getDefaultValue(Object defaultValue) {
if (defValueResolver != null && defaultValue instanceof String) {
return GeneralUtils.replaceVariables((String) defaultValue, defValueResolver);
}
return defaultValue;
}
@Override
public Object getEditableValue()
{
......@@ -130,7 +141,7 @@ public class PropertySourceCustom implements DBPPropertySource {
if (value == null) {
value = originalValues.get(id);
}
return value != null ? value : defaultValues.get(id);
return value != null ? value : getDefaultValue(defaultValues.get(id));
}
@Override
......@@ -146,7 +157,7 @@ public class PropertySourceCustom implements DBPPropertySource {
if (value == null) {
return false;
}
final Object defaultValue = defaultValues.get(id);
final Object defaultValue = getDefaultValue(defaultValues.get(id));
return !CommonUtils.equalObjects(value, defaultValue);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册