use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by dbeaver.
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 dbeaver.
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 dbeaver.
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 AbstractNativeToolHandler method validateClientHome.
private void validateClientHome(DBRProgressMonitor monitor, SETTINGS settings) throws DBCException {
DBPDataSourceContainer dataSourceContainer = settings.getDataSourceContainer();
if (isNativeClientHomeRequired()) {
String clientHomeId = dataSourceContainer.getConnectionConfiguration().getClientHomeId();
final DBPDriver driver = dataSourceContainer.getDriver();
final List<DBPNativeClientLocation> clientLocations = driver.getNativeClientLocations();
final DBPNativeClientLocationManager locationManager = driver.getNativeClientManager();
if (locationManager != null) {
clientLocations.addAll(locationManager.findLocalClientLocations());
}
if (clientHomeId == null) {
if (!clientLocations.isEmpty()) {
settings.setClientHome(clientLocations.get(0));
} else {
settings.setClientHome(null);
}
if (settings.getClientHome() == null) {
throw new DBCException("Client binaries location is not specified");
}
} else {
DBPNativeClientLocation clientHome = DBUtils.findObject(clientLocations, clientHomeId);
if (clientHome == null) {
clientHome = settings.findNativeClientHome(clientHomeId);
}
settings.setClientHome(clientHome);
}
if (settings.getClientHome() == null) {
throw new DBCException("Native client home '" + clientHomeId + "' not found");
}
}
DBPNativeClientLocation clientHome = settings.getClientHome();
if (!isNativeClientHomeRequired() || clientHome == null) {
return;
}
try {
clientHome.validateFilesPresence(monitor);
} catch (DBException e) {
throw new DBCException("Error downloading client file(s)", e);
} catch (InterruptedException e) {
// ignore
throw new DBCException("Client file download interrupted", e);
}
}
use of org.jkiss.dbeaver.model.connection.DBPNativeClientLocation in project dbeaver by dbeaver.
the class AbstractNativeToolWizard method updateErrorMessage.
void updateErrorMessage() {
WizardPage currentPage = (WizardPage) getStartingPage();
if (isNativeClientHomeRequired()) {
String clientHomeId = getSettings().getDataSourceContainer().getConnectionConfiguration().getClientHomeId();
List<DBPNativeClientLocation> nativeClientLocations = getSettings().getDataSourceContainer().getDriver().getNativeClientLocations();
if (CommonUtils.isEmpty(clientHomeId)) {
if (nativeClientLocations != null && !nativeClientLocations.isEmpty()) {
settings.setClientHome(nativeClientLocations.get(0));
} else {
settings.setClientHome(null);
}
if (settings.getClientHome() == null) {
currentPage.setErrorMessage(TaskNativeUIMessages.tools_wizard_message_no_client_home);
getContainer().updateMessage();
return;
}
} else {
DBPNativeClientLocation clientHome = DBUtils.findObject(nativeClientLocations, clientHomeId);
if (clientHome == null) {
clientHome = getSettings().findNativeClientHome(clientHomeId);
}
if (clientHome == null) {
// Make local client home from location
clientHome = new LocalNativeClientLocation(clientHomeId, clientHomeId);
}
settings.setClientHome(clientHome);
}
if (settings.getClientHome() == null) {
currentPage.setErrorMessage(NLS.bind(TaskNativeUIMessages.tools_wizard_message_client_home_not_found, clientHomeId));
} else {
currentPage.setErrorMessage(null);
}
getContainer().updateMessage();
}
}
Aggregations