Search in sources :

Example 61 with DBPDataSourceContainer

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

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)

Example 62 with DBPDataSourceContainer

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

the class EditorUtils method setFileDataSource.

public static void setFileDataSource(@NotNull IFile file, @NotNull DatabaseEditorContext context) {
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
    if (projectMeta == null) {
        return;
    }
    DBPDataSourceContainer dataSourceContainer = context.getDataSourceContainer();
    String dataSourceId = dataSourceContainer == null ? null : dataSourceContainer.getId();
    projectMeta.setResourceProperty(file, PROP_SQL_DATA_SOURCE_ID, dataSourceId);
    if (!isDefaultContextSettings(context)) {
        projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE, dataSourceId);
        String catalogName = getDefaultCatalogName(context);
        if (catalogName != null)
            projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG, catalogName);
        String schemaName = getDefaultSchemaName(context);
        if (catalogName != null || schemaName != null)
            projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA, schemaName);
    }
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 63 with DBPDataSourceContainer

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

the class EditorUtils method setFileDataSource.

public static void setFileDataSource(@NotNull File localFile, @NotNull DatabaseEditorContext context) {
    final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
    DBPDataSourceContainer dataSourceContainer = context.getDataSourceContainer();
    efManager.setFileProperty(localFile, PROP_SQL_PROJECT_ID, dataSourceContainer == null ? null : dataSourceContainer.getRegistry().getProject().getName());
    String dataSourceId = dataSourceContainer == null ? null : dataSourceContainer.getId();
    efManager.setFileProperty(localFile, PROP_SQL_DATA_SOURCE_ID, dataSourceId);
    if (!isDefaultContextSettings(context)) {
        efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE, dataSourceId);
        String catalogName = getDefaultCatalogName(context);
        if (catalogName != null)
            efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG, getDefaultCatalogName(context));
        String schemaName = getDefaultSchemaName(context);
        if (catalogName != null || schemaName != null)
            efManager.setFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA, getDefaultCatalogName(context));
    }
}
Also used : DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 64 with DBPDataSourceContainer

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

