Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.editor.handler;
import  org.eclipse.core.commands.AbstractHandler;
import  org.eclipse.core.commands.ExecutionEvent;
import  org.eclipse.core.commands.ExecutionException;
import  org.eclipse.core.expressions.IEvaluationContext;
import  org.eclipse.ui.ISources;
import  org.eclipse.ui.handlers.HandlerUtil;
import  org.eclipse.ui.texteditor.ContentAssistAction;
import  org.eclipse.ui.texteditor.ITextEditor;

Dennis H´┐Żbner - Initial contribution and API
public class ContentAssistHandler extends AbstractHandler {
	public Object execute(ExecutionEvent eventthrows ExecutionException {
		// Due to an Handler ExtensionPoint declaration, we have an XtextEditor as Active
		// Editor so can just cast to an ITextEditor
		new ContentAssistAction(XtextUIMessages.getResourceBundle(), "ContentAssistProposal.",
				(ITextEditor) HandlerUtil.getActiveEditor(event)).run();
		return this;
	public void setEnabled(Object evaluationContext) {
		boolean contentAssistAvailable = false;
		if (evaluationContext instanceof IEvaluationContext) {
			Object var = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_EDITOR_NAME);
			if (var instanceof XtextEditor) {
				contentAssistAvailable = ((XtextEditorvar).isContentAssistAvailable();
		super.setBaseEnabled(isEnabled() & contentAssistAvailable);
New to GrepCode? Check out our FAQ X