JTable - fire row changed when row deleted - java

In my system we use JTable with data model.
when data changes we remove it from the model, iterate the model and fire for each row listElementPropertyChanged (I think its intellij's). In this way removed lines are not deleted cause they are not in the model.
How do I refresh the whole table according to the model?

Simply use fireTableDataChanged(). This way, all listeners will now that all data may have changed.
However, use it with care, as usual behaviour for listeners will be to refresh the whole table.
You would have better using fireTableRowsDeleted(int, int) with the removed rows indexes.

Related

Scroll to Row with Pageable option in a List grid Smart gwt

I have a list grid which contains thousands of records. I can update any row in this list grid. After updating a row, I need to remain focus to the particular row.
From the RecordClickEvent, I take the index of the record. When I fetch the data again I've used below methods.
listGrid.selectRecord(recordIndex);
listGrid.scrollToRow(recordIndex);
If I update a record within first 75, it works nicely. How can I remain the focus, if I update a record not in first 75 records?
You must be doing something in your code that breaks this default behavior (of keeping focus on the edited record), because I have a paged editable ListGrid with close to 20.000 records, and when I update any record, I retain focus on the edited record without doing anything specific. Without looking at your code, it's not possible to know what can be wrong in your case, that focus is lost after updating one record.
Take a look at this particular demo for an example of what I mean regarding the default behavior.
By the way, what you are trying to do could be accomplished by loading your data page by page, until you get past the recordIndex, but take into consideration that this could be a very disconcerting user experience.

Linking an editable tableView to a database in javaFX

I'm working on a project for JavaFX and databasing practice (mostly I'm a beginner), where I have a unique class which holds records about concerts (name, location, date etc). I originally held these in an observable arraylist which populated a table view. From here the records could be editted, deleted or new ones added.
I am now storing these in a database using ORMLite and sqlite. This is so I can perform filtering on the data (ie show all events in a particular location) and then show this on the table.
My issue is that when I read in the data from the database I convert it to a ObservableArrayList so the table view can use it, but by creating the new array list my edit/new/delete buttons only effect this list and not the database. The problem is that every time I perform a query such as adding or deleting records to the database, it needs to re-produce the observableArrayList for the tableView which is taking around 5 seconds with ~250k records.
Is there a more efficient way to work with databases and javaFx tableViews?
Is there a more efficient way to work with databases and javaFx tableViews?
How about setting some sort of dirty flag on the records when you update certain fields and then go through your list of records and only make the DAO calls on those that are dirty? Maybe an enum with CREATE, DELETE, UPDATE, NONE.
Another idea would be to do your dao.update(...), dao.delete(...), or dao.create(...) calls whenever you update an record although you may want to do the chances all once time.
Last idea is to keep 4 arrays. One with the entire list, one for the new records, one for the dirty records, and one for the records to be deleted. You would add the records to the lists as edit/new/delete buttons are pressed and then at the end you can save them all at once.

Related to Auto-Update of JTable

I have two radiobuttons(Say rbtn_Asia,rbtn_Europe)and one JTable. When I select rbtn_Asia, table must contains Asia's data. Similarly when I select rbtn_Europe, table must contains Europe's data. (Asia's data and Europe's data is in same database which will be updated periodically). I have implemented upto this.
My problem is like this: Consider the following case: I have selected rbtn_Asia and obviously table will contain Asia's data. Now let database has got two new tuples of Asia, how can I update the JTable dynamically without selecting the rbtn_Asia once again (because rbtn_Asia is already in selected state).
In your button handler, update your implementation of TableModel, which should then fire the appropriate event. A structure that supports clear() such as Map, shown here, is convenient. More examples may be found here.

Auto-change TableModel based on Table view?

So I am working on a GUI that involves working with tables that can be sorted. I am noticing that when I sort a table, and I select a row from the newly sorted table, the selected row index of that row points to the data row from before the sort. I understand that this is because the view has changed, but the model has not; thus, you have the need for convertRowIndexToModel. It is also to my understanding that one can automatically update the view based on changes to the model by firing TableModelEvent's.
So here is my question: is it possible to automatically update the TableModel, based on changes to the view, so that I would not have to worry about converting the view index to table index?
All the default table code does this automatically so you don't need to worry about this. That is if you reference the model by using the table.getValueAt(...) and table.setValueAt(...) methods then you won't have a problem.
Only code that you write that tries to access the TableModel directly will have a problem. In this case thats what the convertXXX(...) methods are for.

Does SWT Table emit column created / removed events?

Skimmed through the Eclipse API doc and found no mentioning of this event. Could I have missed something? I'm building something that lists all table columns in a given table, and it needs to be automatically updated if the set of columns in the Table changes, so I need to listen to the Table structure changes and update my list accordingly.
What you are looking for doesn't exist. You could add dispose listeners to the TableColumns, and that could tell you when one is removed, but there are no events for telling you when widgets are created. You might be able to "fake it" by tracking control events on the table columns with TableColumn#addControlListener, but this is iffy. If you have control of the tables you could do something more advanced by wrapping them in a dynamic proxy that could perform that function for you.

Categories