use of org.eclipse.ui.contexts.IContextService in project dbeaver by serge-rider.
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 serge-rider.
the class WorkbenchContextListener method listenWindowEvents.
private void listenWindowEvents(IWorkbenchWindow window) {
{
// Register ds toolbar handler
DataSourceToolbarHandler toolbarHandler = new DataSourceToolbarHandler(window);
window.getShell().addDisposeListener(e -> toolbarHandler.dispose());
}
IPerspectiveListener perspectiveListener = new IPerspectiveListener() {
private IContextActivation perspectiveActivation;
@Override
public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
if (perspective.getId().equals(DBeaverPerspective.PERSPECTIVE_ID)) {
perspectiveActivation = contextService.activateContext(PERSPECTIVE_CONTEXT_ID);
} else if (perspectiveActivation != null) {
contextService.deactivateContext(perspectiveActivation);
perspectiveActivation = null;
}
}
@Override
public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
}
};
window.addPerspectiveListener(perspectiveListener);
IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
perspectiveListener.perspectiveActivated(activePage, activePage.getPerspective());
}
window.addPageListener(this);
for (IWorkbenchPage page : window.getPages()) {
page.addPartListener(this);
}
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by serge-rider.
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;
}
}
});
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.
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 mylyn.docs by eclipse.
the class MarkupEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
IContextService contextService = site.getService(IContextService.class);
contextService.activateContext(CONTEXT);
}
Aggregations