private void parseSampleURL(DBPDriver driver) { metaURL = null; if (!CommonUtils.isEmpty(driver.getSampleURL())) { isCustom = false; try { metaURL = DriverDescriptor.parseSampleURL(driver.getSampleURL()); } catch (DBException e) { setErrorMessage(e.getMessage()); } final Set<String> properties = metaURL.getAvailableProperties(); urlText.setEditable(false); // urlText.setBackground(urlText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); showControlGroup(GROUP_HOST, properties.contains(DriverDescriptor.PROP_HOST)); showControlGroup(GROUP_SERVER, properties.contains(DriverDescriptor.PROP_SERVER)); showControlGroup(GROUP_DB, properties.contains(DriverDescriptor.PROP_DATABASE)); showControlGroup( GROUP_PATH, properties.contains(DriverDescriptor.PROP_FOLDER) || properties.contains(DriverDescriptor.PROP_FILE)); } else { isCustom = true; showControlGroup(GROUP_HOST, false); showControlGroup(GROUP_SERVER, false); showControlGroup(GROUP_DB, false); showControlGroup(GROUP_PATH, false); urlText.setEditable(true); urlText.setBackground(null); } showControlGroup(GROUP_LOGIN, !driver.isAnonymousAccess()); updateCreateButton(driver); settingsGroup.layout(); }
@Override public boolean isComplete() { if (isCustom) { return !CommonUtils.isEmpty(urlText.getText()); } else { if (metaURL == null) { return false; } for (String prop : metaURL.getRequiredProperties()) { if ((prop.equals(DriverDescriptor.PROP_HOST) && CommonUtils.isEmpty(hostText.getText())) || (prop.equals(DriverDescriptor.PROP_PORT) && CommonUtils.isEmpty(portText.getText())) || (prop.equals(DriverDescriptor.PROP_DATABASE) && CommonUtils.isEmpty(dbText.getText()))) { return false; } } return true; } }
@Override public void saveSettings(DBPDataSourceContainer dataSource) { DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration(); final Set<String> properties = metaURL == null ? Collections.<String>emptySet() : metaURL.getAvailableProperties(); if (hostText != null && properties.contains(DriverDescriptor.PROP_HOST)) { connectionInfo.setHostName(hostText.getText().trim()); } if (portText != null && properties.contains(DriverDescriptor.PROP_PORT)) { connectionInfo.setHostPort(portText.getText().trim()); } if (serverText != null && properties.contains(DriverDescriptor.PROP_SERVER)) { connectionInfo.setServerName(serverText.getText().trim()); } if (dbText != null && properties.contains(DriverDescriptor.PROP_DATABASE)) { connectionInfo.setDatabaseName(dbText.getText().trim()); } if (pathText != null && (properties.contains(DriverDescriptor.PROP_FOLDER) || properties.contains(DriverDescriptor.PROP_FILE))) { connectionInfo.setDatabaseName(pathText.getText().trim()); } if (userNameText != null) { connectionInfo.setUserName(userNameText.getText().trim()); } if (passwordText != null) { connectionInfo.setUserPassword(passwordText.getText()); } super.saveSettings(dataSource); if (isCustom) { if (urlText != null) { connectionInfo.setUrl(urlText.getText().trim()); } } else { if (urlText != null && connectionInfo.getUrl() != null) { urlText.setText(connectionInfo.getUrl()); } } }