Search in sources :

Example 71 with DBPDataSourceContainer

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);
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) GridLayout(org.eclipse.swt.layout.GridLayout) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 72 with DBPDataSourceContainer

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;
}
Also used : DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 73 with DBPDataSourceContainer

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);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 74 with DBPDataSourceContainer

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IViewPart(org.eclipse.ui.IViewPart) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) BookmarkStorage(org.jkiss.dbeaver.ui.resources.bookmarks.BookmarkStorage) PartInitException(org.eclipse.ui.PartInitException) DBNBookmark(org.jkiss.dbeaver.ui.resources.bookmarks.DBNBookmark) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 75 with DBPDataSourceContainer

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)));
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) DataSourceNavigatorSettings(org.jkiss.dbeaver.registry.DataSourceNavigatorSettings) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) Separator(org.eclipse.jface.action.Separator)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)230 DBException (org.jkiss.dbeaver.DBException)32 ArrayList (java.util.ArrayList)31 IFile (org.eclipse.core.resources.IFile)30 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)27 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)27 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)22 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)19 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)19 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)18 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)18 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 GridData (org.eclipse.swt.layout.GridData)16 IEditorPart (org.eclipse.ui.IEditorPart)16 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)16 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13