Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Forms] How to programmatically access widget's properties
[EMF Forms] How to programmatically access widget's properties [message #1695168] Tue, 12 May 2015 12:44 Go to next message
Volker Fervers is currently offline Volker FerversFriend
Messages: 14
Registered: March 2015
Junior Member
Hello!

I'm trying to become familiar with EMF/ECP/EMF Forms. I read in a file with XMI data (ComposedAdapterFactory, BasicCommandStack, ResourceSet, AdapterFactoryEditingDomain, Resource) to display a tree with the data in a Part. Clicking on an EObject of the Tree transfers this selection via the selectionService to another Part, where I show the properties powered by EMF Forms:

final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(ViewProviderHelper.getView(eObj, null), eObj, new DefaultReferenceService());

ECPSWTViewRenderer.INSTANCE.render(content, vmc);


Now I can alter the properties in the created UI. My question is:

How can I programatically access these (altered) properties?

The tutorial "EMF Forms: A Question of Effort" states in Paragraph "Faster?" : "In the case of EMF Forms, the renderer takes over this task. Controls are not only bound to the data model, they also provide additional functionality". So I'm quite sure, that there must be a way to read and store the changes Smile.

Thanks for your time!
GV
Re: [EMF Forms] How to programmatically access widget's properties [message #1695266 is a reply to message #1695168] Wed, 13 May 2015 07:06 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,

I am not sure, if I understand the question correctly. By default, the
changes are directly written to the data model.

Best regards

Jonas

Am 12.05.2015 um 14:44 schrieb Volker Fervers:
> Hello!
>
> I'm trying to become familiar with EMF/ECP/EMF Forms. I read in a file
> with XMI data (ComposedAdapterFactory, BasicCommandStack, ResourceSet,
> AdapterFactoryEditingDomain, Resource) to display a tree with the data
> in a Part. Clicking on an EObject of the Tree transfers this selection
> via the selectionService to another Part, where I show the properties
> powered by EMF Forms:
>
>
> final ViewModelContext vmc =
> ViewModelContextFactory.INSTANCE.createViewModelContext(ViewProviderHelper.getView(eObj,
> null), eObj, new DefaultReferenceService());
>
> ECPSWTViewRenderer.INSTANCE.render(content, vmc);
>
>
> Now I can alter the properties in the created UI. My question is:
>
> How can I programatically access these (altered) properties?
>
> The tutorial "EMF Forms: A Question of Effort" states in Paragraph
> "Faster?" : "In the case of EMF Forms, the renderer takes over this
> task. Controls are not only bound to the data model, they also provide
> additional functionality". So I'm quite sure, that there must be a way
> to read and store the changes :).
>
> Thanks for your time!
> GV


--
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [EMF Forms] How to programmatically access widget's properties [message #1695288 is a reply to message #1695266] Wed, 13 May 2015 11:13 Go to previous messageGo to next message
Volker Fervers is currently offline Volker FerversFriend
Messages: 14
Registered: March 2015
Junior Member
Hello!

Sorry if my question was unclear.

The UI displays the properties of an EObject, i.e. a Person's name. Now I change that name.
What are the names of the class and the method to access the new name?

TIA!
GV
Re: [EMF Forms] How to programmatically access widget's properties [message #1695609 is a reply to message #1695288] Mon, 18 May 2015 05:36 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,

you can directly access the EObject, it holds the new name.

Best regards

Jonas

Am 13.05.2015 um 13:13 schrieb Volker Fervers:
> Hello!
>
> Sorry if my question was unclear.
>
> The UI displays the properties of an EObject, i.e. a Person's name. Now
> I change that name.
> What are the names of the class and the method to access the new name?
>
> TIA!
> GV


--
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [EMF Forms] How to programmatically access widget's properties [message #1696675 is a reply to message #1695609] Wed, 27 May 2015 19:59 Go to previous messageGo to next message
Volker Fervers is currently offline Volker FerversFriend
Messages: 14
Registered: March 2015
Junior Member
Hello again .*!

Neither the EObject nor the resource as a whole reflect the changes. The corresponding setName-Methods of the altered objects are not called on focus lost of the input fields which they do when I don't use an XMI file as data source but create a dummy object.

Obviously I'm doing something wrong. Sadly searching the web didn't let me find an example known to work.

Thank you for your help!
GV


