XText 2.4 - 2.5: How to pass information from a AbstractDeclarativeValidator to a ViewPart [message #1262088] |
Mon, 03 March 2014 08:50 |
J A 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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03219 seconds