Refresh only one column/cell from a SWT / JFace TableViewer - eclipse

I currently have a big table (aprox 1000 rows) and about 20 columns. Out of the 20 columns I need one to be refreshed once every 2-3 seconds ( holds elapsed time from the object creation ) , i have tried this by refreshing the whole table every 3 seconds but because of so many rows it is a big performance penalty this whole table refresh.
Anyone seen a way to refresh only one cell / one column in JFace tableviewer ?? I need that one elapsed time column refresh and that's it.
Any help is greatly appreciated.
Thanks
Mircea

I see TableViewer didn't expect to refresh just one cell in a row.
AbstractTableViewer
protected void doUpdateItem(Widget widget, Object element, boolean fullMap)
you need to override the above method. Current implementation refreshes the entire row ( basically invokes LabelProvider on each cell)
you can follow the same implementation but invoke update on specific ViewerCell

The TableViewer's refresh() method is meant to be triggered when the list of objects that represents the model for the rows of your table is changed. If you only need to update the text or image shown in a particular row or cell, you should use the update() method. There are variants of that method to let you update as little or us much as necessary.

Related

Reducing the amount of time that it takes to do date calculations

I am running the following code in cellForRow that does an on-the-fly date calculation. After seeing some stuttering whilst scrolling, I ran a Time Profiler while replicating the stuttering and determined that this bit of my code is the issue. As far as I am aware, this is the best way to accomplish getting a double for difference in number of days and then converting to number of years? Any suggestions on how to reduce the amount of time this takes to hopefully improve scrolling?
Provide default value and then use a completion handler to detect when the calculation is finished. then use reload rows at indexpath. That will let the user scroll and calculate the value in the background. And once the value is calculated, it will reload the cell to show the final value.
Date Formatters are always a heavy task to perform. If we are performing inside the table view cell then we will face scrolling issue with the table view. Approach for better performances using table view cell + Date formatters is to provide final data values to table view cell subview components. Data decoration should be done prior to assigning values to the table view cell.
Instead of using Dictionary use struct to provide data to cell. While initializing model classes all date formatters work should be done.
Now model class array will be passed to table view to render table.

Iterating all rows and changing a specific value ends up in a disappearing table

I have following problem: I have a small application running where i have implementes a language switching function. Therefore i need to change the datetime columns in footable for the right date format.
My idea was to iterate through all rows, get the date value, recalculate it in the right format and write it back to the table. But This approach is not working properly, when i try it, you can see the very first row changing, and then the whole table disappears. I have attached some screen shots and the relevant code to explain the problem...
My Code (for iterating the rows and changing the value):
var ft = FooTable.get("#spiele_data");
$.each(ft.rows.all, function(i, row){
v=row.val();
var m = moment(v.sp_timestamp, 'L LT');
v.sp_timestamp=m.format('L LT');
row.val(v);
});
This is what happens:
Table is loaded and displayes properly
After changing the language => see the first line
Immediatley after that the table is gone
What am i doing wrong or is there a better possibility to change specific columns in all rows?
Best regards
Christian
+EDIT: One more thing: the $.each-loop is iterated completely. I've tested that by writing the index to the console.
$('table').trigger('footable_redraw');
You need to call redraw to see footable again

Adding values to each row in Swift but not when row is dequeued & reused

I'm getting info from a GPS service giving an array of addresses, each one containing a duration of time in seconds. So from point A to Point B the time duration is 250 seconds and from Point B to C 100 seconds. It does not add the times together to make a complete route time, I have to do that on my own. In above example I would want to see 250 on the first row and 350 on the 2nd row etc. So I am calculating the values together to get the true total for each address by adding them from row to row right inside my table. I grab each address's value from the route's array based on my table index.path row. I populate that into a table and it works beautifuly as so:
let secondsToAdd = Int(self.thisRoute.ttaForSubleg(UInt(indexPath.row)).duration)
duration += secondsToAdd
However when table is scrolled up and down and cells are dequeued and re-queued values are getting added to again and again. I need to reset the duration somewhere to 0 as so:
duration = 0
but I'm stumped as to where!
Without another solution, my only way to do this I think would be to build and maintain an array separately outside the table instead of building it inside the table as I go along. If somebody has a better solution please post!

How to select rows in swt table

I am trying to create a UI using SWT in eclipse. I have a table with multiple rows and two buttons Start and Next.When I click on Start, the first row is supposed to get selected. When I click Next, the next row has to be selected. And when a row is selected I have to read the corresponding row data.
I tried using
tableViewer.getTable().setFocus();
tableViewer.setSelection(new StructuredSelection(tableViewer.getElementAt(0)),true);
But no row is getting selected.
I also tried with table.getSelection(0);
And now each row is selected but with grey colour.As a result the row selection is not invoking table.addListener().
Please help me with this. I am new to this topic.
Thanks in advance.
You might have missed
tableViewer.refresh ();
before doing setSelection

Is there any way to avoid PostgreSQL placing the updated row as the last row?

Well, my problem is that each time that I make an update of a row, this row goes to the last place in the table. It doesn't really matter where was placed before.
I've read in this post Postgresql: row number changes on update that rows in a relational table are not sorted. Then, why when I execute a select * from table; do I always get the same order?
Anyway, I don't want to start a discussion about that, just to know if is there any way to don't let update sentence place the row in the last place.
Edit for more info:
I don't really want to get all results at all. I have programmed 2 buttons in Java, next and previous and, being still a begginer, the only way that I had to get the next or the previous row was to use select * from table limit 1 and adding offset num++ or offset num-- depending of the button clicked. So, when I execute the update, I lose the initial order (insertion order).
Thanks.
You could make some space in your tables for updates. Change the fill factor from the default 100%, no space for updates left on a page, to something less to create space for updates.
From the manual (create table):
fillfactor (integer)
The fillfactor for a table is a percentage
between 10 and 100. 100 (complete packing) is the default. When a
smaller fillfactor is specified, INSERT operations pack table pages
only to the indicated percentage; the remaining space on each page is
reserved for updating rows on that page. This gives UPDATE a chance to
place the updated copy of a row on the same page as the original,
which is more efficient than placing it on a different page. For a
table whose entries are never updated, complete packing is the best
choice, but in heavily updated tables smaller fillfactors are
appropriate. This parameter cannot be set for TOAST tables.
But without an ORDER BY in your query, there is no guarantee that a result set will be sorted the way you expect it to be sorted. No fill factor can change that.