Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Finding model from widget
Finding model from widget [message #526029] Thu, 08 April 2010 14:49 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
I have a TableView connected with a *very* simple model (just an EList
of EObjects with an handful of string fields each).

-------------------------------------------
/**
* @model
*/
public interface IQuotations extends EObject {
/**
* @model containment="true"
*/
EList<IQuotation> getQuotation();
}
-------------------------------------------
/**
* @model
*/
public interface IQuotation extends EObject {
/**
* @model
*/
String getName();
/**
* @model
*/
String getHead();
/**
* @model
*/
String getTail();
/**
* @model
*/
String getTexHead();
/**
* @model
*/
String getTexTail();
/**
* @model
*/
String getColor();
/**
* @model
*/
String getFont();
}
-------------------------------------------

Here is how I do the binding:

-------------------------------------------
DataBindingContext bindingContext = new DataBindingContext();

ObservableListContentProvider listContentProvider = new
ObservableListContentProvider();
tViewer.setContentProvider(listContentProvider);

IObservableMap[] observeMaps =
EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
EStructuralFeature[]{Literals.IQUOTATION__HEAD,
Literals.IQUOTATION__TAIL, Literals.IQUOTATION__TEX_HEAD,
Literals.IQUOTATION__TEX_TAIL});
tViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));

IObservableList iquotationsQuotationObserveList =
EMFObservables.observeList(Realm.getDefault(), getQuotations(),
Literals.IQUOTATIONS__QUOTATION);
tViewer.setInput(iquotationsQuotationObserveList);
-------------------------------------------

Notice the model has a few more fields than the columns in the table.

I want to build a dialog to edit *all* the fields of the selected row in
the table.

Obviously the SelectionEvent returns the TableItem an knows nothing
about the model.

Is there an easy way to "revert" the binding?
I need to do something like:

-------------------------------------------
private IQuotation selectedQuotation;
....
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.item instanceof TableItem) {
TableItem ti = (TableItem) e.item;
selectedQuotation = doTheRightThing(ti);
}
}
});
-------------------------------------------

Then I could edit the model as needed.
I would like to avoid scanning the model to find the matching entry, if
possible.

Is there a better way to do this?

