private void activateContext() { IContextService service = (IContextService) getSite().getService(IContextService.class); if (service != null) { service.activateContext("org.eclipse.dltk.ui.scriptEditorScope"); service.activateContext(EDITING_XQUERY_SOURCE_CONTEXT); } }
@SuppressWarnings("unused") public Object execute(ExecutionEvent event) throws ExecutionException { final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window == null) { return null; } final IContextService service = (IContextService) window.getService(IContextService.class); Shell shell = new Shell(window.getShell().getDisplay()); service.registerShell(shell, IContextService.TYPE_WINDOW); // Shell shell = new Shell(window.getShell()); shell.setLayout(new FillLayout()); Button b = new Button(shell, SWT.PUSH); final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); b.setText(Messages.showContexts_button); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Object[] array = service.getActiveContextIds().toArray(); Arrays.sort(array); StringBuffer buf = new StringBuffer(Messages.showContexts_title); for (int i = 0; i < array.length; i++) { buf.append('\n'); buf.append(array[i].toString()); } text.setText(buf.toString()); } }); shell.setSize(400, 300); shell.layout(); shell.open(); return null; }
public void testTwoEvaluations() throws Exception { IWorkbenchWindow window = openTestWindow(); IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class); assertNotNull(service); MyEval listener1 = new MyEval(); MyEval listener2 = new MyEval(); IContextActivation context1 = null; IEvaluationReference evalRef1 = null; IEvaluationReference evalRef2 = null; IContextService contextService = null; try { evalRef1 = service.addEvaluationListener( new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}), listener1, IEvaluationService.RESULT); assertEquals(1, listener1.count); assertFalse(listener1.currentValue); evalRef2 = service.addEvaluationListener( new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}), listener2, IEvaluationService.RESULT); assertEquals(1, listener2.count); assertFalse(listener2.currentValue); evalRef2.setResult(true); contextService = (IContextService) window.getService(IContextService.class); context1 = contextService.activateContext(CONTEXT_ID1); assertEquals(2, listener1.count); assertTrue(listener1.currentValue); // we already set this guy to true, he should skip assertEquals(1, listener2.count); assertFalse(listener2.currentValue); evalRef1.setResult(false); contextService.deactivateContext(context1); context1 = null; assertEquals(2, listener2.count); assertFalse(listener2.currentValue); // we already set this guy to false, so he should be the old // values assertEquals(2, listener1.count); assertTrue(listener1.currentValue); } finally { if (context1 != null) { contextService.deactivateContext(context1); } if (evalRef1 != null) { service.removeEvaluationListener(evalRef1); } if (evalRef2 != null) { service.removeEvaluationListener(evalRef2); } } }
public void testExtensionContributionExpression() throws Exception { IAction a = new Action() { @Override public void run() { System.out.println("Hello action"); } }; final MenuManager manager = new MenuManager(); final ActionContributionItem aci = new ActionContributionItem(a); IExtensionRegistry reg = Platform.getExtensionRegistry(); IExtensionPoint menusExtension = reg.getExtensionPoint("org.eclipse.ui.menus"); IExtension extension = menusExtension.getExtension(EXTENSION_ID); IConfigurationElement[] mas = extension.getConfigurationElements(); final Expression activeContextExpr[] = new Expression[1]; for (IConfigurationElement ma : mas) { IConfigurationElement[] items = ma.getChildren(); for (IConfigurationElement item : items) { String id = item.getAttribute("id"); if (id != null && id.equals("org.eclipse.ui.tests.menus.itemX1")) { IConfigurationElement visibleWhenElement = item.getChildren("visibleWhen")[0]; activeContextExpr[0] = ExpressionConverter.getDefault().perform(visibleWhenElement.getChildren()[0]); } } } assertNotNull("Failed to find expression", activeContextExpr[0]); AbstractContributionFactory factory = new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) { @Override public void createContributionItems( IServiceLocator menuService, IContributionRoot additions) { additions.addContributionItem(aci, activeContextExpr[0]); } }; menuService.addContributionFactory(factory); menuService.populateContributionManager(manager, LOCATION); assertFalse("starting state", aci.isVisible()); activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID); final Menu menu = manager.createContextMenu(window.getShell()); menu.notifyListeners(SWT.Show, new Event()); assertTrue("active context", aci.isVisible()); menu.notifyListeners(SWT.Hide, new Event()); contextService.deactivateContext(activeContext); activeContext = null; menu.notifyListeners(SWT.Show, new Event()); assertFalse("after deactivation", aci.isVisible()); menu.notifyListeners(SWT.Hide, new Event()); menuService.releaseContributions(manager); menuService.removeContributionFactory(factory); manager.dispose(); }
/* * (non-Javadoc) * * @see * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets * .Composite) */ public void createPartControl(Composite parent) { Assert.isTrue(fViewer == null); fTypeComparator = new ScriptElementTypeComparator(); // Setup viewer fViewer = createViewer(parent); initDragAndDrop(); fLabelProvider = createLabelProvider(); fViewer.setLabelProvider(createDecoratingLabelProvider(fLabelProvider)); fViewer.setComparator(createModelElementComparator()); fViewer.setUseHashlookup(true); fTitleProvider = createTitleProvider(); createContextMenu(); getSite().setSelectionProvider(fViewer); if (fMemento != null) { // initialize linking state before creating the // actions restoreLinkingEnabled(fMemento); } createActions(); // call before registering for selection changes addKeyListener(); if (fMemento != null) restoreState(fMemento); getSite().setSelectionProvider(fViewer); // Status line IStatusLineManager slManager = getViewSite().getActionBars().getStatusLineManager(); fViewer.addSelectionChangedListener(createStatusBarUpdater(slManager)); hookViewerListeners(); // Filters addFilters(); // Initialize viewer input fViewer.setContentProvider(createContentProvider()); setInitialInput(); // Initialize selection setInitialSelection(); fMemento = null; // Listen to page changes getViewSite().getPage().addPostSelectionListener(this); getViewSite().getPage().addPartListener(fPartListener); fillActionBars(getViewSite().getActionBars()); IContextService ctxService = (IContextService) getSite().getService(IContextService.class); if (ctxService != null) { fContextActivation = ctxService.activateContext(DLTKUIPlugin.CONTEXT_VIEWS); } setHelp(); }
/** * We just store the input and site to catch events * * @param input : the input to set * @param site : the site to set */ @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { IContextService contextService = (IContextService) site.getService(IContextService.class); contextService.activateContext(GRAPH_CONTEXT_ID); handlerService = (IHandlerService) site.getService(IHandlerService.class); setSite(site); setInput(input); }
/* * (non-Javadoc) * * @see org.eclipse.ui.console.IConsolePageParticipant#deactivated() */ public void deactivated() { // remove EOF submissions IPageSite site = fPage.getSite(); IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class); IContextService contextService = (IContextService) site.getService(IContextService.class); handlerService.deactivateHandler(fActivatedHandler); contextService.deactivateContext(fActivatedContext); }
/** @param newContextId The new context id */ private void changeContext(String newContextId) { IContextService contextService = Utils.getContextService(); if (previousActivation != null) { contextService.deactivateContext(previousActivation); } previousActivation = contextService.activateContext(newContextId); }
@Override public void createPartControl(Composite parent) { IContextService contextService = (IContextService) getSite().getService(IContextService.class); // FIXME : before Eclipse Juno, this line was not necessary // see bug 367816 and bug 382218 contextService.activateContext( "org.eclipse.gmf.runtime.diagram.ui.diagramContext"); //$NON-NLS-1$ super.createPartControl(parent); }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); IContextService contextService = (IContextService) getSite().getService(IContextService.class); if (contextService != null) { // This String constant is referenced in the plugin.xml contextService.activateContext("org.eclipse.emf.eson.ui.context"); } }
/* * (non-Javadoc) * * @see org.eclipse.ui.console.IConsolePageParticipant#activated() */ public void activated() { // add EOF submissions IPageSite site = fPage.getSite(); IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class); IContextService contextService = (IContextService) site.getService(IContextService.class); fActivatedContext = contextService.activateContext(fContextId); fActivatedHandler = handlerService.activateHandler( "org.eclipse.debug.ui.commands.eof", fEOFHandler); // $NON-NLS-1$ ErlideUIPlugin.getDefault().setConsolePage((ErlangConsolePage) fPage); }
public void testBasicContribution() throws Exception { IAction a = new Action() { @Override public void run() { System.out.println("Hello action"); } }; final MenuManager manager = new MenuManager(); final ActionContributionItem item = new ActionContributionItem(a); final Expression activeContextExpr = new ActiveContextExpression( MenuContributionHarness.CONTEXT_TEST1_ID, new String[] {ISources.ACTIVE_CONTEXT_NAME}); AbstractContributionFactory factory = new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) { @Override public void createContributionItems( IServiceLocator menuService, IContributionRoot additions) { additions.addContributionItem(item, activeContextExpr); } }; menuService.addContributionFactory(factory); menuService.populateContributionManager(manager, LOCATION); Shell shell = window.getShell(); // Test the initial menu creation final Menu menuBar = manager.createContextMenu(shell); Event e = new Event(); e.type = SWT.Show; e.widget = menuBar; menuBar.notifyListeners(SWT.Show, e); assertFalse("starting state", item.isVisible()); activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID); menuBar.notifyListeners(SWT.Show, e); assertTrue("active context", item.isVisible()); contextService.deactivateContext(activeContext); activeContext = null; menuBar.notifyListeners(SWT.Show, e); assertFalse("after deactivation", item.isVisible()); menuService.releaseContributions(manager); menuService.removeContributionFactory(factory); manager.dispose(); }
/* * @see IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ @Override public final void createPartControl(Composite parent) { internalCreatePartControl(parent); inititalizeColors(); getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener); createActions(); createContextMenu(); fillActionBars(getViewSite().getActionBars()); IContextService ctxService = (IContextService) getSite().getService(IContextService.class); if (ctxService != null) { fContextActivation = ctxService.activateContext(DLTKUIPlugin.CONTEXT_VIEWS); } PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpContextId()); }
@Override public void dispose() { if (checkIocStatusJob != null) { checkIocStatusJob.cancel(); } IContextService cs = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class); if (cs != null && contextActivation != null) { cs.deactivateContext(contextActivation); contextActivation = null; } getSite().getPage().removePartListener(tomoPartAdapter); super.dispose(); }
/* * (non-Javadoc) * * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown() */ protected void doTearDown() throws Exception { handlerService.deactivateHandlers(testHandlerActivations.values()); testHandlerActivations.clear(); contextService.deactivateContexts(testContextActivations.values()); testContextActivations.clear(); super.doTearDown(); }
public void testTwoHandlers() throws Exception { createHandlerActivation(C1_ID, H1, new String[] {ISources.ACTIVE_CONTEXT_NAME}); createHandlerActivation( C2_ID, H2, new String[] {ISources.ACTIVE_CONTEXT_NAME, ISources.ACTIVE_ACTION_SETS_NAME}); Command cmd = commandService.getCommand(CMD_ID); assertTrue("Command should be defined", cmd.isDefined()); assertFalse("Should not be handled yet", cmd.isHandled()); IContextActivation activationC1 = activateContext(C1_ID); assertTrue("Should definitely be handled", cmd.isHandled()); ActTestHandler handler1 = (ActTestHandler) testHandlers.get(H1); int count1 = handler1.executionCount; cmd.executeWithChecks(new ExecutionEvent()); assertEquals("The handler count should be incremented", count1 + 1, handler1.executionCount); activateContext(C2_ID); assertTrue("Should still be handled", cmd.isHandled()); ActTestHandler handler2 = (ActTestHandler) testHandlers.get(H2); int count2 = handler2.executionCount; count1 = handler1.executionCount; cmd.executeWithChecks(new ExecutionEvent()); assertEquals("The handler1 count should not be incremented", count1, handler1.executionCount); assertEquals("The handler2 count should be incremented", count2 + 1, handler2.executionCount); contextService.deactivateContext(activationC1); assertTrue("Will still be handled", cmd.isHandled()); }
public synchronized void activateContext() { if (contextActivation == null) { contextActivation = contextService.activateContext(CONTROL_PANEL_CONTEXT_ID); bindingService.addBindingManagerListener(new BindingServiceListener()); updateTriggerSequences(); } }
public synchronized void deactivateContext() { if (contextActivation != null) { contextService.deactivateContext(contextActivation); contextActivation = null; bindingService.removeBindingManagerListener(new BindingServiceListener()); updateTriggerSequences(); } }
public boolean close() { if (contextActivation != null && contextService != null) { contextService.deactivateContext(contextActivation); contextActivation = null; } deactivateJob(); if (getReturnCode() == OK) saveNotes(); return super.close(); }
/** * @throws ExecutionException * @throws NotDefinedException * @throws NotEnabledException * @throws NotHandledException */ private void doTestForBreak() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException { Command cmd = commandService.getCommand(CMD_ID); assertTrue("Command should be defined", cmd.isDefined()); assertFalse("Should not be handled yet", cmd.isHandled()); IContextActivation c1 = activateContext(C1_ID); IContextActivation c2 = activateContext(C2_ID); IContextActivation c3 = activateContext(C3_ID); assertTrue("Should still be handled", cmd.isHandled()); assertHandlerIsExecuted(cmd, H3); contextService.deactivateContext(c3); contextService.deactivateContext(c2); contextService.deactivateContext(c1); }
/* * (non-Javadoc) * * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown() */ protected void doTearDown() throws Exception { if (activeContext != null) { contextService.deactivateContext(activeContext); activeContext = null; } menuService = null; contextService = null; window = null; super.doTearDown(); }
/* * (non-Javadoc) * * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp() */ protected void doSetUp() throws Exception { super.doSetUp(); window = openTestWindow(); menuService = (IMenuService) window.getService(IMenuService.class); contextService = (IContextService) window.getService(IContextService.class); Context context1 = contextService.getContext(MenuContributionHarness.CONTEXT_TEST1_ID); if (!context1.isDefined()) { context1.define("Menu Test 1", "Menu test 1", IContextService.CONTEXT_ID_DIALOG_AND_WINDOW); } }
public void dispose() { if (fContextActivation != null) { IContextService ctxService = (IContextService) getSite().getService(IContextService.class); if (ctxService != null) { ctxService.deactivateContext(fContextActivation); } } if (fViewer != null) { getViewSite().getPage().removePostSelectionListener(this); getViewSite().getPage().removePartListener(fPartListener); fViewer = null; } if (fActionGroups != null) fActionGroups.dispose(); if (fWorkingSetFilterActionGroup != null) { fWorkingSetFilterActionGroup.dispose(); } super.dispose(); }
/* * @see IWorkbenchPart#dispose() */ @Override public final void dispose() { // cancel possible running computation fComputeCount++; if (fContextActivation != null) { IContextService ctxService = (IContextService) getSite().getService(IContextService.class); if (ctxService != null) { ctxService.deactivateContext(fContextActivation); } } getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener); ISelectionProvider provider = getSelectionProvider(); if (provider != null) provider.removeSelectionChangedListener(fCopyToClipboardAction); JFaceResources.getColorRegistry().removeListener(this); fBackgroundColorRGB = null; if (fBackgroundColor != null) { fBackgroundColor.dispose(); fBackgroundColor = null; } internalDispose(); }
public void createPartControl(Composite parent) { super.createPartControl(parent); // Code Folding ProjectionViewer viewer = (ProjectionViewer) getSourceViewer(); // Occurrence initiation, need ITextResource and ISourceViewer. highlighting = new com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptHighlighting( getResource(), viewer, colorManager, this); projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors()); projectionSupport.install(); // turn projection mode on viewer.doOperation(ProjectionViewer.TOGGLE); codeFoldingManager = new com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui .RezeptCodeFoldingManager(viewer, this); IContextService contextService = (IContextService) getSite().getService(IContextService.class); contextService.activateContext( "com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.EditorScope"); }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { if (!(input instanceof TaskEditorInput)) { throw new PartInitException( "Invalid editor input \"" + input.getClass() + "\""); // $NON-NLS-1$ //$NON-NLS-2$ } super.init(site, input); this.taskEditorInput = (TaskEditorInput) input; this.task = taskEditorInput.getTask(); // initialize selection site.getSelectionProvider().setSelection(new StructuredSelection(task)); setPartName(input.getName()); // activate context IContextService contextSupport = (IContextService) site.getService(IContextService.class); if (contextSupport != null) { contextSupport.activateContext(ID_EDITOR); } }
public void testScopedService() throws Exception { IWorkbenchWindow window = openTestWindow(); IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class); assertNotNull(service); assertTrue(service instanceof SlaveEvaluationService); MyEval listener = new MyEval(); IContextActivation context1 = null; IContextService contextService = null; try { service.addEvaluationListener( new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}), listener, IEvaluationService.RESULT); assertEquals(1, listener.count); assertFalse(listener.currentValue); contextService = (IContextService) window.getWorkbench().getService(IContextService.class); context1 = contextService.activateContext(CONTEXT_ID1); assertEquals(2, listener.count); assertTrue(listener.currentValue); window.close(); processEvents(); assertEquals(3, listener.count); assertTrue(listener.currentValue); contextService.deactivateContext(context1); context1 = null; assertEquals(3, listener.count); assertTrue(listener.currentValue); } finally { if (context1 != null) { contextService.deactivateContext(context1); } } }
/* * (non-Javadoc) * * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp() */ protected void doSetUp() throws Exception { for (int i = 0; i < CREATE_CONTEXTS.length; i++) { final String[] contextInfo = CREATE_CONTEXTS[i]; final Context context = contextService.getContext(contextInfo[0]); if (!context.isDefined()) { context.define(contextInfo[1], contextInfo[2], contextInfo[3]); } } Command cmd = commandService.getCommand(CMD_ID); if (!cmd.isDefined()) { Category cat = commandService.getCategory(CATEGORY_ID); cmd.define("Test Handler", "Test handler activation", cat); } }
@Override protected void initActions( final IServiceLocator serviceLocator, final HandlerCollection handlers) { super.initActions(serviceLocator, handlers); final IContextService contextService = (IContextService) serviceLocator.getService(IContextService.class); contextService.activateContext("de.walware.statet.r.actionSets.RSessionTools"); // $NON-NLS-1$ fHelpContextProvider = RUIHelp.createEnrichedRHelpContextProvider( getInputGroup().getViewer(), IRUIHelpContextIds.R_CONSOLE); getInputGroup() .getViewer() .getTextWidget() .addHelpListener( new HelpListener() { public void helpRequested(final HelpEvent e) { PlatformUI.getWorkbench() .getHelpSystem() .displayHelp(fHelpContextProvider.getContext(null)); } }); }
public int open() { IWorkbench workbench = window.getWorkbench(); bindingService = (IBindingService) workbench.getAdapter(IBindingService.class); contextService = (IContextService) workbench.getAdapter(IContextService.class); if (bindingService != null) { registerWorkbenchCommands(); } int ret = super.open(); if (ret == OK) { if (contextService != null) { contextActivation = contextService.activateContext(CONTEXT_ID); } if (bindingService != null) { registerDialogCommands(); } } activateJob(); return ret; }