use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by dbeaver.
the class DriverDependencies method resolveDependencies.
@Override
public void resolveDependencies(DBRProgressMonitor monitor) throws DBException {
IOException lastError = null;
{
rootNodes.clear();
final Map<String, DependencyNode> libMap = new LinkedHashMap<>();
for (DBPDriverLibrary library : rootLibraries) {
DependencyNode node = new DependencyNode(null, library);
try {
final Map<String, DependencyNode> localLibMap = new LinkedHashMap<>();
localLibMap.put(node.library.getId(), node);
resolveDependencies(monitor, node, localLibMap);
rootNodes.add(node);
libMap.putAll(localLibMap);
} catch (IOException e) {
lastError = e;
log.error("Error resolving library '" + library.getDisplayName() + "' dependencies", e);
}
}
libraryList.clear();
libraryList.addAll(libMap.values());
/*
StringBuilder sb = new StringBuilder();
Set<String> ns = new TreeSet<>();
for (String lib : libMap.keySet()) {
String newName = lib.replaceAll(".+\\:", "");
if (ns.contains(newName)) {
//System.out.println(123);
}
ns.add(newName);
}
for (String lib : ns) {
sb.append(lib).append("\n");
}
System.out.println(sb.toString());
System.out.println("---------------------------");
for (DependencyNode node : rootNodes) {
dumpNode(node, 0);
}
*/
}
if (lastError != null) {
throw new DBException("Error resolving dependencies", lastError);
}
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverDependenciesTree method resolveLibraries.
public boolean resolveLibraries() {
boolean resolved = false;
try {
runnableContext.run(true, true, monitor -> {
monitor.beginTask("Resolve dependencies", 100);
try {
dependencies.resolveDependencies(monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
});
resolved = true;
} catch (InterruptedException e) {
// User just canceled download
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Resolve libraries", "Error resolving driver libraries", e.getTargetException());
}
filesTree.removeAll();
int totalItems = 1;
for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) {
DBPDriverLibrary library = node.library;
TreeItem item = new TreeItem(filesTree, SWT.NONE);
item.setData(node);
item.setImage(DBeaverIcons.getImage(library.getIcon()));
item.setText(0, library.getDisplayName());
item.setText(1, CommonUtils.notEmpty(library.getVersion()));
item.setText(2, CommonUtils.notEmpty(library.getDescription()));
if (editable) {
item.setFont(1, boldFont);
}
totalItems++;
if (addDependencies(item, node)) {
item.setExpanded(true);
totalItems += item.getItemCount();
}
}
UIUtils.packColumns(filesTree);
// Check missing files
int missingFiles = 0;
for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryList()) {
File localFile = node.library.getLocalFile();
if (localFile == null || !localFile.exists()) {
missingFiles++;
}
}
if (missingFiles == 0) {
// UIUtils.showMessageBox(getShell(), "Driver Download", "All driver files are present", SWT.ICON_INFORMATION);
// ((DriverDownloadDialog)getWizard().getContainer()).closeWizard();
}
return resolved;
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverEditDialog method createLibrariesTab.
private void createLibrariesTab(TabFolder group) {
GridData gd;
Composite libsGroup = new Composite(group, SWT.NONE);
libsGroup.setLayout(new GridLayout(2, false));
{
Composite libsListGroup = new Composite(libsGroup, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
libsListGroup.setLayoutData(gd);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
libsListGroup.setLayout(layout);
// Additional libraries list
libTable = new TreeViewer(libsListGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
libTable.setContentProvider(new LibContentProvider());
libTable.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
final Object element = cell.getElement();
if (element instanceof DBPDriverLibrary) {
DBPDriverLibrary lib = (DBPDriverLibrary) element;
String displayName = lib.getDisplayName();
if (lib.getPreferredVersion() != null) {
displayName += " [" + lib.getPreferredVersion() + "]";
}
cell.setText(displayName);
File localFile = lib.getLocalFile();
if (localFile != null && !localFile.exists()) {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
} else if (!driver.isLibraryResolved(lib)) {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
} else {
cell.setForeground(null);
}
cell.setImage(DBeaverIcons.getImage(lib.getIcon()));
} else {
cell.setText(element.toString());
if (element instanceof DriverDescriptor.DriverFileInfo) {
if (((DriverDescriptor.DriverFileInfo) element).getType() == DBPDriverLibrary.FileType.license) {
cell.setImage(DBeaverIcons.getImage(DBIcon.TYPE_TEXT));
} else {
cell.setImage(DBeaverIcons.getImage(DBIcon.JAR));
}
} else {
cell.setImage(DBeaverIcons.getImage(DBIcon.JAR));
}
}
}
@Override
public String getToolTipText(Object element) {
if (element instanceof DBPDriverLibrary) {
File localFile = ((DBPDriverLibrary) element).getLocalFile();
return localFile == null ? "N/A" : localFile.getAbsolutePath();
}
return super.getToolTipText(element);
}
});
ColumnViewerToolTipSupport.enableFor(libTable);
libTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
libTable.getControl().addListener(SWT.Selection, event -> changeLibSelection());
libTable.addDoubleClickListener(event -> {
if (getSelectedLibrary() instanceof DriverLibraryMavenArtifact) {
editMavenArtifact();
}
});
// Find driver class
boolean isReadOnly = !provider.isDriversManagable();
Composite findClassGroup = new Composite(libsListGroup, SWT.TOP);
findClassGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
layout = new GridLayout(3, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
findClassGroup.setLayout(layout);
UIUtils.createControlLabel(findClassGroup, UIConnectionMessages.dialog_edit_driver_label_driver_class);
classListCombo = new Combo(findClassGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
classListCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
classListCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selIndex = classListCombo.getSelectionIndex();
if (selIndex >= 0) {
driverClassText.setText(classListCombo.getItem(selIndex));
}
}
});
classListCombo.setEnabled(!isReadOnly);
findClassButton = new Button(findClassGroup, SWT.PUSH);
findClassButton.setText(UIConnectionMessages.dialog_edit_driver_button_bind_class);
findClassButton.addListener(SWT.Selection, event -> {
try {
DriverClassFindJob classFinder = new DriverClassFindJob(driver, java.sql.Driver.class.getName(), true);
UIUtils.runInProgressDialog(classFinder);
if (classListCombo != null && !classListCombo.isDisposed()) {
List<String> classNames = classFinder.getDriverClassNames();
classListCombo.setItems(classNames.toArray(new String[classNames.size()]));
classListCombo.setListVisible(true);
}
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
}
});
findClassButton.setEnabled(!isReadOnly);
}
Composite libsControlGroup = new Composite(libsGroup, SWT.TOP);
libsControlGroup.setLayout(new GridLayout(1, true));
libsControlGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_add_file, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addLibraryFiles();
}
});
UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_add_folder, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addLibraryFolder();
}
});
UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_add_artifact, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addMavenArtifact();
}
});
updateVersionButton = UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_update_version, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
driver.updateFiles();
changeLibContent();
}
});
detailsButton = UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_details, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new DriverLibraryDetailsDialog(getShell(), driver, getSelectedLibrary()).open();
}
});
detailsButton.setEnabled(false);
deleteButton = UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_delete, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) libTable.getSelection();
if (selection != null && !selection.isEmpty()) {
if (UIUtils.confirmAction(getShell(), UIConnectionMessages.dialog_edit_driver_dialog_delete_library_title, UIConnectionMessages.dialog_edit_driver_dialog_delete_library_message)) {
for (Object obj : selection.toArray()) {
if (obj instanceof DriverLibraryAbstract) {
driver.removeDriverLibrary((DriverLibraryAbstract) obj);
}
}
}
}
changeLibContent();
}
});
deleteButton.setEnabled(false);
UIUtils.createHorizontalLine(libsControlGroup);
UIUtils.createToolButton(libsControlGroup, UIConnectionMessages.dialog_edit_driver_button_classpath, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ViewClasspathDialog cpDialog = new ViewClasspathDialog(getShell());
cpDialog.open();
}
});
changeLibContent();
TabItem libsTab = new TabItem(group, SWT.NONE);
libsTab.setText(UIConnectionMessages.dialog_edit_driver_tab_name_driver_libraries);
libsTab.setToolTipText(UIConnectionMessages.dialog_edit_driver_tab_tooltip_driver_libraries);
libsTab.setControl(libsGroup);
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverDownloadAutoPage method createControl.
@Override
public void createControl(Composite parent) {
final DriverDownloadWizard wizard = getWizard();
final DBPDriver driver = wizard.getDriver();
setMessage(NLS.bind(UIConnectionMessages.dialog_driver_download_auto_page_download_specific_driver_files, driver.getFullName()));
initializeDialogUnits(parent);
Composite composite = UIUtils.createPlaceholder(parent, 1);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
if (!wizard.isForceDownload()) {
Composite infoGroup = UIUtils.createPlaceholder(composite, 2, 5);
infoGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label infoText = new Label(infoGroup, SWT.NONE);
infoText.setText(NLS.bind(UIConnectionMessages.dialog_driver_download_auto_page_driver_file_missing_text, driver.getFullName()));
infoText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Button forceCheckbox = UIUtils.createCheckbox(infoGroup, UIConnectionMessages.dialog_driver_download_auto_page_force_download, wizard.isForceDownload());
forceCheckbox.setToolTipText(UIConnectionMessages.dialog_driver_download_auto_page_force_download_tooltip);
forceCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_BEGINNING));
forceCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
wizard.setForceDownload(forceCheckbox.getSelection());
}
});
}
{
Group filesGroup = UIUtils.createControlGroup(composite, UIConnectionMessages.dialog_driver_download_auto_page_required_files, 1, -1, -1);
filesGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
depsTree = new DriverDependenciesTree(filesGroup, new RunnableContextDelegate(getContainer()), getWizard().getDependencies(), driver, driver.getDriverLibraries(), true) {
protected void setLibraryVersion(final DBPDriverLibrary library, final String version) {
String curVersion = library.getVersion();
if (CommonUtils.equalObjects(curVersion, version)) {
return;
}
library.setPreferredVersion(version);
resolveLibraries();
}
};
new Label(filesGroup, SWT.NONE).setText(UIConnectionMessages.dialog_driver_download_auto_page_change_driver_version_text);
}
if (!wizard.isForceDownload()) {
Label infoText = new Label(composite, SWT.NONE);
infoText.setText(UIConnectionMessages.dialog_driver_download_auto_page_obtain_driver_files_text);
infoText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
createLinksPanel(composite);
setControl(composite);
}
use of org.jkiss.dbeaver.model.connection.DBPDriverLibrary in project dbeaver by serge-rider.
the class DriverEditDialog method resetLibraries.
private void resetLibraries(boolean original) {
// Set libraries
Collection<DBPDriverLibrary> newLibList = CommonUtils.copyList(original ? driver.getOrigFiles() : origLibList);
for (DBPDriverLibrary lib : newLibList) {
lib.setDisabled(false);
driver.addDriverLibrary(lib, true);
}
for (DBPDriverLibrary lib : CommonUtils.copyList(driver.getDriverLibraries())) {
if (!newLibList.contains(lib)) {
driver.removeDriverLibrary(lib);
}
}
}
Aggregations