My EMF initializing code goes as follows:
private EMFInit() {

	PhiPackage.eINSTANCE.eClass();

	caf = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
	caf.addAdapterFactory(new ResourceItemProviderAdapterFactory());
	caf.addAdapterFactory(new PhiItemProviderAdapterFactory());
	caf.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

	bcs = new BasicCommandStack();

	rs = new ResourceSetImpl();
	rs.getPackageRegistry().put(PhiPackage.eNS_URI, PhiPackage.eINSTANCE);
	rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
		Resource.Factory.Registry.DEFAULT_EXTENSION,
		new XMIResourceFactoryImpl());

	ed = new AdapterFactoryEditingDomain(caf, bcs, rs);

	r = ed.createResource("file:///home/volker/.data/data.phi");

	try {
		r.load(null);

	} catch (final IOException ex) {
		// TODO Auto-generated catch block
		ex.printStackTrace();
	}
}


The TreeViewer's relevant code (Tree in a left part, form on the right):
public void init() {
	final EMFInit emfInit = EMFInit.getInstance();
	final ComposedAdapterFactory caf = emfInit.getComposedAdapterFactory();
	final Resource r = emfInit.getResource();

	setContentProvider(new AdapterFactoryContentProvider(caf));
	setLabelProvider(new AdapterFactoryLabelProvider(caf));

	final Organisation eObj = (Organisation) r.getContents().get(0);
	setInput(eObj);
	}


And the FormPart:
@Inject
public void receiveSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) EObject eObj) {

	if (eObj != null) {

		eventBroker.post("Phi/selectedEObject", eObj);

		// final Person p = PhiFactory.eINSTANCE.createPerson();
		// p.setVorname("Johann");
		// eObj = p;

		for (final Control c : content.getChildren()) {
			c.dispose();
		}

		try {
			final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(
				ViewProviderHelper.getView(eObj, null),
				eObj,
				new DefaultReferenceService());
			ECPSWTViewRenderer.INSTANCE.render(content, vmc);

			content.layout();

		} catch (final ECPRendererException ex) {
			ex.printStackTrace();
		}

		content.getParent().layout();
	}
}
Re: [EMF Forms] How to programmatically access widget's properties [message #1696739 is a reply to message #1695168] Thu, 28 May 2015 10:11 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 161
Registered: May 2015
Senior Member
Hi Volker,
The code seems to be valid.
Can you provide an example projects, which we could use to reproduce the error?

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [EMF Forms] How to programmatically access widget's properties [message #1696764 is a reply to message #1695168] Thu, 28 May 2015 13:06 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 63
Registered: March 2012
Member
Hi Volker,
the code you provided seems to be valid.
Can you provide a project which can be used to reproduce the error?

Cheers,
Eugen
Re: [EMF Forms] How to programmatically access widget's properties [message #1696956 is a reply to message #1696764] Fri, 29 May 2015 17:33 Go to previous messageGo to next message
Volker Fervers is currently offline Volker FerversFriend
Messages: 14
Registered: March 2015
Junior Member
Hello Eugen!

Thank you. You can find the zipped project(s) attached.

Projects:
- emfeugen: model
- .app: e4 app
- .edit
- .editor
- .feat: product's feature

(File \ Import \ General \ Archive \ projects into ws ...)

The EMFForm is displayed in
emfeugen.app \ src \ enfeugen.app.parts \ FormPart.java # receiveSelection(...)

where you can comment in the online creation of an eObject which is altered on focus out.

I sysout'ed old- and newName in
emfeugen \ emfeugen.impl \ Person.impl # setName(...)

to see when the attribute's change occurs.


Thanks for your help!
GV
  • Attachment: emfeugen.zip
    (Size: 146.48KB, Downloaded 80 times)
Re: [EMF Forms] How to programmatically access widget's properties [message #1697387 is a reply to message #1696956] Wed, 03 June 2015 14:18 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 161
Registered: May 2015
Senior Member
Hi Volker,
I looked at your code.
You are missing one small line in the constructor of the EMFInit class:
rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(ed));

Add this before creating the resource.

You can find an explanation here: https://www.eclipse.org/forums/index.php/t/521251/

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
[solved] Re: [EMF Forms] How to programmatically access widget's properties [message #1698063 is a reply to message #1697387] Wed, 10 June 2015 18:01 Go to previous message
Volker Fervers is currently offline Volker FerversFriend
Messages: 14
Registered: March 2015
Junior Member
Thank you very much! Smile
Works exactly as I hoped.

GV
Previous Topic:Can't find "initialize ecore diagram file"
Next Topic:[EMF Edit] Browser/Session dependent localization
Goto Forum:
  


Current Time: Sun Jul 05 11:59:36 GMT 2020

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

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

Back to the top