use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.
the class WorkbenchContextListener method partDeactivated.
@Override
public void partDeactivated(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
try {
contextService.deferUpdates(true);
if (activationNavigator != null && part instanceof INavigatorModelView) {
contextService.deactivateContext(activationNavigator);
activationNavigator = null;
}
if (activationSQL != null && part instanceof SQLEditorBase) {
contextService.deactivateContext(activationSQL);
activationSQL = null;
}
if (activationResults != null) {
contextService.deactivateContext(activationResults);
activationResults = null;
}
} finally {
contextService.deferUpdates(false);
}
// log.info(part.getClass().getSimpleName() + " DEACTIVATED: " + contextService.getActiveContextIds());
}
use of org.eclipse.ui.contexts.IContextService in project tmdm-studio-se by Talend.
the class TreeViewerListener method activateContext.
/**
* Activate a context that this view uses. It will be tied to this view activation events and will be removed when
* the view is disposed.
*/
private void activateContext() {
IContextService contextService = (IContextService) getSite().getService(IContextService.class);
contextService.activateContext(VIEW_CONTEXT_ID);
}
use of org.eclipse.ui.contexts.IContextService in project tdq-studio-se by Talend.
the class DQRespositoryView method activateContext.
/**
* Activate a context that this view uses. It will be tied to this view activation events and will be removed when
* the view is disposed.
*/
private void activateContext() {
IContextService contextService = (IContextService) getSite().getService(IContextService.class);
contextService.activateContext(VIEW_CONTEXT_ID);
}
use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.
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 xtext-eclipse by eclipse.
the class EmbeddedEditorActions method createFocusAndDisposeListeners.
protected void createFocusAndDisposeListeners() {
final List<IHandlerActivation> handlerActivations = Lists.newArrayListWithExpectedSize(3);
final IHandlerService handlerService = workbench.getAdapter(IHandlerService.class);
final IContextService contextService = workbench.getAdapter(IContextService.class);
Shell shell = viewer.getTextWidget().getShell();
final ActiveShellExpression expression = new ActiveShellExpression(shell);
final IContextActivation contextActivation = contextService.activateContext(EMBEDDED_TEXT_EDITOR_SCOPE, expression);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handlerService.deactivateHandlers(handlerActivations);
contextService.deactivateContext(contextActivation);
}
});
viewer.getTextWidget().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
handlerService.deactivateHandlers(handlerActivations);
handlerActivations.clear();
}
@Override
public void focusGained(FocusEvent e) {
for (final IAction action : allActions.values()) {
handlerActivations.add(handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action), expression, true));
}
}
});
}
Aggregations