org.eclipse.ui.contexts.IContextService Java Examples

The following examples show how to use org.eclipse.ui.contexts.IContextService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LangTextMergeViewer.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
	protected void createControls(Composite composite) {
		super.createControls(composite);
		ICompareContainer container = getCompareConfiguration().getContainer();
		
		IWorkbenchPart workbenchPart= container.getWorkbenchPart();
		if (workbenchPart != null) {
			IContextService service= workbenchPart.getSite().getService(IContextService.class);
			if (service != null) {
				service.activateContext(EditorSettings_Actual.EDITOR_CONTEXT_ID);
			}
		}
		// TODO: activate Lang editor commands
//		IHandlerService handlerSvc = container.getServiceLocator().getService(IHandlerService.class);
//		handlerSvc.activateHandler(EditorCommandIds.OpenDef_ID, new OpenDefinitionHandler2());
	}
 
Example #2
Source File: PyContextActivator.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private void handleStateChange() {
    boolean isActive = false;
    for (IPyContextObserver obs : this.observers.getListeners()) {
        if (obs.isPyContextActive()) {
            isActive = true;
            break;
        }
    }

    IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);
    //May be null on shutdown on Eclipse 4. 
    if (contextService != null) {
        if (isActive) {
            if (activateContext == null) {
                activateContext = contextService.activateContext("com.python.pydev.contexts.window");
            }
        } else {
            if (activateContext != null) {
                contextService.deactivateContext(activateContext);
            }
            activateContext = null;
        }
    }
}
 
Example #3
Source File: SARLPackageExplorerPart.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	// Open the context
	final IContextService contextService = getSite().getService(IContextService.class);
	contextService.activateContext(CONTEXT_ID);
	// Overridden for setting the label provider, which is set in a private function in the super type.
	super.createPartControl(parent);
	internalResetLabelProvider();
	restoreFilterAndSorter();
}
 
Example #4
Source File: BonitaStudioWorkbenchAdvisor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void initialize(final IWorkbenchConfigurer configurer) {
    super.initialize(configurer);
    configurer.setSaveAndRestore(true);
    final IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    contextService.activateContext("org.bonitasoft.studio.context.id");
    initializeIDEImages(configurer);
}
 
Example #5
Source File: KeyAssistDialog.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Registers the shell as the same type as its parent with the context
 * support. This ensures that it does not modify the current state of the
 * application.
 */
private final void registerShellType() {
    final Shell shell = getShell();
    final IContextService contextService = (IContextService) EditorUtils.getActiveWorkbenchWindow().getService(
            IContextService.class);
    contextService.registerShell(shell, contextService.getShellType((Shell) shell.getParent()));
}
 
Example #6
Source File: RepeatCommandSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private void clearContext() {
	if (this.repeatc != null) {
		((IContextService)PlatformUI.getWorkbench().getService(IContextService.class)).deactivateContext(repeatc);
		this.repeatc = null;
	}
	
}
 
Example #7
Source File: CommandSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
public void getContexts(ITextEditor editor) {
	IContextService contextService = (IContextService) editor.getSite().getService(IContextService.class);
	@SuppressWarnings("unchecked")	// Eclipse documents the collection type
	Collection<String> col = contextService.getActiveContextIds();
	Iterator<String> it = col.iterator();
	while (it.hasNext()) {
		System.out.println("context: " + it.next());		//$NON-NLS-1$
	}
}
 
Example #8
Source File: EmacsPlusConsoleParticipant.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.ui.console.IConsolePageParticipant#deactivated()
 */
public void deactivated() {
       if (fContextActivation != null){
       	IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class);
       	contextService.deactivateContext(fContextActivation);
       	fContextActivation = null;
       	((EmacsPlusConsole)console).offLine();
       }
}
 
Example #9
Source File: SelectionDialog.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Registers the shell as the same type as its parent with the context
 * support. This ensures that it does not modify the current state of the
 * application.
 */
