Finding model from widget [message #526029] |
Thu, 08 April 2010 10:49  |
Eclipse User |
|
|
|
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 10:59   |
Eclipse User |
|
|
|
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
|
|
|
Re: Finding model from widget [message #526042 is a reply to message #526029] |
Thu, 08 April 2010 11:01   |
Eclipse User |
|
|
|
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 03:30  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.06366 seconds