Search in sources :

Example 36 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DatabaseDebugConfigurationTab method loadConnectionDebugTypes.

private void loadConnectionDebugTypes() {
    for (Control c : typesGroup.getChildren()) {
        c.dispose();
    }
    DBPDataSourceContainer dataSource = connectionCombo.getSelectedItem();
    if (dataSource == null) {
        UIUtils.createInfoLabel(typesGroup, "Select a connection to see available debug types");
    } else {
        List<DebugConfigurationPanelDescriptor> panels = DebugConfigurationPanelRegistry.getInstance().getPanels(dataSource);
        if (CommonUtils.isEmpty(panels)) {
            UIUtils.createInfoLabel(typesGroup, "Driver '" + dataSource.getDriver().getFullName() + "' doesn't support debugging");
        } else {
            for (DebugConfigurationPanelDescriptor panel : panels) {
                Button typeSelector = new Button(typesGroup, SWT.RADIO);
                typeSelector.setText(panel.getName());
                if (!CommonUtils.isEmpty(panel.getDescription())) {
                    typeSelector.setToolTipText(panel.getDescription());
                }
                typeSelector.setData(panel);
                if (panel.isValid()) {
                    typeSelector.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            if (typeSelector.getSelection()) {
                                setDirty(true);
                                setDebugType(connectionCombo.getSelectedItem(), (DebugConfigurationPanelDescriptor) typeSelector.getData());
                                typesGroup.getParent().layout(true, true);
                            }
                        }
                    });
                } else {
                    typeSelector.setEnabled(false);
                }
            }
        }
    }
    setDebugType(dataSource, null);
    typesGroup.getParent().layout(true, true);
}
Also used : DebugConfigurationPanelDescriptor(org.jkiss.dbeaver.debug.ui.internal.DebugConfigurationPanelDescriptor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 37 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DatabaseDebugConfigurationTab method createConnectionSettingsGroup.

protected void createConnectionSettingsGroup(Composite composite) {
    Group group = UIUtils.createControlGroup(composite, DebugUIMessages.DatabaseTab_connection_group_text, 4, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
    UIUtils.createControlLabel(group, DebugUIMessages.DatabaseTab_datasource_label_text);
    connectionCombo = new SelectDataSourceCombo(group) {

        @Override
        protected void onDataSourceChange(DBPDataSourceContainer dataSource) {
            String driverName = dataSource == null ? "" : dataSource.getDriver().getFullName();
            driverText.setText(driverName);
            setDirty(true);
            loadConnectionDebugTypes();
            updateLaunchConfigurationDialog();
        }
    };
    connectionCombo.addItem(null);
    for (DBPDataSourceContainer ds : DataSourceRegistry.getAllDataSources()) {
        connectionCombo.addItem(ds);
    }
    driverText = UIUtils.createLabelText(group, DebugUIMessages.DatabaseTab_driver_label_text, "", SWT.READ_ONLY);
}
Also used : SelectDataSourceCombo(org.jkiss.dbeaver.ui.controls.SelectDataSourceCombo) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 38 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DatabaseDebugConfigurationTab method initializeFrom.

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
    this.currentConfiguration = configuration;
    try {
        DBPDataSourceContainer dataSource = null;
        try {
            dataSource = DebugUtils.getDataSourceContainer(configuration);
        } catch (CoreException e) {
            log.debug(e);
        }
        connectionCombo.select(dataSource);
        if (dataSource != null) {
            driverText.setText(dataSource.getDriver().getFullName());
        } else {
            driverText.setText("");
        }
        loadConnectionDebugTypes();
        String typeId = configuration.getAttribute(DBGConstants.ATTR_DEBUG_TYPE, (String) null);
        DebugConfigurationPanelDescriptor savedPanel = null;
        if (typeId != null) {
            savedPanel = DebugConfigurationPanelRegistry.getInstance().getPanel(typeId);
            if (savedPanel == null) {
                setWarningMessage("Debug type '" + typeId + "' cannot be resolved");
            }
        }
        setDebugType(dataSource, savedPanel);
    } catch (CoreException e) {
        setWarningMessage("Error loading debug configuration: " + e.getMessage());
    }
    scheduleUpdateJob();
}
Also used : DebugConfigurationPanelDescriptor(org.jkiss.dbeaver.debug.ui.internal.DebugConfigurationPanelDescriptor) CoreException(org.eclipse.core.runtime.CoreException) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 39 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class SelectActiveSchemaHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    if ("true".equals(parameters.get("noCustomLabel"))) {
        return;
    }
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    String schemaName = "< N/A >";
    DBIcon schemaIcon = DBIcon.TREE_SCHEMA;
    String schemaTooltip = UINavigatorMessages.toolbar_datasource_selector_combo_database_tooltip;
    DBPDataSourceContainer dataSource = DataSourceToolbarUtils.getCurrentDataSource(workbenchWindow);
    if (dataSource != null && dataSource.isConnected()) {
        // schemaName = "<no schema>";
        IEditorInput editorInput = activeEditor.getEditorInput();
        if (editorInput instanceof IDatabaseEditorInput) {
            if (editorInput instanceof DatabaseLazyEditorInput) {
                activeEditor.addPropertyListener(new IPropertyListener() {

                    @Override
                    public void propertyChanged(Object source, int propId) {
                        if (EntityEditor.PROP_TITLE == propId) {
                            DataSourceToolbarUtils.updateCommandsUI();
                            activeEditor.removePropertyListener(this);
                        }
                    }
                });
            }
            DBCExecutionContext executionContext = ((IDatabaseEditorInput) editorInput).getExecutionContext();
            if (executionContext != null) {
                DBSObject schemaObject = DBUtils.getSelectedObject(executionContext);
                if (schemaObject != null && DBUtils.getPublicObjectContainer(schemaObject) != dataSource) {
                    DBSObject schemaParent = schemaObject.getParentObject();
                    if (schemaParent instanceof DBSObjectContainer && !(schemaParent instanceof DBPDataSource)) {
                        schemaName = schemaObject.getName() + "@" + schemaParent.getName();
                    } else {
                        schemaName = schemaObject.getName();
                    }
                }
            }
        } else {
            DBCExecutionContext executionContext = getExecutionContextFromPart(activeEditor);
            DBCExecutionContextDefaults contextDefaults = null;
            if (executionContext != null) {
                contextDefaults = executionContext.getContextDefaults();
            }
            if (contextDefaults != null) {
                DBSCatalog defaultCatalog = contextDefaults.getDefaultCatalog();
                DBSSchema defaultSchema = contextDefaults.getDefaultSchema();
                if (defaultCatalog != null && (defaultSchema != null || contextDefaults.supportsSchemaChange())) {
                    schemaName = defaultSchema == null ? "?" : defaultSchema.getName() + "@" + defaultCatalog.getName();
                    schemaIcon = DBIcon.TREE_SCHEMA;
                } else if (defaultCatalog != null) {
                    schemaName = defaultCatalog.getName();
                    schemaIcon = DBIcon.TREE_DATABASE;
                } else if (defaultSchema != null) {
                    schemaName = defaultSchema.getName();
                    schemaIcon = DBIcon.TREE_SCHEMA;
                }
            }
        }
    }
    element.setText(schemaName);
    element.setIcon(DBeaverIcons.getImageDescriptor(schemaIcon));
    element.setTooltip(schemaTooltip);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DatabaseLazyEditorInput(org.jkiss.dbeaver.ui.editors.DatabaseLazyEditorInput) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) IPropertyListener(org.eclipse.ui.IPropertyListener) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IEditorInput(org.eclipse.ui.IEditorInput)