private final void registerShellType() {
	final Shell shell = getShell();
	
	final IContextService contextService = (IContextService) editor.getEditorSite().getWorkbenchWindow().getWorkbench().getService(IContextService.class);
	contextService.registerShell(shell, contextService.getShellType((Shell) shell.getParent()));
}
 
Example #10
Source File: GraphicalEditorWithFlyoutPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void deActivateDesignerEditPart( )
{
	if ( !UIUtil.isReportEditorActivated( ) )
	{
		IContextService contextService = (IContextService) PlatformUI.getWorkbench( )
				.getService( IContextService.class );
		if ( contextActivation != null )
		{
			contextService.deactivateContext( contextActivation );
			contextActivation = null;
		}
	}
}
 
Example #11
Source File: GraphicalEditorWithFlyoutPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void activateDesignerEditPart( )
{
	IContextService contextService = (IContextService) PlatformUI.getWorkbench( )
			.getService( IContextService.class );
	if ( contextActivation == null )
		contextActivation = contextService.activateContext( VIEW_CONTEXT_ID );
}
 
Example #12
Source File: TeStartup.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void earlyStartup() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	workbench.getDisplay().asyncExec(new Runnable() {
		
		@Override
		public void run() {
			IContextService contextService = (IContextService) workbench.getService(IContextService.class);
			if(contextService != null){
				contextService.activateContext("net.heartsome.cat.te.context");
			}
		}
	});
}
 
Example #13
Source File: N4IDEXpectView.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 = getSite().getService(IContextService.class);
	// this will get cleaned up automatically when the site
	// is disposed
	contextService.activateContext(VIEW_CONTEXT_ID);
}
 
Example #14
Source File: JavaMergeViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void createControls(Composite composite) {
	super.createControls(composite);
	IWorkbenchPart workbenchPart = getCompareConfiguration().getContainer().getWorkbenchPart();
	if (workbenchPart != null) {
		IContextService service = (IContextService)workbenchPart.getSite().getService(IContextService.class);
		if (service != null) {
			service.activateContext("org.eclipse.jdt.ui.javaEditorScope"); //$NON-NLS-1$
		}
	}
}
 
Example #15
Source File: AbstractSegmentStoreTableView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void deactivateContextService() {
    IContextService contextService = fContextService;
    if (contextService != null) {
        contextService.deactivateContexts(fActiveContexts);
        fActiveContexts.clear();
    }
}
 
Example #16
Source File: SDWidget.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets view part.
 *
 * @param viewSite The view part to set
 */
public void setSite(ViewPart viewSite) {
    fSite = viewSite;
    fSite.getSite().setSelectionProvider(fSelProvider);
    Object serviceObject = fSite.getSite().getWorkbenchWindow().getService(IContextService.class);
    IContextService service = (IContextService) serviceObject;
    service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
    service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
}
 
Example #17
Source File: TypeScriptMergeViewer.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
protected void createControls(Composite composite) {
	super.createControls(composite);
	IWorkbenchPart workbenchPart = getCompareConfiguration().getContainer().getWorkbenchPart();
	if (workbenchPart != null) {
		IContextService service = workbenchPart.getSite().getService(IContextService.class);
		if (service != null) {
			service.activateContext("ts.eclipse.ide.jsdt.ui.typeScriptEditorScope"); //$NON-NLS-1$
		}
	}
}
 
Example #18
Source File: UpdateManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Cancel overriding of standard 'Check for Updates' handler. 
 */
public static void deactivateXdsUpdateContext() {
	if (activateContext != null) {
		IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);
		contextService.deactivateContext(activateContext);
		activateContext = null;
	}
}
 
Example #19
Source File: XFindPanel.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void deactivateContext() {
    if (contextActivation != null) {
        IContextService contextService = getService(IContextService.class);
        if (contextService != null) {
            contextService.deactivateContext(contextActivation);
        }
        contextActivation = null;
    }
}
 
