|
Re: Finding model from widget [message #526041 is a reply to message #526029] |
Thu, 08 April 2010 14:59 |
Ed Merks 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 |
Thomas Schindl 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03146 seconds