类org.eclipse.ui.contexts.IContextService源码实例Demo

下面列出了怎么用org.eclipse.ui.contexts.IContextService的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Pydev   文件: PyContextActivator.java
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;
        }
    }
}
 
源代码2 项目: goclipse   文件: LangTextMergeViewer.java
@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());
	}
 
源代码3 项目: n4js   文件: N4IDEXpectView.java
/**
 * 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);
}
 
private void initN4Context() {
	if (isWorkbenchRunning()) {
		final IWorkbench workbench = getWorkbench();
		workbench.getDisplay().asyncExec(() -> {
			final IContextService service = workbench.getService(IContextService.class);
			service.activateContext(N4_CONTEXT_ID);
		});
	}
}
 
源代码5 项目: xds-ide   文件: XFindPanel.java
private void deactivateContext() {
    if (contextActivation != null) {
        IContextService contextService = getService(IContextService.class);
        if (contextService != null) {
            contextService.deactivateContext(contextActivation);
        }
        contextActivation = null;
    }
}
 
源代码6 项目: xds-ide   文件: UpdateManager.java
/**
 * 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;
	}
}
 
源代码7 项目: typescript.java   文件: TypeScriptMergeViewer.java
@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$
		}
	}
}
 
源代码8 项目: tracecompass   文件: SDWidget.java
/**
 * 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);
}
 
private void deactivateContextService() {
    IContextService contextService = fContextService;
    if (contextService != null) {
        contextService.deactivateContexts(fActiveContexts);
        fActiveContexts.clear();
    }
}
 
@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$
		}
	}
}
 
源代码11 项目: sarl   文件: SARLPackageExplorerPart.java
@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();
}
 
源代码12 项目: tmxeditor8   文件: TeStartup.java
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");
			}
		}
	});
}
 
源代码13 项目: birt   文件: GraphicalEditorWithFlyoutPalette.java
private void activateDesignerEditPart( )
{
	IContextService contextService = (IContextService) PlatformUI.getWorkbench( )
			.getService( IContextService.class );
	if ( contextActivation == null )
		contextActivation = contextService.activateContext( VIEW_CONTEXT_ID );
}
 
源代码14 项目: birt   文件: GraphicalEditorWithFlyoutPalette.java
private void deActivateDesignerEditPart( )
{
	if ( !UIUtil.isReportEditorActivated( ) )
	{
		IContextService contextService = (IContextService) PlatformUI.getWorkbench( )
				.getService( IContextService.class );
		if ( contextActivation != null )
		{
			contextService.deactivateContext( contextActivation );
			contextActivation = null;
		}
	}
}
 
源代码15 项目: e4macs   文件: SelectionDialog.java
/**
 * 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()));
}
 
源代码16 项目: e4macs   文件: EmacsPlusConsoleParticipant.java
/**
 * @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();
       }
}
 
源代码17 项目: e4macs   文件: CommandSupport.java
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$
	}
}
 
源代码18 项目: e4macs   文件: RepeatCommandSupport.java
private void clearContext() {
	if (this.repeatc != null) {
		((IContextService)PlatformUI.getWorkbench().getService(IContextService.class)).deactivateContext(repeatc);
		this.repeatc = null;
	}
	
}
 
源代码19 项目: Pydev   文件: KeyAssistDialog.java
/**
 * 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()));
}
 
@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);
}
 
源代码21 项目: xds-ide   文件: XFindPanel.java
private void activateContext() {
    IContextService contextService = getService(IContextService.class);
    if (contextService != null) {
        contextActivation = contextService.activateContext(CONTEXT_ID);
    }
}
 
源代码22 项目: xds-ide   文件: UpdateManager.java
/**
 * Override standard 'Check for Updates' handler. 
 */
public static void activateXdsUpdateContext() {
   IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);
	   activateContext = contextService.activateContext( XDS_UPDATE_CONTEXT );
}
 
private void activateContextService() {
    IContextService contextService = fContextService;
    if (fActiveContexts.isEmpty() && contextService != null) {
        fActiveContexts.add(Objects.requireNonNull(contextService.activateContext(TMF_VIEW_UI_CONTEXT)));
    }
}
 
源代码24 项目: KaiZen-OpenAPI-Editor   文件: JsonEditor.java
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    IContextService contextService = (IContextService) site.getService(IContextService.class);
    contextService.activateContext(CONTEXT);
}
 
源代码25 项目: APICloud-Studio   文件: KeybindingsManager.java
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();
}
 
源代码26 项目: APICloud-Studio   文件: KeybindingsManager.java
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;
}
 
源代码27 项目: e4macs   文件: EmacsPlusConsoleParticipant.java
/**
 * @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();
}
 
源代码28 项目: e4macs   文件: RepeatCommandSupport.java
private void activateContext() {
	if (this.repeatc == null) {
		this.repeatc = ((IContextService)PlatformUI.getWorkbench().getService(IContextService.class)).activateContext(RCONTEXT);
	}

}
 
源代码29 项目: Pydev   文件: BindKeysHelper.java
/**
 * @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);
}
 
 类所在包
 同包方法