Example #20
Source File: N4JSApplicationWorkbenchWindowAdvisor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void initN4Context() {
	if (isWorkbenchRunning()) {
		final IWorkbench workbench = getWorkbench();
		workbench.getDisplay().asyncExec(() -> {
			final IContextService service = workbench.getService(IContextService.class);
			service.activateContext(N4_CONTEXT_ID);
		});
	}
}
 
Example #21
Source File: KeybindingsManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private boolean processKeyStroke(Event event, KeyStroke keyStroke)
{
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
	KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence();
	KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, keyStroke);

	if (uniqueKeySequences.contains(sequenceAfterKeyStroke))
	{
		IEvaluationService evaluationService = (IEvaluationService) workbench.getService(IEvaluationService.class);
		IEvaluationContext evaluationContext = evaluationService.getCurrentState();
		IWorkbenchPart workbenchPart = (IWorkbenchPart) evaluationContext.getVariable(ISources.ACTIVE_PART_NAME);
		ICommandElementsProvider commandElementsProvider = (ICommandElementsProvider) workbenchPart
				.getAdapter(ICommandElementsProvider.class);
		if (commandElementsProvider != null)
		{
			// Is there a Eclipse binding that matches the key sequence?
			Binding binding = null;
			if (bindingService.isPerfectMatch(sequenceAfterKeyStroke))
			{
				// Record it
				binding = bindingService.getPerfectMatch(sequenceAfterKeyStroke);
			}

			List<CommandElement> commandElements = commandElementsProvider
					.getCommandElements(sequenceAfterKeyStroke);
			if (commandElements.size() == 0)
			{
				if (binding == null)
				{
					// Remember the prefix
					incrementState(sequenceAfterKeyStroke);
				}
				else
				{
					// Reset our state
					resetState();
				}

				// Do not consume the event. Let Eclipse handle it.
				return false;
			}
			else
			{
				if (binding == null && commandElements.size() == 1)
				{
					// We have a unique scripting command to execute
					executeCommandElement(commandElementsProvider, commandElements.get(0));

					// Reset our state
					resetState();

					// The event should be consumed
					return true;
				}
				else
				{
					// We need to show commands menu to the user
					IContextService contextService = (IContextService) workbench.getService(IContextService.class);
					popup(workbenchPart.getSite().getShell(), bindingService, contextService,
							commandElementsProvider, commandElements, event, binding,
							getInitialLocation(commandElementsProvider));

					// Reset our state
					resetState();

					// The event should be consumed
					return true;
				}
			}
		}
	}
	else if (uniqueKeySequencesPrefixes.contains(sequenceAfterKeyStroke))
	{
		// Prefix match

		// Is there a Eclipse command with a perfect match
		if (bindingService.isPerfectMatch(sequenceAfterKeyStroke))
		{
			// Reset our state
			resetState();
		}
		else
		{
			// Remember the prefix
			incrementState(sequenceAfterKeyStroke);
		}
	}
	else
	{
		// Reset our state
		resetState();
	}

	// We did not handle the event. Do not consume the event. Let Eclipse handle it.
	return false;
}
 
Example #22
Source File: KeybindingsManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void initBindings()
{
	WorkbenchJob workbenchJob = new WorkbenchJob("Installing KeybindingsManager") //$NON-NLS-1$
	{
		@Override
		public IStatus runInUIThread(IProgressMonitor monitor)
		{

			loadbindings();

			// Insert our key listener before the Eclipse's key listeners
			IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
			if (bindingService instanceof BindingService)
			{
				final BindingService theBindingService = (BindingService) bindingService;
				Display display = PlatformUI.getWorkbench().getDisplay();
				final WorkbenchKeyboard keyboard = theBindingService.getKeyboard();
				Listener keyDownFilter = keyboard.getKeyDownFilter();
				try
				{
					if (keyDownFilter != null)
					{
						display.removeFilter(SWT.KeyDown, keyDownFilter);
						display.removeFilter(SWT.Traverse, keyDownFilter);
					}
					display.addFilter(SWT.KeyDown, listener);
					display.addFilter(SWT.Traverse, listener);
				}
				finally
				{
					if (keyDownFilter != null)
					{
						display.addFilter(SWT.KeyDown, keyDownFilter);
						display.addFilter(SWT.Traverse, keyDownFilter);
					}
				}
			}

			// Set the initial enabled state of KeybindingsManager
			IContextService contextService = (IContextService) workbench.getService(IContextService.class);
			contextService.addContextManagerListener(contextManagerListener);
			setEnabled(contextService.getActiveContextIds().contains(ScriptingUIPlugin.SCRIPTING_CONTEXT_ID));

			return Status.OK_STATUS;
		}
	};
	workbenchJob.setRule(MUTEX_RULE);
	EclipseUtil.setSystemForJob(workbenchJob);
	workbenchJob.setPriority(Job.LONG);
	workbenchJob.schedule();
}
 
