|
Re: Table: Deleted Row (discarding, resuming) [message #683250 is a reply to message #677255] |
Mon, 13 June 2011 11:00 |
|
Hi Jeremie
To revert the deleted rows I would do something like this:
ITableRow[] deletedRows = getSimpleField().getTable().getDeletedRows();
getSimpleField().getTable().clearDeletedRows();
getSimpleField().getTable().addRows(deletedRows);
Does that work for you?
Regards
Claudio
|
|
|
|
Re: Table: Deleted Row (discarding, resuming) [message #685314 is a reply to message #677255] |
Fri, 17 June 2011 08:52 |
|
Hi Jeremie
You could backup the deleted rows, clear the list of deleted rows on the table, add the rows of your backuped list again to the table and delete all beside the one you like to have restored... Or you could manage the deleted rows yourself which allows you to do what you want.
A typical usecase for the functionality of keeping deleted rows is to have them available on the server side in order to remove them on the database. Restoring a single deleted row has not been a request so far.
Regards
Claudio
|
|
|
Re: Table: Deleted Row (discarding, resuming) [message #685621 is a reply to message #685314] |
Fri, 17 June 2011 21:43 |
Jeremie Bresson Messages: 124 Registered: November 2010 |
Senior Member |
|
|
Thanks for your answer...
I manage to solve my problem server-side: for the "primary key" Column (index defined by valueColumn), I check if there is a STATUS_INSERTED and STATUS_DELETED row. If yes I update the status to change it to STATUS_UPDATED (=> Nothing changed in the database for STATUS_UPDATED rows). On the client side I ensure that I do not have multiple STATUS_INSERTED rows for the same primary key Value. Multiple deletes are not a problem with my database query.
private void cleanupTable(AbstractTableFieldData table, int valueColumn) {
HashMap<Object, Integer> deletedMap = new HashMap<Object, Integer>();
HashMap<Object, Integer> insertedMap = new HashMap<Object, Integer>();
for (int i = 0; i < table.getRowCount(); i++) {
switch (table.getRowState(i)) {
case ITableHolder.STATUS_INSERTED:
if (deletedMap.containsKey(table.getValueAt(i, valueColumn))) {
Integer index = deletedMap.get(table.getValueAt(i, valueColumn));
table.setRowState(index.intValue(), ITableHolder.STATUS_UPDATED);
table.setRowState(i, ITableHolder.STATUS_UPDATED);
}
else {
insertedMap.put(table.getValueAt(i, valueColumn), Integer.valueOf(i));
}
break;
case ITableHolder.STATUS_DELETED:
if (insertedMap.containsKey(table.getValueAt(i, valueColumn))) {
Integer index = insertedMap.get(table.getValueAt(i, valueColumn));
table.setRowState(index.intValue(), ITableHolder.STATUS_UPDATED);
table.setRowState(i, ITableHolder.STATUS_UPDATED);
}
else {
deletedMap.put(table.getValueAt(i, valueColumn), Integer.valueOf(i));
}
break;
case ITableHolder.STATUS_NON_CHANGED:
case ITableHolder.STATUS_UPDATED:
default:
//Do nothing
break;
}
}
}
This should work... until there is a discaredDeletedRow(ITableRow) in the AbstractTable in the client.
|
|
|
Re: Table: Deleted Row (discarding, resuming) [message #750299 is a reply to message #685621] |
Tue, 25 October 2011 18:26 |
Jeremie Bresson Messages: 124 Registered: November 2010 |
Senior Member |
|
|
Jeremie Bresson wrote on Fri, 17 June 2011 23:43This should work... until there is a discaredDeletedRow(ITableRow) in the AbstractTable in the client.
I opened a bug: Bug 361985
Jeremie Bresson wrote on Fri, 17 June 2011 23:43the "primary key" Column (index defined by valueColumn)
Writing such utility functions that rely on an index as int is dangerous, because they are called with:
cleanupTable(formData.getActorsTable(), 0);
If a column is inserted before the first column (ActorIdColumn), the code is still valid, but the code do not work as expected. It would be better to call it with:
cleanupTable(formData.getActorsTable(), ActorsTable.ACTOR_ID_COLUMN_ID);
In order to change the SDK to insert the column indexes as constant, I opened and proposed a patch: Bug 356426
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03844 seconds