use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.
the class ConnectionWizard method getActiveDataSource.
@NotNull
public DataSourceDescriptor getActiveDataSource() {
DriverDescriptor driver = (DriverDescriptor) getSelectedDriver();
DataSourceDescriptor info = infoMap.get(driver);
DBPDataSourceRegistry registry = getDataSourceRegistry();
if (registry == null) {
throw new IllegalStateException("No active project");
}
if (info == null) {
DBPConnectionConfiguration connectionInfo = new DBPConnectionConfiguration();
info = new DataSourceDescriptor(registry, DataSourceDescriptor.generateNewId(getSelectedDriver()), driver, connectionInfo);
DBPNativeClientLocation defaultClientLocation = driver.getDefaultClientLocation();
if (defaultClientLocation != null) {
info.getConnectionConfiguration().setClientHomeId(defaultClientLocation.getName());
}
info.setSavePassword(true);
infoMap.put(driver, info);
}
return info;
}
use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.
the class ClientHomesSelector method populateHomes.
public void populateHomes(DBPDriver driver, String currentHome, boolean selectDefault) {
this.driver = driver;
this.currentHomeId = currentHome;
this.homesCombo.removeAll();
this.homeIds.clear();
Map<String, DBPNativeClientLocation> homes = new LinkedHashMap<>();
AbstractJob hlJob = new AbstractJob("Find native client homes") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
for (DBPNativeClientLocation ncl : driver.getNativeClientLocations()) {
homes.put(ncl.getName(), ncl);
}
DBPNativeClientLocationManager clientManager = driver.getNativeClientManager();
if (clientManager != null) {
for (DBPNativeClientLocation location : clientManager.findLocalClientLocations()) {
homes.putIfAbsent(location.getName(), location);
}
}
return Status.OK_STATUS;
}
};
hlJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
UIUtils.syncExec(() -> {
for (DBPNativeClientLocation location : homes.values()) {
homesCombo.add(location.getDisplayName());
homeIds.add(location.getName());
if (currentHomeId != null && location.getName().equals(currentHomeId)) {
homesCombo.select(homesCombo.getItemCount() - 1);
}
}
if (homesCombo.getItemCount() == 0) {
homesCombo.add(UIConnectionMessages.controls_client_home_selector_missing);
homeIds.add(null);
}
if (selectDefault && homesCombo.getSelectionIndex() == -1) {
homesCombo.select(0);
currentHomeId = homeIds.get(0);
}
homesCombo.add(UIConnectionMessages.controls_client_home_selector_browse);
displayClientVersion();
homesCombo.setEnabled(true);
});
super.done(event);
}
});
hlJob.schedule();
}
use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.
the class ClientHomesPanel method createHomeItem.
private TableItem createHomeItem(@NotNull DBPNativeClientLocationManager clientManager, @NotNull DBPNativeClientLocation clientLocation, boolean provided) {
DBPNativeClientLocation defaultLocalClientLocation = clientManager.getDefaultLocalClientLocation();
if (defaultLocalClientLocation == null) {
List<DBPNativeClientLocation> driverLocations = driver.getNativeClientLocations();
if (!CommonUtils.isEmpty(driverLocations)) {
defaultLocalClientLocation = driverLocations.get(0);
}
}
HomeInfo homeInfo = new HomeInfo(clientLocation);
homeInfo.isProvided = provided;
homeInfo.isDefault = defaultLocalClientLocation != null && clientLocation.getName().equals(defaultLocalClientLocation.getName());
TableItem homeItem = new TableItem(homesTable, SWT.NONE);
homeItem.setText(clientLocation.getDisplayName());
homeItem.setImage(DBeaverIcons.getImage(UIIcon.HOME));
homeItem.setData(homeInfo);
if (!homeInfo.isProvided) {
homeItem.setFont(fontItalic);
} else {
if (homeInfo.isDefault) {
homeItem.setFont(fontBold);
}
}
return homeItem;
}
use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by serge-rider.
the class DriverDescriptorSerializerLegacy method serialize.
public void serialize(XMLBuilder xml, boolean export) throws IOException {
Map<String, String> pathSubstitutions = getPathSubstitutions();
try (XMLBuilder.Element e0 = xml.startElement(RegistryConstants.TAG_DRIVER)) {
if (export) {
xml.addAttribute(RegistryConstants.ATTR_PROVIDER, driver.getProviderDescriptor().getId());
}
xml.addAttribute(RegistryConstants.ATTR_ID, driver.getId());
if (driver.isDisabled()) {
xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
}
if (!CommonUtils.isEmpty(driver.getCategory())) {
xml.addAttribute(RegistryConstants.ATTR_CATEGORY, driver.getCategory());
}
xml.addAttribute(RegistryConstants.ATTR_CATEGORIES, String.join(",", driver.getCategories()));
xml.addAttribute(RegistryConstants.ATTR_NAME, driver.getName());
xml.addAttribute(RegistryConstants.ATTR_CLASS, driver.getDriverClassName());
if (!CommonUtils.isEmpty(driver.getSampleURL())) {
xml.addAttribute(RegistryConstants.ATTR_URL, driver.getSampleURL());
}
if (!CommonUtils.isEmpty(driver.getDefaultPort())) {
xml.addAttribute(RegistryConstants.ATTR_PORT, driver.getDefaultPort());
}
if (!CommonUtils.isEmpty(driver.getDefaultDatabase())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_DATABASE, driver.getDefaultDatabase());
}
if (!CommonUtils.isEmpty(driver.getDefaultServer())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_SERVER, driver.getDefaultServer());
}
if (!CommonUtils.isEmpty(driver.getDefaultUser())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_USER, driver.getDefaultUser());
}
xml.addAttribute(RegistryConstants.ATTR_DESCRIPTION, CommonUtils.notEmpty(driver.getDescription()));
if (driver.isCustomDriverLoader()) {
xml.addAttribute(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER, driver.isCustomDriverLoader());
}
xml.addAttribute(RegistryConstants.ATTR_CUSTOM, driver.isCustom());
if (driver.isEmbedded()) {
xml.addAttribute(RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
}
if (driver.isAnonymousAccess()) {
xml.addAttribute(RegistryConstants.ATTR_ANONYMOUS, driver.isAnonymousAccess());
}
if (driver.isAllowsEmptyPassword()) {
xml.addAttribute("allowsEmptyPassword", driver.isAllowsEmptyPassword());
}
if (!driver.isInstantiable()) {
xml.addAttribute(RegistryConstants.ATTR_INSTANTIABLE, driver.isInstantiable());
}
// Libraries
for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
if (export && !lib.isDisabled()) {
continue;
}
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_LIBRARY)) {
xml.addAttribute(RegistryConstants.ATTR_TYPE, lib.getType().name());
xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, lib.getPath()));
xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
if (lib.isDisabled()) {
xml.addAttribute(RegistryConstants.ATTR_DISABLED, true);
}
if (!CommonUtils.isEmpty(lib.getPreferredVersion())) {
xml.addAttribute(RegistryConstants.ATTR_VERSION, lib.getPreferredVersion());
}
// xml.addAttribute(RegistryConstants.ATTR_CUSTOM, lib.isCustom());
List<DriverDescriptor.DriverFileInfo> files = driver.getResolvedFiles().get(lib);
if (files != null) {
for (DriverDescriptor.DriverFileInfo file : files) {
try (XMLBuilder.Element e2 = xml.startElement(RegistryConstants.TAG_FILE)) {
if (file.getFile() == null) {
log.warn("File missing in " + file.getId());
continue;
}
xml.addAttribute(RegistryConstants.ATTR_ID, file.getId());
if (!CommonUtils.isEmpty(file.getVersion())) {
xml.addAttribute(RegistryConstants.ATTR_VERSION, file.getVersion());
}
xml.addAttribute(RegistryConstants.ATTR_PATH, substitutePathVariables(pathSubstitutions, file.getFile().getAbsolutePath()));
}
}
}
}
}
// Client homes
for (DBPNativeClientLocation location : driver.getNativeClientHomes()) {
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_CLIENT_HOME)) {
xml.addAttribute(RegistryConstants.ATTR_ID, location.getName());
if (location.getPath() != null) {
xml.addAttribute(RegistryConstants.ATTR_PATH, location.getPath().getAbsolutePath());
}
}
}
// Parameters
for (Map.Entry<String, Object> paramEntry : driver.getCustomParameters().entrySet()) {
if (!CommonUtils.equalObjects(paramEntry.getValue(), driver.getDefaultParameters().get(paramEntry.getKey()))) {
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PARAMETER)) {
xml.addAttribute(RegistryConstants.ATTR_NAME, paramEntry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(paramEntry.getValue()));
}
}
}
// Properties
for (Map.Entry<String, Object> propEntry : driver.getCustomConnectionProperties().entrySet()) {
if (!CommonUtils.equalObjects(propEntry.getValue(), driver.getDefaultConnectionProperties().get(propEntry.getKey()))) {
try (XMLBuilder.Element e1 = xml.startElement(RegistryConstants.TAG_PROPERTY)) {
xml.addAttribute(RegistryConstants.ATTR_NAME, propEntry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(propEntry.getValue()));
}
}
}
}
}
use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by dbeaver.
the class ClientHomesPanel method loadHomes.
public void loadHomes(DBPDriver driver) {
homesTable.removeAll();
this.driver = driver;
selectHome(null);
DBPNativeClientLocationManager clientManager = this.driver.getNativeClientManager();
if (clientManager == null) {
// $NON-NLS-1$ //$NON-NLS-2$
log.debug("Client manager is not supported by driver '" + driver.getName() + "'");
}
Set<DBPNativeClientLocation> providedHomes = new LinkedHashSet<>();
if (clientManager != null) {
providedHomes.addAll(clientManager.findLocalClientLocations());
}
Set<DBPNativeClientLocation> allHomes = new LinkedHashSet<>();
allHomes.addAll(driver.getNativeClientLocations());
allHomes.addAll(providedHomes);
for (DBPNativeClientLocation home : allHomes) {
TableItem item = createHomeItem(clientManager, home, home instanceof RemoteNativeClientLocation || providedHomes.contains(home));
if (item != null) {
HomeInfo homeInfo = (HomeInfo) item.getData();
if (homeInfo.isDefault) {
homesTable.setSelection(homesTable.indexOf(item));
selectHome(homeInfo);
}
}
}
}
Aggregations