Funny Behaviour in GWT CellTable? - java

I've created a test case of my CellTable issue as a self contained
panel that can easily be imported into any project:
http://pastebin.com/zDLPKUNh
I've also posted this question on Google Groups GWT discussions.
Basically I have two Date class fields in my row model, a startDate
and an endDate. Each Date has two columns in the CellTable (called
batchTable), one to display the actual date (a DatePickerCell) and the
other being a text input cell for the time.
When the FieldUpdater of the startTime or endTime is fired we parse
the value, save the new time and call batchTable.setRowData() with the
updated object and row index.
The problem is that when FieldUpdater is fired, the cells do not
update?
I specifically edited the FieldUpdater of the endTime cell to
be an hour later than what it was set at.
I've checked as best as I can that all the gets and sets of the
respective startDate and endDate are in order, but I'm thinking that
there's something about CellTable I'm not getting.
Apologies if I've missed anything.
I'm running:
GWT 2.3
I've tested it in the latest Chrome and IE9.
Regards,
Julian

According to the google docs it should be enough to just change the field in your object and then call
cellTable.redraw();
in the update() method.
You could also try to call setRowData on your ListDataProvider instead of your CellTable. However calling setRowData on the ListDataProvider would probably end up in a call to every added display of the ListDataProvider which would be the same as calling setRowData on the CellTable directly.

I faced the same problem. In my case I had visiblerange set incorrectly. First parameter is index and second parameter is length. Make sure those two are set up correctly. After that the cell table displays correctly. I did not need to call redraw.

Related

Tracking data offset of data in a table to retrieve the previous/next subset on table scroll

I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).

Android NumberPicker wraps values when displayed values are changed

I have an android Dialog with a 3 numberpickers inside. Changing the 3rd picker triggers a change in the displayed values of the first 2 pickers. However I've noticed when I change the displayed values, and call
setWrapSelectorWheel(false)
it still shows the new values as wrapped visually (I can see the last value above the first one).
If I touch the picker it suddenly snaps into non wrap selector wheel. What's odd is I call
getWrapSelectoWheel()
after setting the displayed values and it returns false... just like I set it. But visually it's wrong.
Any ideas what's going on?
Many thanks!
I found a solution, Daniel was on the right track, however it appears that initializeSelectorWheelIndices is actually a bad thing once you've already set your values. Because of this, you need to call setMinValue and setMaxValue BEFORE you set your values. However, if you already have an array set on your picker, if you call setMaxValue with a higher value than the current array, it will give you a ArrayIndexOutOfBounds exception.
The solution then is to clear the old display values, set your max value, then you can call setWrapSelectorWheel and setDisplayValues:
public void updatePickerValues(String[] newValues){
picker.setDisplayedValues(null);
picker.setMinValue(0);
picker.setMaxValue(newValues.length -1);
picker.setWrapSelectorWheel(false);
picker.setDisplayedValues(newValues);
}
I don't know what version of Android you're running but I would suggest you read the source code for the NumberPicker (v4.2.2). Perhaps you need to trigger a call to the private method initializeSelectorWheelIndices which can be done via a call to some of the public methods.
Although I do think your usage of the picker, by changing the wrapping flag part way through, does seem a little unusual. Don't you want this behaviour to be consistent? In which case make a call to setWrapSelectorWheel once after you've set your min and max values and then leave it alone.
I've verified this behavior as well on kitkat. It's a bug. Couldn't find an existing report so I created a new one here: bug# 98319
Per previous answers I found that making setWrapSelectorWheel(false) the last call after all setup calls will work for most scenarios. In my case I'm dynamically changing limits of the NumberPicker as the user is interacting and I just can't get it to behave 100%. I'm opting to live with the wrap selector.

JTable Data Refresh Issue

