How do I store arbitrary data in a GWT widget? - gwt

I'm creating a table using GWT, and in certain cells of the table, I want to store a piece of data in that cell's Widget for use in the Widget's handler callback. I can't seem to find an API method such as widget.setData(key, value);. How do I (or can I) accomplish this?

You could subclass the widget you want - and add the appropriate members and get/set methods.
The table example may be better served by storing the object inside a button instance, i.e an 'Edit' button.
Alternatively, you could maintain a map of objects that relate to each row index. This would save creating a lot of unnecessary widgets.

Related

flutter, provider and data tables

I'm looking for a way to create a data table with flutter driven by the provider package. But whatever I try with Table() or DataTable() I can't make it happen to connect to a ChangeNotificationProvider.
Both TableRow and DataRaw are not widgets I can connect to the provider.
I want to achieve a way to the each object from my business model connected to a row in the table.
When a value is changing I don't want to rebuild the whole table (that I could achieve with DateTable). I want to update only the relevant cells and keep the scroll position.
Any hint ? All the samples I could find or build are not really useful for reality.

How to do "in-place editing" of a JFace Table?

In WPF (.net), when a DataGrid is made editable and set to an observable collection, there is a placeholder row. When one clicks on it, a new element is added to the backing collection and the table is put into edit mode.
Is something like this possible with JFace Table Viewers as well?
The only solution I can think of is to create a custom observable list that delegates to the "real" list I want to observe, but always adds an additional placeholder object to the end, which gets inserted into the "real" list as soon as it is edited. But that seems a bit hackish to me...

NatTable cell selection provider

Although NatTable already has a class RowSelectionProvider, my data is provided through cells, not rows, so I cannot use this class. Is it possible to create a class CellSelectionProvider, or it would be too difficult?
What I want to do is select a cell in the NatTable, which is linked to an EObject. Then select the EObject in the editor and show its properties in the properties view. The first part I'm able to do, but not the second.
I've seen some tutorials about how connect to the properties view using JFace viewers as the selection provider, but nothing related to NatTable.
The ISelectionProvider interface specifies a getSelection() and a setSelection() method. The selection in NatTable is implemented via the SelectionLayer. While it should be quite easy to implement getSelection() based on the SelectionLayer it could become quite difficult to implement setSelection() in a general way. Since you are working with a model based approach it is maybe possible for you to get the cell coordinates for the element that is sent via an ISelection to correctly implement setSelection(), but typically this is not possible as the same value in a column can be set for multiple rows.
Maybe you also don't need setSelection() and you can implement it empty as you only want to provide a selection to the properties view. But that also depends on your use case and what you want to achieve in whole.

GWT SelectionModel in Cell widgets - setSelected by key?

Is there any way to select items by key with GWT's selection model? setSelected only seems to take an object from which it can derive a Key, but using that function means I have to construct a sort of fake object. If my KeyProvider ever changes, that part of my code could break without my knowledge, so I'd like to just construct a key directly somehow.
"I have a celltable that shows a list of entities. When the user creates a new entity, I want to refresh the list (which will have the new entity) and automatically select the new entity."
I have this behaviour in my app as well. I manipulate the ListDataProvider. I find the item or items of interest, move them to the top of the list, call the selection model to set them to selected, and refresh the attached data displays. I use the same approach for picklist tables I use when I want to pre-select the default choices for the user (usually based on the item that is spawning the picklist) and move them to the top of the list. I spent a lot of time looking through the selection model api and there is nothing for keys. I suspect that the GWT designers figured it wasn't necessary, since you have access to the ListDataProvider. Find the items of interest there and then call the selection model select method on those specific objects. I can see their point -- replicating the functionality in ListDataProvider and SelectionModel would blur the distinction between the two classes, and perhaps limit the reusability of the SelectionModel construction in other (future) data structures that don't use keys.

Best approach to control access/handle objects/models data passed to View in Zend Framework

I want to pass data to views, and I've two options in my mind (if you know a better approach, please mention).
I am using Zend_Based ORM system, and coded in a way that if I add a new field in database, its automatically available within the model.
1st: I convert the model's data into array and pass the array to the view. This way I will have all the data available within the view, but model's function/operations will not be available. And incase I need specific functionality, i will be coding view helpers while there are chances that the same functionality is already coded within model. e.g. a getting a date in specific format.
2nd: Or I pass the complete model object to the view, this way I will have all the model's functions available, but view will be able to access model's save function which is a bad thing. I can add some more functionality within model to make it read-only, but it will be extra work.
any suggestions which approach is better.
According to the MVC principle it's perfectly fine to let the View allow access to the Model. So, pass the complete Model to the View.
By the way, passing arrays around will copy your data (by value), while passing objects around will not (by reference). (Assuming PHP5). Large arrays might affect your performance.