Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Table: Deleted Row (discarding, resuming)
Table: Deleted Row (discarding, resuming) [message #677255] Tue, 07 June 2011 22:57 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
I have a ITableRow r.

When I delete this row in a Table t:
t.deleteRow(r)

It disappears from the array returned by t.getRows().

And as long as I have AutoDiscardOnDelete ==> false, it appears in the array returned by t.getDeletedRows(). And r.getStatus() == STATUS_DELETED

So far so good.

How can I "resume" the deleted row ?

I have try:
r.setStatusUpdated() 
It changes the status of the row returned by t.getDeletedRows() but the row is not visible and to in the array t.getRow().

If I add a new row r1 (with the same primary key):
r1 = addRowsByMatrix(new Object[]{new Object[]{
                      categoryId, //== t.getCategoryIdColumn().getValue(r)
                      t.getNameColumn().getValue(r)
                  }});
I have r1 in the array returned by t.getRows() with r1 status == STATUS_INSERTED
I have r in the array returned by t.getDeleteRows() with r == STATUS_DELETED

I also have tried to discard the deleted row: this doesn't seems to be possible: nothing append.
t.deleteRow(r)
t.discardRow(r)
=> r is still in t.getDeletedRow().


This is not the the behavior I have expected.
Re: Table: Deleted Row (discarding, resuming) [message #683250 is a reply to message #677255] Mon, 13 June 2011 11:00 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
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 #684531 is a reply to message #683250] Wed, 15 June 2011 18:41 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
Thanks for your answer.

First question:
why is the function clearDeletedRows() in AbstractTable not named discardDeletedRows() or discardAllDeletedRows() ?


Second point:
You are saying is that it is not possible to remove just one row from m_deletedRows? Since it is private final I do not have access.


I do not image that my use case is so specific. I have a N:M between two entities. In the form where I edit the first entity, I have a list of the other entities in a TableField. With menus, I can add or remove them. Adding entities opens the corresponding TablePage in an other Form to select some rows to add. My Idea was to handle on the client-side the fact that it is possible to remove and then add again the same entity. I also check that the same entity is not twice in the list. How can I do this without the appropriate functions?
Re: Table: Deleted Row (discarding, resuming) [message #685314 is a reply to message #677255] Fri, 17 June 2011 08:52 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
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 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
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 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
Jeremie Bresson wrote on Fri, 17 June 2011 23:43
This 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:43
the "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


Re: Table: Deleted Row (discarding, resuming) [message #773044 is a reply to message #750299] Sat, 31 December 2011 09:43 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
Jeremie Bresson wrote on Fri, 17 June 2011 23:43
This should work... until there is a discaredDeletedRow(ITableRow) in the AbstractTable in the client.


I just proposed a patch for the bug Bug 361985:

new methods:
- discardAllDeletedRows();
- discardDeletedRow(ITableRow deletedRow);
- discardDeletedRows(ITableRow[] deletedRows);

deprecated:
- clearDeletedRows() [use discardAllDeletedRows() instead]


How can I test this modification (and write a test) to ensure that the methods work as expected ?

.
Re: Table: Deleted Row (discarding, resuming) [message #774873 is a reply to message #773044] Wed, 04 January 2012 20:30 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
Jeremie Bresson wrote on Sat, 31 December 2011 10:43
How can I test this modification (and write a test) to ensure that the methods work as expected ?


I added some tests for my patch (in order to ensure it works as expected)... The patch itself also needed an update...

Everything is in Bugzilla...


Previous Topic:Scout development
Next Topic:SCOUT + RAP
Goto Forum:
  


Current Time: Thu Apr 25 08:07:15 GMT 2024

Powered by FUDForum. Page generated in 0.03844 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top