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.

Thanks,
Bests,
Parsa

[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
Hi,

have anybody tried some thing like this before ? Confused

Thanks,
Parsa
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: 13186
Registered: July 2009
Senior Member
Hi,

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;
import org.xtext.example.mydsl2.services.MyDslGrammarAccess;

import com.google.inject.Provider;

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

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

	@Override
	public void createPartControl(Composite parent) {
		//getStatefulFactoryProvider().get().getDelegate().initializeFor(ga.getRuleBRule());
		IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {
			
			@Override
			public XtextResource createResource() {
				XtextResourceSet rs = rsp.get();
				XtextResource r = (XtextResource) rs.createResource(URI.createURI("dummy.mydsl2"));
				r.setParser(parserProvider.get());
				return r;
			}
		};
		withParent = embeddedEditorFactory.newEditor(resourceProvider).withParent(parent);
		XtextSourceViewer viewer = withParent.getViewer();
		IContentAssistProcessor contentAssistProcessor = ((XtextSourceViewer)viewer).getContentAssistant().getContentAssistProcessor("__string");
		if (contentAssistProcessor instanceof State) {
			((IPartialEditingContentAssistContextFactory)((State)contentAssistProcessor).getContextFactory()).initializeFor(ga.getRuleBRule());
		}
		withParent.createPartialEditor();
	}

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

	}

}

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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 Nov 13 01:51:47 GMT 2019

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

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

Back to the top