I tried TreeSet for FlexTable Sorting, creating a table model like
this:
package chanakya.gwt.client;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.TreeSet;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlexTable;
public class BatchDetailsTableModel extends TableModel {
String[] columnModel = new String[] { "SrNo", "Meters", "Weight",
"Received Date" };
Comparator comparator = new GreyBatchDetailsComparator();
TreeSet<GreyBatchDetails> greyBatchDetails;
ArrayList<GreyBatchDetails> displayDetails = null;
private int colIndex;
private FlexTable batchDetailsTable;
private Date defaultDate;
private boolean refreshed= false;
public BatchDetailsTableModel(FlexTable batchDetailsTable) {
greyBatchDetails = new TreeSet<GreyBatchDetails>(comparator);
this.batchDetailsTable = batchDetailsTable;
this.defaultDate = new Date();
}
@Override
public int getColumCount() {
return columnModel.length;
}
@Override
public int getRowCount() {
return greyBatchDetails.size();
}
@Override
public Object getValueAt(int rowIndex, int colIndex) {
Window.alert("Getting value at: "+ rowIndex);
Object result = null;
// displayDetails = new
ArrayList<GreyBatchDetails>(greyBatchDetails);
switch (colIndex) {
case 0:
switch (rowIndex) {
case 0:
result = columnModel[colIndex];
break;
default:
result = rowIndex;
break;
}
break;
case 1:
switch (rowIndex) {
case 0:
result = columnModel[colIndex];
break;
default:
result = (float) displayDetails.get(rowIndex -
1).getMeters();
break;
}
break;
case 2:
switch (rowIndex) {
case 0:
result = columnModel[colIndex];
break;
default:
result = (float) displayDetails.get(rowIndex -
1).getWeight();
break;
}
break;
case 3:
switch (rowIndex) {
case 0:
result = columnModel[colIndex];
break;
default:
result =
DateTimeFormat.getMediumDateTimeFormat().format(
displayDetails.get(rowIndex).getReceivedDate());
break;
}
break;
}
return result;
}
@Override
public String getColName(int colIndex) {
return columnModel[colIndex];
}
@Override
public void setValueAt(int rowIndex, int colIndex, Object value) {
if (rowIndex == 0)
return;
if (colIndex == 0)
return;
displayDetails = new
ArrayList<GreyBatchDetails>(greyBatchDetails);
if (colIndex == 1) {
displayDetails.get(rowIndex - 1).setMeters((Double)
value);
} else if (colIndex == 3) {
displayDetails.get(rowIndex - 1).setReceivedDate(
DateTimeFormat.getMediumDateFormat().parse((String) value));
}
greyBatchDetails.clear();
greyBatchDetails.addAll(displayDetails);
setRefreshed(false);
refreshDisplay();
return;
}
public void refreshTable () {
if (!isRefreshed()) {
displayDetails = new
ArrayList<GreyBatchDetails>(greyBatchDetails);
setRefreshed(true);
}
}
public void refreshDisplay() {
Window.alert("refreshing screen");
for (int row = 0; row < getRowCount(); row++) {
for (int col = 0; col < getColumCount(); col++) {
batchDetailsTable.setText(row, col,
String.valueOf(getValueAt(row,
col)));
}
}
}
@Override
public String[] getColumnModel() {
return columnModel;
}
public void addBatch(Double meters ) {
Window.alert("Setting meters: "+meters);
GreyBatchDetails greDetails = new GreyBatchDetails(0,
meters,MeterWeightConversionModel.convertMeterToWeight(meters),
this.defaultDate);
Window.alert(greDetails.toString());
greyBatchDetails.add(greDetails);
Window.alert("meters set");
setRefreshed(false);
refreshDisplay();
}
public boolean isRefreshed() {
return refreshed;
}
public void setRefreshed(boolean refreshed) {
this.refreshed = refreshed;
}
}
It says null in the addBatch function second time when the batch is
added. (TableModel is an abstract class i have created and rest are
model classes)...
Please guide me whether tree set usage is possible in GWT?
Thanks,
Parth J Joshi
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.