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;
}
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();
}
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();
}
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");
}
}
}
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");
}
}
}
Aggregations