Search in sources :

Example 6 with UIServiceConnections

use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by serge-rider.

the class NavigatorViewBase method createNavigatorTree.

private DatabaseNavigatorTree createNavigatorTree(Composite parent, DBNNode rootNode) {
    // Create tree
    final DatabaseNavigatorTree navigatorTree = new DatabaseNavigatorTree(parent, rootNode, getTreeStyle(), false, getNavigatorFilter());
    createTreeColumns(navigatorTree);
    navigatorTree.getViewer().addSelectionChangedListener(event -> onSelectionChange((IStructuredSelection) event.getSelection()));
    navigatorTree.getViewer().getTree().addListener(SWT.MouseDoubleClick, event -> {
        event.doit = false;
    });
    navigatorTree.getViewer().getTree().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            super.mouseDoubleClick(e);
        }

        @Override
        public void mouseDown(MouseEvent e) {
            super.mouseDown(e);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            super.mouseUp(e);
        }
    });
    navigatorTree.getViewer().addDoubleClickListener(event -> {
        TreeViewer viewer = tree.getViewer();
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        for (Object node : selection.toArray()) {
            // Object node = selection.getFirstElement();
            if ((node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFolder)) {
                toggleNode(viewer, node);
            } else if (node instanceof DBNDataSource) {
                NavigatorPreferences.DoubleClickBehavior dsBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK), NavigatorPreferences.DoubleClickBehavior.EDIT);
                if (dsBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
                    toggleNode(viewer, node);
                } else {
                    DBPDataSourceContainer dataSource = ((DBNDataSource) node).getObject();
                    switch(dsBehaviorDefault) {
                        case EDIT:
                            NavigatorHandlerObjectOpen.openEntityEditor((DBNDataSource) node, null, UIUtils.getActiveWorkbenchWindow());
                            break;
                        case CONNECT:
                            {
                                UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
                                if (serviceConnections != null) {
                                    if (dataSource.isConnected()) {
                                        serviceConnections.disconnectDataSource(dataSource);
                                    } else {
                                        serviceConnections.connectDataSource(dataSource, null);
                                    }
                                }
                                break;
                            }
                        case SQL_EDITOR:
                            {
                                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                                if (serviceSQL != null) {
                                    serviceSQL.openRecentScript(dataSource);
                                }
                                break;
                            }
                        case SQL_EDITOR_NEW:
                            {
                                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                                if (serviceSQL != null) {
                                    serviceSQL.openNewScript(dataSource);
                                }
                                break;
                            }
                    }
                }
            } else if (node instanceof TreeNodeSpecial) {
                ((TreeNodeSpecial) node).handleDefaultAction(navigatorTree);
            } else {
                String defaultEditorPageId = null;
                NavigatorPreferences.DoubleClickBehavior dcBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK));
                if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
                    defaultEditorPageId = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE);
                }
                boolean hasChildren = node instanceof DBNNode && ((DBNNode) node).hasChildren(true);
                if (hasChildren && dcBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
                    toggleNode(viewer, node);
                } else {
                    Map<String, Object> parameters = null;
                    if (!CommonUtils.isEmpty(defaultEditorPageId)) {
                        parameters = Collections.singletonMap(MultiPageDatabaseEditor.PARAMETER_ACTIVE_PAGE, defaultEditorPageId);
                    }
                    NavigatorUtils.executeNodeAction(DBXTreeNodeHandler.Action.open, node, parameters, getSite());
                }
            }
        }
    });
    // Hook context menu
    NavigatorUtils.addContextMenu(this.getSite(), navigatorTree.getViewer());
    // Add drag and drop support
    NavigatorUtils.addDragAndDropSupport(navigatorTree.getViewer());
    DBWorkbench.getPlatform().getPreferenceStore().addPropertyChangeListener(this);
    return navigatorTree;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) NavigatorPreferences(org.jkiss.dbeaver.ui.navigator.NavigatorPreferences) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with UIServiceConnections

use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by serge-rider.

the class SQLEditor method checkConnected.

private boolean checkConnected(boolean forceConnect, DBRProgressListener onFinish) {
    // Connect to datasource
    final DBPDataSourceContainer dataSourceContainer = getDataSourceContainer();
    boolean doConnect = dataSourceContainer != null && (forceConnect || dataSourceContainer.getPreferenceStore().getBoolean(SQLPreferenceConstants.EDITOR_CONNECT_ON_ACTIVATE));
    if (doConnect) {
        if (!dataSourceContainer.isConnected()) {
            UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
            if (serviceConnections != null) {
                serviceConnections.connectDataSource(dataSourceContainer, onFinish);
            }
        }
    }
    return dataSourceContainer != null && dataSourceContainer.isConnected();
}
Also used : UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections)

Example 8 with UIServiceConnections

use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by dbeaver.

the class SQLEditor method checkConnected.

private boolean checkConnected(boolean forceConnect, DBRProgressListener onFinish) {
    // Connect to datasource
    final DBPDataSourceContainer dataSourceContainer = getDataSourceContainer();
    boolean doConnect = dataSourceContainer != null && (forceConnect || dataSourceContainer.getPreferenceStore().getBoolean(SQLPreferenceConstants.EDITOR_CONNECT_ON_ACTIVATE));
    if (doConnect) {
        if (!dataSourceContainer.isConnected()) {
            UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
            if (serviceConnections != null) {
                serviceConnections.connectDataSource(dataSourceContainer, onFinish);
            }
        }
    }
    return dataSourceContainer != null && dataSourceContainer.isConnected();
}
Also used : UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections)

Example 9 with UIServiceConnections

use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by dbeaver.

the class NNAHDataSourceTunnel method handleNodeAction.

@Override
public void handleNodeAction(INavigatorModelView view, DBNNode node, Event event, boolean defaultAction) {
    if (node instanceof DBNDatabaseNode) {
        DBPDataSourceContainer dataSourceContainer = ((DBNDatabaseNode) node).getDataSourceContainer();
        UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
        if (serviceConnections != null) {
            serviceConnections.openConnectionEditor(dataSourceContainer, "ConnectionPageNetworkHandler.ssh_tunnel");
        }
    }
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections)

Example 10 with UIServiceConnections

use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by dbeaver.

the class NNAHDataSourceReadOnly method handleNodeAction.

@Override
public void handleNodeAction(INavigatorModelView view, DBNNode node, Event event, boolean defaultAction) {
    if (node instanceof DBNDatabaseNode) {
        DBPDataSourceContainer dataSourceContainer = ((DBNDatabaseNode) node).getDataSourceContainer();
        UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
        if (serviceConnections != null) {
            serviceConnections.openConnectionEditor(dataSourceContainer, "ConnectionPageGeneral");
        }
    }
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections)

Aggregations

UIServiceConnections (org.jkiss.dbeaver.runtime.ui.UIServiceConnections)10 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 IFolder (org.eclipse.core.resources.IFolder)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Point (org.eclipse.swt.graphics.Point)2 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)2 UIServiceSQL (org.jkiss.dbeaver.runtime.ui.UIServiceSQL)2 NavigatorPreferences (org.jkiss.dbeaver.ui.navigator.NavigatorPreferences)2 TreeNodeSpecial (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)2