Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Altering/Restricting Xtext DSL Entry and Exit Rule
Altering/Restricting Xtext DSL Entry and Exit Rule [message #1729733] Mon, 18 April 2016 15:10 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member
Hi All,

I was wondering if you can guide me to an "easy way" to alter an xtext entry/exit rule at runtime.

Imagine we have:
RuleX: RuleA
RuleA: RuleB '+' RuleC

Now, when we have embedded editor in the diagram, we would like to edit only a part of the text. It is now possible with using styled text visible regions or xtextpartialeditor ! However, if I pass RuleB to the embedded editor, the user can start with changing the RuleB object and also go further and continue to set object of RuleC ! In the example above, if we pass RuleB object to embedded editor, if the user hits ctrl+space, he can see '+' in the content assistant and can then set the RuleC.

Now, my question is how to restrict the user to prevent going further than the passed rule. An example of this can be only editing an Event of a transition and don't let the user to go further and also set the transition Guard and Actions.


[Updated on: Mon, 18 April 2016 15:12]

Report message to a moderator

Re: Altering/Restricting Xtext DSL Entry and Exit Rule [message #1730578 is a reply to message #1729733] Tue, 26 April 2016 20:24 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member

have anybody tried some thing like this before ? Confused

Re: Altering/Restricting Xtext DSL Entry and Exit Rule [message #1730587 is a reply to message #1730578] Tue, 26 April 2016 22:31 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13466
Registered: July 2009
Senior Member

i have no idea on this. guess the basic idea is to do the same as is done for template proposals.
i did some digging and the following seems to work. maybe you can use it as starting point

( i cannot give you any further support on this)

package org.xtext.example.mydsl2.ui;

import javax.inject.Inject;

import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.ui.codetemplates.ui.partialEditing.IPartialEditingContentAssistContextFactory;
import org.eclipse.xtext.ui.codetemplates.ui.partialEditing.PartialEditingContentAssistContextFactory;
import org.eclipse.xtext.ui.editor.XtextSourceViewer;
import org.eclipse.xtext.ui.editor.contentassist.CompletionProposalComputer.State;
import org.eclipse.xtext.ui.editor.contentassist.antlr.DelegatingContentAssistContextFactory.StatefulFactory;
import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor;
import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory;
import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
import org.xtext.example.mydsl2.parser.antlr.MyDslParser;


public class ViewPart1 extends ViewPart {
	EmbeddedEditorFactory embeddedEditorFactory;
	PartialEditingContentAssistContextFactory fac;
	private Provider<StatefulFactory> statefulFactoryProvider;
	public Provider<? extends StatefulFactory> getStatefulFactoryProvider() {
		return statefulFactoryProvider;
	private EmbeddedEditor withParent;
	MyDslGrammarAccess ga;
	Provider<XtextResourceSet> rsp;

	public ViewPart1() {
		// TODO Auto-generated constructor stub
	static class RuleBParser extends MyDslParser {
		protected String getDefaultRuleName() {
			return "RuleB";
	Provider<RuleBParser> parserProvider;

	public void createPartControl(Composite parent) {
		IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {
			public XtextResource createResource() {
				XtextResourceSet rs = rsp.get();
				XtextResource r = (XtextResource) rs.createResource(URI.createURI("dummy.mydsl2"));
				return r;
		withParent = embeddedEditorFactory.newEditor(resourceProvider).withParent(parent);
		XtextSourceViewer viewer = withParent.getViewer();
		IContentAssistProcessor contentAssistProcessor = ((XtextSourceViewer)viewer).getContentAssistant().getContentAssistProcessor("__string");
		if (contentAssistProcessor instanceof State) {

	public void setFocus() {
		// TODO Auto-generated method stub



class MyDslUiModule extends AbstractMyDslUiModule {
	override bindContentAssistContext$Factory() {

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Serializing & case-insensitive languages (java.lang.RuntimeException: Could not serialize EObjec
Next Topic:Parse DSL instances into Resource without Eclipse application
Goto Forum:

Current Time: Wed May 27 09:56:42 GMT 2020

Powered by FUDForum. Page generated in 0.01971 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top