use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class ConnectionPageNetworkHandler method createControl.
@Override
public void createControl(Composite parent) {
try {
String implName = handlerDescriptor.getHandlerType().getImplName();
UIPropertyConfiguratorDescriptor configDescriptor = UIPropertyConfiguratorRegistry.getInstance().getDescriptor(implName);
if (configDescriptor == null) {
return;
}
configurator = configDescriptor.createConfigurator();
} catch (DBException e) {
log.error("Can't create network configurator '" + handlerDescriptor.getId() + "'", e);
return;
}
DBPDataSourceContainer dataSource = site.getActiveDataSource();
DBPConnectionConfiguration connectionConfiguration = dataSource.getConnectionConfiguration();
handlerConfiguration = connectionConfiguration.getHandler(handlerDescriptor.getId());
if (handlerConfiguration == null) {
handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
connectionConfiguration.updateHandler(handlerConfiguration);
}
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite buttonsGroup = UIUtils.createComposite(composite, 5);
buttonsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
useHandlerCheck = UIUtils.createCheckbox(buttonsGroup, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, handlerDescriptor.getLabel()), false);
useHandlerCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
enableHandlerContent();
}
});
UIUtils.createEmptyLabel(buttonsGroup, 1, 1).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
profileCombo = UIUtils.createLabelCombo(buttonsGroup, "Profile", SWT.READ_ONLY | SWT.DROP_DOWN);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = 200;
profileCombo.setLayoutData(gd);
profileCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setConnectionConfigProfile(profileCombo.getText());
}
});
ToolBar editToolbar = new ToolBar(buttonsGroup, SWT.HORIZONTAL);
ToolItem editItem = new ToolItem(editToolbar, SWT.PUSH);
editItem.setImage(DBeaverIcons.getImage(UIIcon.EDIT));
editItem.setToolTipText("Edit profiles");
editItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PreferenceDialog preferenceDialog = PreferencesUtil.createPropertyDialogOn(getShell(), site.getProject().getEclipseProject(), PrefPageProjectNetworkProfiles.PAGE_ID, null, null);
if (preferenceDialog != null) {
if (preferenceDialog.open() == IDialogConstants.OK_ID) {
setConnectionConfigProfile(profileCombo.getText());
}
}
}
});
handlerComposite = UIUtils.createComposite(composite, 1);
handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
configurator.createControl(handlerComposite, this::updatePageCompletion);
configurator.loadSettings(handlerConfiguration);
useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
enableHandlerContent();
updateProfileList();
if (activeProfile != null) {
DBWHandlerConfiguration profileConfig = activeProfile.getConfiguration(handlerDescriptor);
if (profileConfig != null) {
configurator.loadSettings(profileConfig);
}
}
setControl(composite);
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class ConnectionPageInitialization method loadDatabaseSettings.
private void loadDatabaseSettings(DBRProgressMonitor monitor, DBPDataSource dataSource) {
DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
Collection<DBPTransactionIsolation> txnLevels = CommonUtils.safeCollection(dataSource.getInfo().getSupportedTransactionsIsolation());
Integer levelCode = dataSourceContainer.getDefaultTransactionsIsolation();
UIUtils.syncExec(() -> {
autocommit.setSelection(dataSourceContainer.isDefaultAutoCommit());
// isolationLevel.setEnabled(!autocommit.getSelection());
supportedLevels.clear();
DBPTransactionIsolation defaultLevel = null;
{
if (levelCode != null && !CommonUtils.isEmpty(txnLevels)) {
for (DBPTransactionIsolation level : txnLevels) {
if (level.getCode() == levelCode) {
defaultLevel = level;
break;
}
}
}
}
isolationLevel.removeAll();
supportedLevels.clear();
for (DBPTransactionIsolation level : txnLevels) {
if (!level.isEnabled()) {
continue;
}
isolationLevel.add(level.getTitle());
supportedLevels.add(level);
if (level.equals(defaultLevel)) {
isolationLevel.select(isolationLevel.getItemCount() - 1);
}
}
});
if (dataSource instanceof DBSObjectContainer) {
DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
DBSObjectContainer catalogContainer = DBUtils.getChangeableObjectContainer(contextDefaults, (DBSObjectContainer) dataSource, DBSCatalog.class);
if (catalogContainer != null) {
loadSelectableObject(monitor, catalogContainer, defaultCatalog, contextDefaults, true);
}
DBSObjectContainer schemaContainer = DBUtils.getChangeableObjectContainer(contextDefaults, (DBSObjectContainer) dataSource, DBSSchema.class);
loadSelectableObject(monitor, schemaContainer, defaultSchema, contextDefaults, false);
}
txnOptionsLoaded = true;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class DataSourceAutoCommitHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
boolean autoCommit = true;
DBPTransactionIsolation isolation = null;
DBCExecutionContext context = getExecutionContextFromPart(activeEditor);
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
// Change auto-commit mode
autoCommit = txnManager.isAutoCommit();
isolation = txnManager.getTransactionIsolation();
} catch (DBCException e) {
log.warn(e);
}
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
if (container != null) {
autoCommit = container.isDefaultAutoCommit();
isolation = container.getActiveTransactionsIsolation();
}
}
element.setChecked(autoCommit);
// Update command image
element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
String isolationName = isolation == null ? "?" : isolation.getTitle();
String text = autoCommit ? NLS.bind(CoreMessages.action_menu_transaction_manualcommit_name, isolationName) : CoreMessages.action_menu_transaction_autocommit_name;
element.setText(text);
element.setTooltip(text);
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class NavigateBookmarkHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
NavigatorViewBase activeNavigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (activeNavigatorView != null) {
DBNNode selectedNode = NavigatorUtils.getSelectedNode(HandlerUtil.getCurrentSelection(event));
if (selectedNode instanceof DBNBookmark) {
BookmarkStorage storage = ((DBNBookmark) selectedNode).getStorage();
final DBPDataSourceContainer dataSourceContainer = DBUtils.findDataSource(storage.getDataSourceId());
if (dataSourceContainer == null) {
// $NON-NLS-2$
log.debug("Can't find datasource '" + storage.getDataSourceId() + "'");
return null;
}
final DBNDataSource dsNode = (DBNDataSource) DBNUtils.getNodeByObject(dataSourceContainer);
if (dsNode == null) {
// $NON-NLS-2$
log.error("Can't find datasource node for '" + dataSourceContainer.getName() + "'");
return null;
}
if (activeNavigatorView instanceof ProjectExplorerView) {
// Show in DB navigator is we are currently in project explorer
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
IViewPart dbNavigatorPart = activePage.findView(DatabaseNavigatorView.VIEW_ID);
if (dbNavigatorPart instanceof NavigatorViewBase) {
activeNavigatorView = (NavigatorViewBase) dbNavigatorPart;
try {
activePage.showView(DatabaseNavigatorView.VIEW_ID);
} catch (PartInitException e) {
log.debug(e);
}
}
}
NavigatorViewBase navigatorView = activeNavigatorView;
try {
dsNode.initializeNode(null, status -> {
if (status.isOK()) {
UIUtils.syncExec(() -> BookmarksHandlerImpl.navigateNodeByPath(navigatorView, dsNode, storage));
}
});
} catch (DBException e) {
log.error(e);
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.
the class ConnectionViewSettingsContributor method fillContributionItems.
@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
DBPDataSourceContainer dsContainer = AbstractDataSourceHandler.getDataSourceContainerFromPart(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart());
if (dsContainer == null) {
return;
}
boolean presetChecked = false;
for (DataSourceNavigatorSettings.Preset preset : DataSourceNavigatorSettings.PRESETS.values()) {
if (preset == DataSourceNavigatorSettings.PRESET_CUSTOM) {
continue;
}
boolean checked = preset.getSettings().equals(dsContainer.getNavigatorSettings());
if (checked) {
presetChecked = checked;
}
menuItems.add(new ActionContributionItem(new UseSettingsPresetAction(dsContainer, preset, checked)));
}
menuItems.add(new ActionContributionItem(new UseSettingsCustomAction(dsContainer, !presetChecked)));
menuItems.add(new Separator());
menuItems.add(new ActionContributionItem(new ShowSystemObjectsAction(dsContainer)));
menuItems.add(new Separator());
menuItems.add(new ActionContributionItem(new ShowHostNameAction(dsContainer)));
menuItems.add(new ActionContributionItem(new ShowStatisticsAction(dsContainer)));
menuItems.add(new ActionContributionItem(new ShowStatusIconsAction(dsContainer)));
}
Aggregations