use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by serge-rider.
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");
}
}
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by serge-rider.
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 serge-rider.
the class SQLEditor method promptToSaveOnClose.
@Override
public int promptToSaveOnClose() {
int jobsRunning = getTotalQueryRunning();
if (jobsRunning > 0) {
log.warn("There are " + jobsRunning + " SQL job(s) still running in the editor");
if (ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME), null, SQLPreferenceConstants.CONFIRM_RUNNING_QUERY_CLOSE, ConfirmationDialog.QUESTION, jobsRunning) != IDialogConstants.YES_ID) {
return ISaveablePart2.CANCEL;
}
}
for (QueryProcessor queryProcessor : queryProcessors) {
for (QueryResultsContainer resultsProvider : queryProcessor.getResultContainers()) {
ResultSetViewer rsv = resultsProvider.getResultSetController();
if (rsv != null && rsv.isDirty()) {
return rsv.promptToSaveOnClose();
}
}
}
// Cancel running jobs (if any) and close results tabs
for (QueryProcessor queryProcessor : queryProcessors) {
queryProcessor.cancelJob();
// FIXME: it is a hack (to avoid asking "Save script?" because editor is marked as dirty while queries are running)
// FIXME: make it better
queryProcessor.curJobRunning.set(0);
}
// End transaction
if (executionContext != null) {
UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
if (serviceConnections != null && !serviceConnections.checkAndCloseActiveTransaction(new DBCExecutionContext[] { executionContext })) {
return ISaveablePart2.CANCEL;
}
}
// That's fine
if (isNonPersistentEditor()) {
return ISaveablePart2.NO;
}
updateDirtyFlag();
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_CLOSE)) {
return ISaveablePart2.YES;
}
if (super.isDirty() || (extraPresentation instanceof ISaveablePart && ((ISaveablePart) extraPresentation).isDirty())) {
return ISaveablePart2.DEFAULT;
}
return ISaveablePart2.YES;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by dbeaver.
the class SQLEditor method promptToSaveOnClose.
@Override
public int promptToSaveOnClose() {
int jobsRunning = getTotalQueryRunning();
if (jobsRunning > 0) {
log.warn("There are " + jobsRunning + " SQL job(s) still running in the editor");
if (ConfirmationDialog.showConfirmDialog(ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME), null, SQLPreferenceConstants.CONFIRM_RUNNING_QUERY_CLOSE, ConfirmationDialog.QUESTION, jobsRunning) != IDialogConstants.YES_ID) {
return ISaveablePart2.CANCEL;
}
}
for (QueryProcessor queryProcessor : queryProcessors) {
for (QueryResultsContainer resultsProvider : queryProcessor.getResultContainers()) {
ResultSetViewer rsv = resultsProvider.getResultSetController();
if (rsv != null && rsv.isDirty()) {
return rsv.promptToSaveOnClose();
}
}
}
// Cancel running jobs (if any) and close results tabs
for (QueryProcessor queryProcessor : queryProcessors) {
queryProcessor.cancelJob();
// FIXME: it is a hack (to avoid asking "Save script?" because editor is marked as dirty while queries are running)
// FIXME: make it better
queryProcessor.curJobRunning.set(0);
}
// End transaction
if (executionContext != null) {
UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
if (serviceConnections != null && !serviceConnections.checkAndCloseActiveTransaction(new DBCExecutionContext[] { executionContext })) {
return ISaveablePart2.CANCEL;
}
}
// That's fine
if (isNonPersistentEditor()) {
return ISaveablePart2.NO;
}
updateDirtyFlag();
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_CLOSE)) {
return ISaveablePart2.YES;
}
if (super.isDirty() || (extraPresentation instanceof ISaveablePart && ((ISaveablePart) extraPresentation).isDirty())) {
return ISaveablePart2.DEFAULT;
}
return ISaveablePart2.YES;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceConnections in project dbeaver by dbeaver.
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;
}
Aggregations