Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » TableViewer of EMF object with calculated column?
TableViewer of EMF object with calculated column? [message #1828601] Sun, 14 June 2020 13:29 Go to next message
Jens Bürger is currently offline Jens BürgerFriend
Messages: 55
Registered: October 2012
Member
Hi all,

I want to display data from an EMF model in a TableViewer. Apart from the data coming directly from the model, I want to have an additional column with data that is calculated.
I am using data binding.
For exemplifing reasons, assume that I have an EMF model for project management, with projects having a title and a deadline.
The code I use to set up the TableViewer's data and prepare the databinding is as follows:
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
IObservableMap[] observeMaps = EMFObservables.observeMaps(listContentProvider.getKnownElements(), new EStructuralFeature[]{Literals.PROJECT__TITLE, Literals.PROJECT__DEADLINE});
tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
tableViewer.setContentProvider(listContentProvider);

IObservableList observeList = EMFObservables.observeList(Realm.getDefault(), projectData, Literals.PROJECT__PROJECTS);
tableViewer.setInput(observeList);


Now, I want a TableViewer listing the projects, their deadlines, and have a third column "days remaining". The values for this column shall be calculated.

So, what is the way to go to realize this? Hints are appreciated :)

[Updated on: Sun, 14 June 2020 16:59]

Report message to a moderator

Re: TableViewer of EMF object with calculated column? [message #1828608 is a reply to message #1828601] Mon, 15 June 2020 05:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I hate to admit it, but I'm not very familiar with how data binding is used in practice. I don't want to suggest that "polluting" the model with stuff needed only for a particular view is a good practice, but certain you could define an EAttribute in the model, mark it volatile, transient, derived, and then just use it. Of course it must be possible to define a property directly via the data binding APIs that accomplishes the same effect. Perhaps someone else with experience using these in practice will have a practical answer for how to do that without modifying the model...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: TableViewer of EMF object with calculated column? [message #1828610 is a reply to message #1828608] Mon, 15 June 2020 06:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

For a specific problem you might:

a) set up a custom metamodel with an M2M to populate it
b) create a derived metamodel with derived classes with extra attributes, and an ECopier tweak to populate it by converting every XXXX class instance to its DerivedXXXX instance.

For a more generic problem you could install a 'TableViewerColumn'Adapter (via eAdapters) in each object that needs extra info.

Regards

Ed Willink
Re: TableViewer of EMF object with calculated column? [message #1828660 is a reply to message #1828610] Tue, 16 June 2020 07:18 Go to previous messageGo to next message
Jens Bürger is currently offline Jens BürgerFriend
Messages: 55
Registered: October 2012
Member
Thanks for your answers!

I think, it is a more generic problem since, in different parts of the application I will need various kinds of calculated values in tables.
Where can I get information on how to build such an adapter? I have never used eAdapters before.

As far as I can understand, I would need to add my adapter to all EObjects that are relevant for me to (re-)calculate the values. So, regarding my example
Literals.PROJECT__DEADLINE.eAdapters().add(myAdapter);

But how to get my additional data into the input for the TableViewer?
Re: TableViewer of EMF object with calculated column? [message #1828687 is a reply to message #1828660] Tue, 16 June 2020 15:36 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Adapters are one of the many extensibility mechanisms of EMF. You will find numerous examples which is usually the best way to learn. Find References, Type Hierarchy and the debugger are all good friends.

In the absence of someone who knows about TableViewer looking at examples is your best bet,.

Regards

Ed Willink
Previous Topic:Is there a way to delete the data EList (Xcore) from my tableviewer faster?
Next Topic:Split Ecore model over different repos
Goto Forum:
  


Current Time: Thu Apr 25 05:11:44 GMT 2024

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

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

Back to the top