Thanks in Advance
Mauro
Re: Finding model from widget [message #526041 is a reply to message #526029] Thu, 08 April 2010 14:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mauro,

You should be taking advantage of the fact that a TableViewer is an
ISelectionProvider.


Mauro Condarelli wrote:
> Hi,
> I have a TableView connected with a *very* simple model (just an EList
> of EObjects with an handful of string fields each).
>
> -------------------------------------------
> /**
> * @model
> */
> public interface IQuotations extends EObject {
> /**
> * @model containment="true"
> */
> EList<IQuotation> getQuotation();
> }
> -------------------------------------------
> /**
> * @model
> */
> public interface IQuotation extends EObject {
> /**
> * @model
> */
> String getName();
> /**
> * @model
> */
> String getHead();
> /**
> * @model
> */
> String getTail();
> /**
> * @model
> */
> String getTexHead();
> /**
> * @model
> */
> String getTexTail();
> /**
> * @model
> */
> String getColor();
> /**
> * @model
> */
> String getFont();
> }
> -------------------------------------------
>
> Here is how I do the binding:
>
> -------------------------------------------
> DataBindingContext bindingContext = new DataBindingContext();
>
> ObservableListContentProvider listContentProvider = new
> ObservableListContentProvider();
> tViewer.setContentProvider(listContentProvider);
>
> IObservableMap[] observeMaps =
> EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
> EStructuralFeature[]{Literals.IQUOTATION__HEAD,
> Literals.IQUOTATION__TAIL, Literals.IQUOTATION__TEX_HEAD,
> Literals.IQUOTATION__TEX_TAIL});
> tViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
>
> IObservableList iquotationsQuotationObserveList =
> EMFObservables.observeList(Realm.getDefault(), getQuotations(),
> Literals.IQUOTATIONS__QUOTATION);
> tViewer.setInput(iquotationsQuotationObserveList);
> -------------------------------------------
>
> Notice the model has a few more fields than the columns in the table.
>
> I want to build a dialog to edit *all* the fields of the selected row
> in the table.
>
> Obviously the SelectionEvent returns the TableItem an knows nothing
> about the model.
>
> Is there an easy way to "revert" the binding?
> I need to do something like:
>
> -------------------------------------------
> private IQuotation selectedQuotation;
> ...
> table.addSelectionListener(new SelectionAdapter() {
> @Override
> public void widgetSelected(SelectionEvent e) {
> if (e.item instanceof TableItem) {
> TableItem ti = (TableItem) e.item;
> selectedQuotation = doTheRightThing(ti);
> }
> }
> });
> -------------------------------------------
>
> Then I could edit the model as needed.
> I would like to avoid scanning the model to find the matching entry,
> if possible.
>
> Is there a better way to do this?
>
> Thanks in Advance
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Finding model from widget [message #526042 is a reply to message #526029] Thu, 08 April 2010 15:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Why not using attaching a selection listener on the viewer? Besides that
TableItem#getElement() gives you the Domain-Object. But you are better
of using a SelectionChangeListener on the viewer.

Tom

Am 08.04.10 16:49, schrieb Mauro Condarelli:
> Hi,
> I have a TableView connected with a *very* simple model (just an EList
> of EObjects with an handful of string fields each).
>
> -------------------------------------------
> /**
> * @model
> */
> public interface IQuotations extends EObject {
> /**
> * @model containment="true"
> */
> EList<IQuotation> getQuotation();
> }
> -------------------------------------------
> /**
> * @model
> */
> public interface IQuotation extends EObject {
> /**
> * @model
> */
> String getName();
> /**
> * @model
> */
> String getHead();
> /**
> * @model
> */
> String getTail();
> /**
> * @model
> */
> String getTexHead();
> /**
> * @model
> */
> String getTexTail();
> /**
> * @model
> */
> String getColor();
> /**
> * @model
> */
> String getFont();
> }
> -------------------------------------------
>
> Here is how I do the binding:
>
> -------------------------------------------
> DataBindingContext bindingContext = new DataBindingContext();
>
> ObservableListContentProvider listContentProvider = new
> ObservableListContentProvider();
> tViewer.setContentProvider(listContentProvider);
>
> IObservableMap[] observeMaps =
> EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
> EStructuralFeature[]{Literals.IQUOTATION__HEAD,
> Literals.IQUOTATION__TAIL, Literals.IQUOTATION__TEX_HEAD,
> Literals.IQUOTATION__TEX_TAIL});
> tViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
>
> IObservableList iquotationsQuotationObserveList =
> EMFObservables.observeList(Realm.getDefault(), getQuotations(),
> Literals.IQUOTATIONS__QUOTATION);
> tViewer.setInput(iquotationsQuotationObserveList);
> -------------------------------------------
>
> Notice the model has a few more fields than the columns in the table.
>
> I want to build a dialog to edit *all* the fields of the selected row in
> the table.
>
> Obviously the SelectionEvent returns the TableItem an knows nothing
> about the model.
>
> Is there an easy way to "revert" the binding?
> I need to do something like:
>
> -------------------------------------------
> private IQuotation selectedQuotation;
> ...
> table.addSelectionListener(new SelectionAdapter() {
> @Override
> public void widgetSelected(SelectionEvent e) {
> if (e.item instanceof TableItem) {
> TableItem ti = (TableItem) e.item;
> selectedQuotation = doTheRightThing(ti);
> }
> }
> });
> -------------------------------------------
>
> Then I could edit the model as needed.
> I would like to avoid scanning the model to find the matching entry, if
> possible.
>
> Is there a better way to do this?
>
> Thanks in Advance
> Mauro
Re: Finding model from widget [message #526390 is a reply to message #526042] Sat, 10 April 2010 07:30 Go to previous message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
On 08/04/2010 17.01, Tom Schindl wrote:
> Why not using attaching a selection listener on the viewer? Besides that
> TableItem#getElement() gives you the Domain-Object. But you are better
> of using a SelectionChangeListener on the viewer.
>
> Tom
>
Thanks.

The information I was missing is SelectionChangeListener will provide
the EObject (actually the XxxImpl) out of the box and that
TableItem.data holds the same EObject.
The debugger showed me :)
I moved to SelectionChangeListener.

Thanks again.
Mauro
Previous Topic:EMF Compare merger bug
Next Topic:[OCLinEcore] Calling operations within constraints
Goto Forum:
  


Current Time: Fri Apr 26 20:57:08 GMT 2024

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

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

Back to the top