My question in its simplest form: Is it possible to determine the subset of items (or the indices of the corresponding items) currently being displayed in a JavaFX TableView?
The reason I'm asking is that I want to implement lazy loading. Therefore, I subclass ObservableList and implement the code that fetches new items from the database in the overriden E get(int index) (using prefetch/cache). However, the entity objects might be changed by the user and are therefore observed by the database backend. That's why I'd like to detach them as soon as they are not displayed any more.
Many thanks in advance for any suggestions.
You can use VirtualFlow to get the indizes of the first and the last visible cell: Scroll TableView via a Button
However, as I understood it, this is more a hack then a real part of the API. Also you might run into trouble if you have more tables around, it will be triggered each time a table changes.
Related
When changing the number of columns and rows of natTable
After clearing the column list of DataProvider, create a new column item and change the column item list of columnPropertyAccessor.
Then, put the new data model into the filter list and refresh it.
When the 7-column nattable is sorted (ascending or descending) and clicked, it is changed to a different data model (4 columns) as above, but if it is sorted, "CurrentModificationException" and "IndezxOutOfBoundException" occur.
If you exchange data models without sorting, there is no problem.
I don't know which part is causing it.
Is my way of replacing the filter list wrong when changing the data model?
If anyone has encountered a similar error and has solved it, please help.
Well you don't show how you are doing things, so I can't tell any details. But to answer your question, yes I think you are doing things wrong.
In short, if you have a state applied according to a column like sorting or filtering and you change the underlying data structure, things will break as the states does match the structure anymore. Not sure why you think this should work automatically.
If you change the underlying data structure you need to clear structure based states in advance.
There is an example in the NatTable examples application that shows how to change the data provider dynamically. Not sure if the example covers the clearing of states or if this is handled automatically when you are doing things correctly.
Suppose, I would like to implement data validation in JavaFX TableView.
Once user have changed data in the row, I would like to check it when user is trying to change current row number. Once data is correct, I would like to allow row change, once data is incorrect, I want to disallow this.
How to implement this?
Currently, I am trying to add a listener
getSelectionModel().selectedIndexProperty().addListener(indexFromTableToModel);
but any operations inside it causes bad table view behavior. Using
Platform.runLater
makes situation better, but still imperfect.
Is there a convenient place, to perform row data validation and perform different operation depending on it?
You can write your own selection model that can be locked (if current value is invalid). In that case the model won't change the internal selected index.
In my java application, I have a dropdown box which needs to be populated with values from a table games.
There is a separate functionality to add a game. (i:e. an insert in the table games)
The values of the dropdown wont be changing unless someone adds something in the database.
To develop the functionality to populate the dropdown box,
One way is to -
Hit the table everytime a page load happens and fetch the data to populate the dropdown.
Is this an effective way? Can someone suggest me a better alternative design?
You could use a cache... everytime a game is added you simply update your cache.
Implementing a cache is simple.
If inserting data and retrieving it for the dropdown are performed in the same java application, then we might implement a kind of cache for the list of values.
So, we need a structure to store last list of games fetched from database, for example List<Game>, and a flag that is essentially an indicator for the event "someone added row to database".
Each time the page with dropdown is requested, we first check the indicator - if it is true, then we need to reload the list from database and set it back to false, if it is false - we can return the cached list.
Each time user adds entry to database, we set this indicator to true.
Also please be advised of possible concurrency problems when implementing that kind of cache.
This a variant for the classic "wait rpc call problem" in GWT.
I have done a complete CRUD screen in GWT, calling RPC to atack an Oracle database. It has one panel for the search criteria and the results table, and other for the detail fields. I swap the visiblity of both as i need to.
The results table is a CellTable and i call the "setVisibleRangeAndClearData" method to get the table populated, which that takes care for paging, column sort and so on (for example when i come back from an update RPC call i keep the range i came from).
I use to make the "synchro" by putting the "after code" in the "onSuccess" block of the RPC call (i.e. swaping the panels), but when calling "setVisibleRangeAndClearData", the cellTable by itself launches another RPC call to get new data which is out of my control. So, what happens is that i swap the panels (wich is immediate) and after that, the user sees the table data update, which is ugly.
So the question is: How can i control that? How can i wait or get called when the "setVisibleRangeAndClearData" is finisehd?
Thanks in advance,
David
Showing the table right away and then populating it with data is not ugly - in fact, it's the right solution from a UI perspective. Users expect immediate result of their actions, and showing them a loading indicator immediately after they press the button is the right approach.
CellTable has two methods you may find useful:
setLoadingIndicator() - your table should display it until the data arrives;
onLoadingStatusChange().
I am using Entity bean in NetBeans, to develop some master/detail forms. When I run the forms, I click the Delete JButton, and the row dissapears from the JTable.
But when I click on "Reload", the supposedly deleted row shows up again. I don't know why is this happening; why does the Entity doesn't erase all the way to the database table, and just deletes it out of the JTable?
This sort of issue sounds like it's related to the separation of the data (the model) from the view. I don't have specific knowledge regarding your technologies used, but hopefully I can provide some insight into what is the root of your problem.
In your case, it sounds like when you "Delete" you're only removing it from the view; you're not actually manipulating the data in any way (i.e. the model is not aware of this deletion).
Therefore once you "Reload" - which usually means that the view asks the model for what data to present - your "deletion" is lost since the model hasn't changed at all, and thus provides the exact same data to the view.
This sort of behavior is likely to occur when you're manipulating the data (i.e. deleting things) via the JTree itself or even the contained TreeNode objects, rather than the underlying TreeModel.
Hopefully this information helps you, sorry I don't have a more specific answer.
The JTable when reloaded, brought the record deleted because it had a foreign key link and couldn't deleted it at database level.