Example #23
Source File: JsonEditor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    IContextService contextService = (IContextService) site.getService(IContextService.class);
    contextService.activateContext(CONTEXT);
}
 
Example #24
Source File: AbstractSegmentStoreTableView.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private void activateContextService() {
    IContextService contextService = fContextService;
    if (fActiveContexts.isEmpty() && contextService != null) {
        fActiveContexts.add(Objects.requireNonNull(contextService.activateContext(TMF_VIEW_UI_CONTEXT)));
    }
}
 
Example #25
Source File: EmacsPlusConsoleParticipant.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.ui.console.IConsolePageParticipant#activated()
 */
public void activated() {
       IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class);
       fContextActivation = contextService.activateContext("org.eclipse.ui.textEditorScope"); //$NON-NLS-1$
       ((EmacsPlusConsole)console).onLine();
}
 
Example #26
Source File: RepeatCommandSupport.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
private void activateContext() {
	if (this.repeatc == null) {
		this.repeatc = ((IContextService)PlatformUI.getWorkbench().getService(IContextService.class)).activateContext(RCONTEXT);
	}

}
 
Example #27
Source File: BindKeysHelper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param contextId defines the keys context we'll work with...
 *
 * We'll only remove/add bindings to this context.
 */
public BindKeysHelper(String contextId) {
    Assert.isNotNull(contextId);
    this.contextId = contextId;

    // Set the context we're working with.
    Set<String> activeContextIds = new HashSet<>();
    activeContextIds.add(contextId);
    contextManager.setActiveContextIds(activeContextIds);

    // Check that the context we're working with actually exists
    IWorkbench workbench = PlatformUI.getWorkbench();
    bindingService = (IBindingService) workbench.getService(IBindingService.class);
    IContextService contextService = (IContextService) workbench.getService(IContextService.class);
    Context context = contextService.getContext(contextId);
    if (context == null || context.isDefined() == false) {
        throw new RuntimeException("The context: " + contextId + " does not exist.");
    }

    Scheme activeScheme = bindingService.getActiveScheme();
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();

    // Make a copy we can work with locally (we'll apply changes later based on this copy).
    try {
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = localChangeManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
        }
        localChangeManager.setActiveScheme(activeScheme);
    } catch (final NotDefinedException e) {
        throw new Error("There is a programmer error in the bind keys helper"); //$NON-NLS-1$
    }
    localChangeManager.setLocale(bindingService.getLocale());
    localChangeManager.setPlatform(bindingService.getPlatform());
    Binding[] bindings = bindingService.getBindings();
    for (Binding binding : bindings) {
        initialState.add(binding);
    }
    localChangeManager.setBindings(bindings);
}
 
Example #28
Source File: UpdateManager.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Override standard 'Check for Updates' handler. 
 */
public static void activateXdsUpdateContext() {
   IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);
	   activateContext = contextService.activateContext( XDS_UPDATE_CONTEXT );
}
 
Example #29
Source File: XFindPanel.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private void activateContext() {
    IContextService contextService = getService(IContextService.class);
    if (contextService != null) {
        contextActivation = contextService.activateContext(CONTEXT_ID);
    }
}