Search in sources :

Example 26 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class DataSourcePropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    try {
        // Get root datasource node (we don't want to
        while (receiver instanceof DBNDatabaseNode && !(receiver instanceof DBNDataSource)) {
            receiver = ((DBNDatabaseNode) receiver).getParentNode();
        }
        if (!(receiver instanceof DBPContextProvider)) {
            return false;
        }
        DBPContextProvider contextProvider = (DBPContextProvider) receiver;
        @Nullable DBCExecutionContext context = contextProvider.getExecutionContext();
        switch(property) {
            case PROP_CONNECTED:
                boolean isConnected;
                if (context != null) {
                    isConnected = context.getDataSource().getContainer().isConnected();
                } else if (receiver instanceof IDataSourceContainerProvider) {
                    DBPDataSourceContainer container = ((IDataSourceContainerProvider) receiver).getDataSourceContainer();
                    isConnected = container != null && container.isConnected();
                } else {
                    isConnected = false;
                }
                boolean checkConnected = Boolean.TRUE.equals(expectedValue);
                return checkConnected ? isConnected : !isConnected;
            case PROP_TRANSACTIONAL:
                {
                    if (context == null) {
                        return false;
                    }
                    if (!context.isConnected()) {
                        return Boolean.FALSE.equals(expectedValue);
                    }
                    DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
                    try {
                        return txnManager != null && Boolean.valueOf(!txnManager.isAutoCommit()).equals(expectedValue);
                    } catch (DBCException e) {
                        log.debug("Error checking auto-commit state", e);
                        return false;
                    }
                }
            case PROP_SUPPORTS_TRANSACTIONS:
                {
                    if (context == null || !context.isConnected()) {
                        return false;
                    }
                    DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
                    return txnManager != null && txnManager.isSupportsTransactions();
                }
            case PROP_TRANSACTION_ACTIVE:
                if (context != null && context.isConnected()) {
                    DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
                    return txnManager != null && !txnManager.isAutoCommit();
                // boolean active = QMUtils.isTransactionActive(context);
                // return Boolean.valueOf(active).equals(expectedValue);
                }
                return Boolean.FALSE.equals(expectedValue);
        }
        return false;
    } catch (Exception e) {
        log.debug("Error testing property " + property + ": " + e.getMessage());
        return false;
    }
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) Nullable(org.jkiss.code.Nullable)

