NatTable cell selection provider - nattable

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.

Related

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...

EF- Replacing inheritance

I am using inheritance currently in EF and feel like it is causing more issues than it is helping, especially with binding an aggregation of tables to a datagrid. I have given a screen of part of the model. What I am trying to do is bind FREQUENCY to a datagrid, and have the grid fields be based on the type of FREQ_POOL(which is a base class). So for instance, if I want a POOL_IA datagrid, then it would have those fields, as well as the few fields in FREQUENCY. I was using inheritance because it made since from an OO perspective. The alternative is to just have lots of 0..1 relationships that show the ability for FREQ_POOL to have an extension, but then I have no constraint in place saying that FREQ_POOL can only be ONE type. What is a better design to accomplish this and make data binding easier? Thank you for any guidance.
One approach may be creating a data grid that gets the data from FREQ_POOL and then put all the variables of POOL_IA (or the all the properties of derived class using reflection) and FREQUENCY .
If you really don't need using objects while binding your data grid and able to use DataSet the another approach may be getting all the properties and the values of entry with Context.Entry method on the fly and put it into DataSet dynamically.

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.

How do I store arbitrary data in a GWT widget?

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.

One UITableView - Multiple DataSource, best design pattern?

This seems like a typical problem, but I have a UITableView that has identical behavior for two separate data sources. What is the best way of going about designing the class hierarchy to have as little duplication and if/else conditions? The view controller is going to do the same exact thing to both data sources, they're just unique in their data set. Should I have the parent controller just set its data source/respective title?
The same issue is relevant as well when using a UISegmentControl for displaying two views with the same interfaces, but different data sources.
Be careful with your terminology here. A UITableView has something called a dataSource but you seem to be referring, essentially, to two different sets of data.
In the case you're suggesting, in the table's dataSource (the object that adheres to the UITableViewDataSource protocol), I'd have three arrays.
currentlyViewedArray
datasetOneArray
datasetTwoArray
In the dataSource methods, use the currentlyViewedArray as the source of the table's data.
Then, set the currentlyViewedArray to whichever array you want to view:
self.currentlyViewedArray = self.datasetOneArray;
[theTableView reloadData];
You can use the UISegmentedControl to switch between the two arrays.