Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText 2.4 - 2.5: How to pass information from a AbstractDeclarativeValidator to a ViewPart
XText 2.4 - 2.5: How to pass information from a AbstractDeclarativeValidator to a ViewPart [message #1262088] Mon, 03 March 2014 08:50 Go to next message
J A is currently offline J AFriend
Messages: 31
Registered: July 2013
Member
Dear forum,

With Xtext 2.5.2 (but maybe also with older Xtext like 2.4.2) I can now do validation inside the text editor of my model, but I also want to do the same validation in a visual GUI add-in to that text editor. The idea of this extra visual GUI is for user to use mouse instead of keyboard when he/she wants to.

Now, inside the text editor I have some logic to validate on name uniqueness of things, and the question is how to use that same logic in de visual GUI for another name validation.

Details:


I have a class MyValidator to do validation, in which I store information to a global variable GlobalVariableABC.

public class MyValidator extends org.eclipse.xtext.validation.AbstractDeclarativeValidator
{
	/**
	 * Validates something here
	 * 
	 */
	@Check(CheckType.FAST)
	public void checkSomething(SomeClass someParam)
	{
            //[1] Calculate something, store to a global variable GlobalVariableABC
        }
}


In the visual GUI, I have a MyViewPart, and I would like to have access to GlobalVariableABC here.


public class MyViewPart extends org.eclipse.ui.part.ViewPart implements ISelectionListener, IEditingDomainProvider
{

        // This would be called when the user clicks onto the text editor of org.eclipse.xtext.ui.editor.XtextEditor
	@Override
	public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection)
	{
                //[2] Wish to be able to read from GlobalVariableABC here

		if (!selection.isEmpty() && (sourcepart instanceof XtextEditor))
		{
			xtextEditor = (XtextEditor) sourcepart;
			URI resourceURI = EditUIUtil.getURI(xtextEditor.getEditorInput());
			AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(adapterFactory, new BasicCommandStack(), new HashMap<Resource, Boolean>()));

			org.eclipse.emf.ecore.resource.Resource resource = null;
			try
			{
				resource = editingDomain.getResourceSet().getResource(resourceURI, true);
			}
			catch (Exception e)
			{
				resource = editingDomain.getResourceSet().getResource(resourceURI, false);
			}

			org.eclipse.emf.ecore.resource.ResourceSet resourceSet = getEditingDomain().getResourceSet();
		}
	}

	@Override
	public void createPartControl(Composite parent)
	{
		// Register selection service listener
		getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
        }
}


Could you recommend the way to achieve this ?

GlobalVariableABC is only a figure of speech, actually I am happy with anyway to pass information from the derived class of AbstractDeclarativeValidator to that derived class of ViewPart.

Thanks a lot

[Updated on: Mon, 03 March 2014 09:14]

Report message to a moderator

Re: XText 2.4 - 2.5: How to pass information from a AbstractDeclarativeValidator to a ViewPart [message #1265627 is a reply to message #1262088] Thu, 06 March 2014 10:30 Go to previous messageGo to next message
J A is currently offline J AFriend
Messages: 31
Registered: July 2013
Member
Does it seem that this question is irrelevant, or too specific, or too difficult ?
Help please!
Tnkx

[Updated on: Thu, 06 March 2014 10:30]

Report message to a moderator

Re: XText 2.4 - 2.5: How to pass information from a AbstractDeclarativeValidator to a ViewPart [message #1265636 is a reply to message #1265627] Thu, 06 March 2014 10:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
did you have a look at the docs Validating Manually.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText 2.4 - 2.5: How to pass information from a AbstractDeclarativeValidator to a ViewPart [message #1270711 is a reply to message #1265636] Thu, 13 March 2014 11:09 Go to previous message
J A is currently offline J AFriend
Messages: 31
Registered: July 2013
Member
Hi Christian,

Sorry for a late reply. I did not know that this got answered.

It seems to work toward the direction I want, thanks.
Previous Topic:Multiple output configurations to separate API and Impl code
Next Topic:Building org.eclipse.xtext.xbase from source
Goto Forum:
  


Current Time: Tue Apr 23 16:04:26 GMT 2024

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

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

Back to the top