the class ScriptSelectorPanel method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    /*Rectangle bounds = new Rectangle(100, 100, 500, 200);
        final String boundsStr = getBoundsSettings().get(CONFIG_BOUNDS_PARAM);
        if (boundsStr != null && !boundsStr.isEmpty()) {
            final String[] bc = boundsStr.split(",");
            try {
                bounds = new Rectangle(
                    Integer.parseInt(bc[0]),
                    Integer.parseInt(bc[1]),
                    Integer.parseInt(bc[2]),
                    Integer.parseInt(bc[3]));
            } catch (NumberFormatException e) {
                log.warn(e);
            }
        }*/
    patternText = new Text(composite, SWT.BORDER);
    patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    UIUtils.addEmptyTextHint(patternText, text -> "Enter a part of script name here");
    // patternText.setForeground(fg);
    // patternText.setBackground(bg);
    patternText.addModifyListener(e -> {
        if (filterJob != null) {
            return;
        }
        filterJob = new FilterJob();
        filterJob.schedule(250);
    });
    // parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
    final Color fg = patternText.getForeground();
    // parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
    final Color bg = patternText.getBackground();
    composite.setForeground(fg);
    composite.setBackground(bg);
    Button newButton = new Button(composite, SWT.PUSH | SWT.FLAT);
    newButton.setText("&New Script");
    newButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IFile scriptFile;
            try {
                scriptFile = SQLEditorUtils.createNewScript(DBWorkbench.getPlatform().getWorkspace().getProject(rootFolder.getProject()), rootFolder, navigatorContext);
                SQLEditorHandlerOpenEditor.openResource(scriptFile, navigatorContext);
            } catch (CoreException ex) {
                log.error(ex);
            }
            cancelPressed();
        }
    });
    ((GridData) UIUtils.createHorizontalLine(composite).getLayoutData()).horizontalSpan = 2;
    Tree scriptTree = new Tree(composite, SWT.SINGLE | SWT.FULL_SELECTION);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    gd.widthHint = 500;
    gd.heightHint = 200;
    scriptTree.setLayoutData(gd);
    scriptTree.setForeground(fg);
    scriptTree.setBackground(bg);
    scriptTree.setLinesVisible(true);
    // scriptViewer.setHeaderVisible(true);
    this.scriptViewer = new TreeViewer(scriptTree);
    ColumnViewerToolTipSupport.enableFor(this.scriptViewer);
    // scriptTree.setS
    this.scriptViewer.setContentProvider(new TreeContentProvider() {

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof ResourceInfo) {
                final List<ResourceInfo> children = ((ResourceInfo) parentElement).getChildren();
                return CommonUtils.isEmpty(children) ? null : children.toArray();
            }
            return null;
        }

        @Override
        public boolean hasChildren(Object element) {
            if (element instanceof ResourceInfo) {
                final List<ResourceInfo> children = ((ResourceInfo) element).getChildren();
                return !CommonUtils.isEmpty(children);
            }
            return false;
        }
    });
    ViewerColumnController columnController = new ViewerColumnController("scriptSelectorViewer", scriptViewer);
    columnController.addColumn("Script", "Resource name", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            final ResourceInfo ri = (ResourceInfo) element;
            if (!ri.isDirectory()) {
                if (ri.getDataSource() == null) {
                    return DBeaverIcons.getImage(UIIcon.SQL_SCRIPT);
                } else {
                    return DBeaverIcons.getImage(ri.getDataSource().getDriver().getIcon());
                }
            } else {
                return DBeaverIcons.getImage(DBIcon.TREE_FOLDER);
            }
        }

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

        @Override
        public String getToolTipText(Object element) {
            final DBPDataSourceContainer dataSource = ((ResourceInfo) element).getDataSource();
            return dataSource == null ? null : dataSource.getName();
        }

        @Override
        public Image getToolTipImage(Object element) {
            final DBPDataSourceContainer dataSource = ((ResourceInfo) element).getDataSource();
            return dataSource == null ? null : DBeaverIcons.getImage(dataSource.getDriver().getIcon());
        }
    });
    columnController.addColumn("Time", "Modification time", SWT.LEFT, true, true, new ColumnLabelProvider() {

        private SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_TIMESTAMP_FORMAT);

        @Override
        public String getText(Object element) {
            final File localFile = ((ResourceInfo) element).getLocalFile();
            if (localFile.isDirectory()) {
                return null;
            } else {
                return sdf.format(new Date(localFile.lastModified()));
            }
        }
    });
    columnController.addColumn("Info", "Script preview", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            // ((ResourceInfo)element).getDescription();
            return "";
        }

        @Override
        public Color getForeground(Object element) {
            return getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
        }

        @Override
        public String getToolTipText(Object element) {
            final ResourceInfo ri = (ResourceInfo) element;
            String description = ri.getDescription();
            return description == null ? null : description.trim();
        }
    });
    columnController.createColumns();
    columnController.sortByColumn(1, SWT.UP);
    scriptTree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            List<ResourceInfo> files = new ArrayList<>();
            for (Object item : ((IStructuredSelection) scriptViewer.getSelection()).toArray()) {
                if (!((ResourceInfo) item).isDirectory()) {
                    files.add((ResourceInfo) item);
                }
            }
            if (files.isEmpty()) {
                return;
            }
            cancelPressed();
            for (ResourceInfo ri : files) {
                SQLEditorHandlerOpenEditor.openResourceEditor(ScriptSelectorPanel.this.workbenchWindow, ri, navigatorContext);
            }
        }
    });
    scriptTree.addListener(SWT.PaintItem, event -> {
        final TreeItem item = (TreeItem) event.item;
        final ResourceInfo ri = (ResourceInfo) item.getData();
        if (ri != null && !ri.isDirectory() && CommonUtils.isEmpty(item.getText(2))) {
            UIUtils.asyncExec(() -> {
                if (!item.isDisposed()) {
                    item.setText(2, CommonUtils.getSingleLineString(CommonUtils.notEmpty(ri.getDescription())));
                }
            });
        }
    });
    this.patternText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final Tree tree = scriptViewer.getTree();
            if (e.keyCode == SWT.ARROW_DOWN) {
                // scriptViewer.get
                scriptViewer.setSelection(new StructuredSelection(tree.getItem(0).getData()));
                tree.setFocus();
            } else if (e.keyCode == SWT.ARROW_UP) {
                scriptViewer.setSelection(new StructuredSelection(tree.getItem(tree.getItemCount() - 1).getData()));
                tree.setFocus();
            }
        }
    });
    closeOnFocusLost(patternText, scriptViewer.getTree(), newButton);
    scriptViewer.setInput(scriptFiles);
    UIUtils.expandAll(scriptViewer);
    final Tree tree = scriptViewer.getTree();
    final TreeColumn[] columns = tree.getColumns();
    columns[0].pack();
    columns[0].setWidth(columns[0].getWidth() + 10);
    columns[1].pack();
    columns[2].setWidth(200 * 8);
    UIUtils.asyncExec(scriptTree::setFocus);
    return composite;
}
Also used : IFile(org.eclipse.core.resources.IFile) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) ResourceInfo(org.jkiss.dbeaver.ui.editors.sql.SQLEditorUtils.ResourceInfo) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Date(java.util.Date) CoreException(org.eclipse.core.runtime.CoreException) GridData(org.eclipse.swt.layout.GridData) SimpleDateFormat(java.text.SimpleDateFormat) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 65 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class SQLScriptTaskPageSettings method updateSelectedScripts.

private void updateSelectedScripts() {
    DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
    Set<DBPDataSourceContainer> dataSources = new LinkedHashSet<>();
    for (DBNResource element : selectedScripts) {
        Collection<DBPDataSourceContainer> resDS = element.getAssociatedDataSources();
        if (!CommonUtils.isEmpty(resDS)) {
            dataSources.addAll(resDS);
        }
    }
    if (!dataSources.isEmpty()) {
        List<DBNDataSource> checkedDataSources = new ArrayList<>();
        for (DBPDataSourceContainer ds : dataSources) {
            DBNDataSource dsNode = projectNode.getDatabases().getDataSource(ds);
            if (dsNode != null) {
                checkedDataSources.add(dsNode);
            }
        }
        if (!checkedDataSources.isEmpty()) {
            refreshDataSources();
            for (DBNDataSource dsNode : checkedDataSources) {
                if (!selectedDataSources.contains(dsNode)) {
                    selectedDataSources.add(dsNode);
                }
            }
        }
    }
    refreshDataSources();
    updatePageCompletion();
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

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