Example 27 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class AddBookmarkHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        final DBNNode node = NavigatorUtils.getSelectedNode(selection);
        if (node instanceof DBNDataSource) {
            DBWorkbench.getPlatformUI().showError(CoreMessages.actions_navigator_bookmark_error_title, "Connection itself cannot be bookmarked. Choose some element under a connection element.");
            return null;
        }
        if (node instanceof DBNDatabaseNode) {
            try {
                AddBookmarkDialog dialog = new AddBookmarkDialog(activeShell, (DBNDatabaseNode) node);
                final String title = dialog.chooseName();
                if (title != null) {
                    BookmarksHandlerImpl.createBookmark((DBNDatabaseNode) node, title, dialog.getTargetFolder());
                }
            } catch (DBException e) {
                DBWorkbench.getPlatformUI().showError(CoreMessages.actions_navigator_bookmark_error_title, CoreMessages.actions_navigator_bookmark_error_message, e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Shell(org.eclipse.swt.widgets.Shell) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 28 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class SQLScriptTaskPageSettings method saveSettings.

public void saveSettings() {
    if (sqlWizard == null) {
        return;
    }
    SQLScriptExecuteSettings settings = sqlWizard.getSettings();
    List<String> scriptPaths = new ArrayList<>();
    for (DBNResource resource : selectedScripts) {
        IResource res = resource.getResource();
        if (res instanceof IFile) {
            scriptPaths.add(res.getFullPath().toString());
        }
    }
    settings.setScriptFiles(scriptPaths);
    List<DBPDataSourceContainer> dsList = new ArrayList<>();
    for (DBNDataSource dsNode : selectedDataSources) {
        dsList.add(dsNode.getDataSourceContainer());
    }
    settings.setDataSources(dsList);
    settings.setIgnoreErrors(ignoreErrorsCheck.getSelection());
    settings.setDumpQueryResultsToLog(dumpQueryCheck.getSelection());
    settings.setAutoCommit(autoCommitCheck.getSelection());
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IFile(org.eclipse.core.resources.IFile) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 29 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class SQLScriptTaskPageSettings method loadSettings.

public void loadSettings() {
    SQLScriptExecuteSettings settings = sqlWizard.getSettings();
    List<String> scriptFiles = settings.getScriptFiles();
    for (String filePath : scriptFiles) {
        IFile file = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
        if (file == null) {
            log.debug("Script file '" + filePath + "' not found");
            continue;
        }
        DBPProject currentProject = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
        if (currentProject == null) {
            log.debug("Project '" + file.getProject().getName() + "' not found");
            continue;
        }
        DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(currentProject);
        if (projectNode != null) {
            DBNResource resource = projectNode.findResource(file);
            if (resource != null) {
                selectedScripts.add(resource);
            }
        }
    }
    scriptsViewer.setInput(selectedScripts);
    for (DBPDataSourceContainer dataSource : settings.getDataSources()) {
        DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(dataSource.getProject());
        DBNDataSource dsNode = projectNode.getDatabases().getDataSource(dataSource);
        if (dsNode != null) {
            selectedDataSources.add(dsNode);
        }
    }
    dataSourceViewer.setInput(selectedDataSources);
// if (!selectedDataSources.isEmpty()) {
// dataSourceTree.getCheckboxViewer().setCheckedElements(selectedDataSources.toArray());
// dataSourceTree.getCheckboxViewer().reveal(selectedDataSources.get(0));
// }
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) IFile(org.eclipse.core.resources.IFile) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 30 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class DiagramCreateWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    Composite configGroup = UIUtils.createControlGroup(placeholder, ERDUIMessages.wizard_page_diagram_create_group_settings, 2, GridData.FILL_BOTH, 0);
    // $NON-NLS-1$
    final Text projectNameText = UIUtils.createLabelText(configGroup, "Name", null);
    projectNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            diagram.setName(projectNameText.getText());
            updateState();
        }
    });
    Label contentLabel = UIUtils.createControlLabel(configGroup, ERDUIMessages.wizard_page_diagram_create_label_init_content);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.horizontalSpan = 2;
    contentLabel.setLayoutData(gd);
    final DBNProject rootNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject());
    if (rootNode == null) {
        setControl(placeholder);
        return;
    }
    contentTree = new DatabaseNavigatorTree(configGroup, rootNode.getDatabases(), SWT.SINGLE | SWT.CHECK);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    gd.heightHint = 400;
    contentTree.setLayoutData(gd);
    CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
    viewer.setCheckStateProvider(new ICheckStateProvider() {

        @Override
        public boolean isChecked(Object element) {
            return false;
        }

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof DBNDatabaseNode && !(element instanceof DBNDataSource)) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBSTable) {
                    return false;
                }
            }
            return true;
        }
    });
    if (entitySelection != null) {
        viewer.setSelection(entitySelection, true);
        viewer.setCheckedElements(entitySelection.toArray());
    }
    setControl(placeholder);
}
Also used : DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)59 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)26 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)17 DBException (org.jkiss.dbeaver.DBException)15 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)13 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)12 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)10 ArrayList (java.util.ArrayList)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 DBNLocalFolder (org.jkiss.dbeaver.model.navigator.DBNLocalFolder)8 IFile (org.eclipse.core.resources.IFile)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)6 SQLScriptExecuteSettings (org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings)6 GridData (org.eclipse.swt.layout.GridData)5 IResource (org.eclipse.core.resources.IResource)4 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)4 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4