use of org.eclipse.ui.contexts.IContextService in project dbeaver by serge-rider.
the class WorkbenchContextListener method activatePartContexts.
void activatePartContexts(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
try {
contextService.deferUpdates(true);
if (part instanceof INavigatorModelView) {
// We check for instanceof (do not use adapter) because otherwise it become active
// for all entity editor and clashes with SQL editor and other complex stuff.
// if (activationNavigator != null) {
// //log.debug("Double activation of navigator context");
// contextService.deactivateContext(activationNavigator);
// }
// activationNavigator = contextService.activateContext(INavigatorModelView.NAVIGATOR_CONTEXT_ID);
}
if (part instanceof SQLEditorBase || part.getAdapter(SQLEditorBase.class) != null) {
if (activationSQL != null) {
// log.debug("Double activation of SQL context");
contextService.deactivateContext(activationSQL);
}
activationSQL = contextService.activateContext(SQLEditorContributions.SQL_EDITOR_CONTEXT);
}
if (part.getAdapter(ResultSetViewer.class) != null || (part instanceof SQLEditor) || (part instanceof EntityEditor && ((EntityEditor) part).getDatabaseObject() instanceof DBSDataContainer)) {
if (activationResults != null) {
contextService.deactivateContext(activationResults);
}
activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
}
// Refresh auto-commit element state (#3315)
// Refresh OpenSeparateConnection
ActionUtils.fireCommandRefresh(ConnectionCommands.CMD_TOGGLE_AUTOCOMMIT, SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
} finally {
contextService.deferUpdates(false);
}
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by serge-rider.
the class EditorUtils method trackControlContext.
public static void trackControlContext(IWorkbenchSite site, Control control, String contextId) {
final IContextService contextService = site.getService(IContextService.class);
if (contextService != null) {
final IContextActivation[] activation = new IContextActivation[1];
FocusListener focusListener = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
// No need to deactivate the same context
if (activation[0] != null) {
contextService.deactivateContext(activation[0]);
activation[0] = null;
}
activation[0] = contextService.activateContext(contextId);
// new Exception().printStackTrace();
}
@Override
public void focusLost(FocusEvent e) {
if (activation[0] != null) {
contextService.deactivateContext(activation[0]);
activation[0] = null;
}
}
};
control.addFocusListener(focusListener);
control.addDisposeListener(e -> {
if (activation[0] != null) {
contextService.deactivateContext(activation[0]);
activation[0] = null;
}
});
}
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.
the class WorkbenchContextListener method deactivatePartContexts.
void deactivatePartContexts(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
try {
contextService.deferUpdates(true);
// }
if (activationSQL != null) {
contextService.deactivateContext(activationSQL);
activationSQL = null;
}
if (activationResults != null) {
contextService.deactivateContext(activationResults);
activationResults = null;
}
} finally {
contextService.deferUpdates(false);
}
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.
the class WorkbenchContextListener method activatePartContexts.
void activatePartContexts(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
try {
contextService.deferUpdates(true);
if (part instanceof INavigatorModelView) {
// We check for instanceof (do not use adapter) because otherwise it become active
// for all entity editor and clashes with SQL editor and other complex stuff.
// if (activationNavigator != null) {
// //log.debug("Double activation of navigator context");
// contextService.deactivateContext(activationNavigator);
// }
// activationNavigator = contextService.activateContext(INavigatorModelView.NAVIGATOR_CONTEXT_ID);
}
if (part instanceof SQLEditorBase || part.getAdapter(SQLEditorBase.class) != null) {
if (activationSQL != null) {
// log.debug("Double activation of SQL context");
contextService.deactivateContext(activationSQL);
}
activationSQL = contextService.activateContext(SQLEditorContributions.SQL_EDITOR_CONTEXT);
}
if (part.getAdapter(ResultSetViewer.class) != null || (part instanceof SQLEditor) || (part instanceof EntityEditor && ((EntityEditor) part).getDatabaseObject() instanceof DBSDataContainer)) {
if (activationResults != null) {
contextService.deactivateContext(activationResults);
}
activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
}
// Refresh auto-commit element state (#3315)
// Refresh OpenSeparateConnection
ActionUtils.fireCommandRefresh(ConnectionCommands.CMD_TOGGLE_AUTOCOMMIT, SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
} finally {
contextService.deferUpdates(false);
}
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.
the class AbstractPresentation method activateTextKeyBindings.
protected void activateTextKeyBindings(@NotNull IResultSetController controller, Control control) {
final IContextService contextService = controller.getSite().getService(IContextService.class);
control.addFocusListener(new FocusListener() {
IContextActivation activation;
@Override
public void focusGained(FocusEvent e) {
controller.updateEditControls();
if (activation == null) {
activation = contextService.activateContext("org.eclipse.ui.textEditorScope");
}
}
@Override
public void focusLost(FocusEvent e) {
controller.updateEditControls();
if (activation != null) {
contextService.deactivateContext(activation);
activation = null;
}
}
});
}
Aggregations