title: GWT CellList Error: onSelectionChange, index out of bounds
body: <p>I'm writing a messaging application in GWT, and have a fairly difficult problem to find a solution for. I'm working with a GWT CellList. In my cell list I'm displaying all the recent contacts a user has had recent communication with. But lets say that a user is writing a message to a person not on that list. I temporarily add them to the recentContacts list, and update the CellList so that it shows..</p>
  
  <p>But then let's say that they end up not sending the message. I need to be able to detect that, and remove them from the list. The obvious place to do that is in the selection change handler. It actually turns out though that within a selection change handler, if can modify the list of data objects that represent the cell list, but when you actually push them to the cell list, I get an index out of bounds error.</p>
  
  <p>I've verified that this is the issue. So basically I'm stuck. The obvious place to check this is when your selecting a different contact to view. I can then check if any messages were sent to this other contact, and if not, get rid of the contact, but I need to somehow not do it in the selectionChangeHandler. Does anyone have any solution/ideas? I tried a mouse up event, but that ends up happening before the selection event takes place.</p>
  
  <p>Thanks for any help in advance :-)</p>
  
  <pre><code>selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
          public void onSelectionChange(SelectionChangeEvent event) {
              ContactDO selectedContact = selectionModel.getSelectedObject();
  
              //Check if we want to remove a contact from the list
              if ( we want to remove a contact in the list that is not the currently selected contact. ) {
  
                   //remove contact
                   recentContacts.remove(contactThatisNotSelected);
  
                   //Refresh the contact cell list
                   contactCellList.setVisibleRange(0, recentContacts.size());
                   contactCellList.setRowCount(recentContacts.size(), true);
                   contactCellList.setRowData(0, recentContacts);
              }
  
  
          }
      });
  </code></pre>