Example 40 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class SQLScriptTaskDataSourceSelectorDialog method createScriptColumns.

static void createScriptColumns(ColumnViewer viewer) {
    final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
    ViewerColumnController columnController = new ViewerColumnController("sqlTaskScriptViewer", viewer);
    columnController.setForceAutoSize(true);
    columnController.addColumn(ModelMessages.model_navigator_Name, DTUIMessages.sql_script_task_data_source_selection_dialog_column_description_script, SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return mainLabelProvider.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            return mainLabelProvider.getImage(element);
        }

        @Override
        public String getToolTipText(Object element) {
            if (mainLabelProvider instanceof IToolTipProvider) {
                return ((IToolTipProvider) mainLabelProvider).getToolTipText(element);
            }
            return null;
        }
    });
    columnController.addColumn(ModelMessages.model_navigator_Connection, DTUIMessages.sql_script_task_data_source_selection_dialog_column_description_script_data_source, SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DBNResource) {
                Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
                if (!CommonUtils.isEmpty(containers)) {
                    StringBuilder text = new StringBuilder();
                    for (DBPDataSourceContainer container : containers) {
                        if (text.length() > 0) {
                            text.append(", ");
                        }
                        text.append(container.getName());
                    }
                    return text.toString();
                }
            }
            return "";
        }

        @Override
        public Image getImage(Object element) {
            return null;
        }
    });
    columnController.createColumns(true);
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) IToolTipProvider(org.eclipse.jface.viewers.IToolTipProvider) Collection(java.util.Collection) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Image(org.eclipse.swt.graphics.Image) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)148 IFile (org.eclipse.core.resources.IFile)22 ArrayList (java.util.ArrayList)21 DBException (org.jkiss.dbeaver.DBException)19 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)19 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)19 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)14 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)13 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)12 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 IFolder (org.eclipse.core.resources.IFolder)11 IEditorPart (org.eclipse.ui.IEditorPart)11 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 GridData (org.eclipse.swt.layout.GridData)9 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)9