I want to refresh the JTable data by clicking a button.
The problem is that the old data in the JTable can't be removed and the new data are just added into the table. I tried below ways to remove the old data but none of them works.
1. table.setModel(new DefaultTableModel());
2. ((DefaultTableModel)table.getModel()).setRowCount(0);
3. ((DefaultTableModel)table.getModel()).fireTableDataChanged();
4. ((DefaultTableModel)table.getModel()).getDataVector().removeAllElements();
5. table.repaint();
6. model = (DefaultTableModel)table.getModel();
while(model.getRowCount() > 0) {
model.removeRow(0);
}
Having a refresh button for a JTable is very suspect. It makes me think you aren't correctly adding data as JTables should refresh everytime data is added or removed.
I would verify a couple of things when using a DefaultTableModel:
Make sure to only add data using addRow
Data should only be inserted using insertRow
Remove data using removeRow
Never modify the internal vectors directly. It won't cause events to fire and you're stuck with a refresh button. I don't know why they even expose it. The JavaDocs should at least specifically warn against this.
If all else fails, fire up a debugger and see what happens.
More of your code might be appropriate here. Hard to tell exactly where you're calling these methods and the order. If you change the model and then call fireTableDataChanged() it should work....assuming you've updated the right TableModel. There is a good Java tutorial for using tables: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
Had the same issue myself, but my solution was different. After checking just about everything, I checked the contents of the table via the console, and found that the contents were indeed being updated. However, the update was not being reflected on the table which was visible on the screen.
In fact, this code:
model = (DefaultTableModel)table.getModel();
while(model.getRowCount() > 0) {
model.removeRow(0);
}
Did not only remove the rows, but also removed the table.
My solution was to remove the table from the form and then re-add it, whenever the table data was changed.
Seemed in my case there was nothing wrong with my coding to generate the table but that the layout manager didn't like overwriting or updating a component the area where I wanted to put it already had something in there.
Something weird going on methinks but at the end of the day this worked for me.

SWT ComboBoxCellEditor editable

I have a TableViewer where the values in one column should typically come from a dynamic list.
I'm currently using org.eclipse.jface.viewers.ComboBoxCellEditor , which is actually a Select-List: it stores the index of the selected value. If I change the underlying list (calling setItems(String[]), it's clumsy to keep the previous selected value... (specially if it's not included in the list anymore!) What I'd wish is actually a cell editor that stores, not the index from the list, but the string (perhaps letting the user edit it freely, perhaps not), where the list is just used as a suggestion at input time - like a "combobox" was supposed to work in the good old days... Is this possible?
I would suggest you to have your CellEditor to mimic the behavior that you are looking for. Extend ComboBoxViewerCellEditor and override doGetValue() method. Add modify listener on Combo control and also filter (which filters list items based on input text) to comboviewer.
You should look at :
org.eclipse.wst.xml.ui.internal.properties.StringComboBoxCellEditor This class comes from WTP project; It's an extended ComboBoxCellEditor that selects and returns Strings.
codemirror.eclipse.ui.xquery.viewers.StringComboBoxCellEditor It's the copy/paste of WTP StringComboBoxCellEditor; it adds the capability to add the item in the combo when it is not found.

Java: Selected rows's index does not changes when sorted

I have a Jtable on which I called the method
table1.setAutoCreateRowSorter(true);.
So this works on well.
But I also have a methos in my JFrame class which is fired when i push a button. It gets the selected rows indexes using this code
int selectedRows[] = this.table1.getSelectedRows();.
And displays an edit window for the first row corresponding in the selected interval.
The problem is that if I don't click on column's headers (I mean i don't sorte them at all) my method works perfect. But when I sort the row, the indexes of the rows doesn't seems to change at all - thus resulting an edit window for the old row whicn was initially in that position before making any sort.
I am using JDK 6 could anyonw give ma a tip?
The underlying model does not change order. Only the view changes. You can read more about this in Sun's tutorial. You will need to use JTable.convertRowIndexToView() and JTable.convertRowIndexToModel().
You need to use convertRowIndexToView(int) and convertRowIndexToModel(int) to convert model (underlying data) indices and view indices.

Categories

Resources