Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Addition to class Table -- invertSelection


It's possible to get the same affect without adding API by getting the selection
and every item in the table and then setting the new selection to be those items
that are not in the old selection.

One of the problems with adding API like this is that the API should really also be
added in other places where it makes sense (ie. List and Tree).  Then there is
the question of supporting, debugging and testing the new API on each platform.
Each new API method takes up space and makes the class that little bit harder to
understand because there's just a little bit more to remember.

So, new API has to really pay for itself either by offering new functionality or
significantly improving existing functionality in terms of performance or
reduced code bulk.  That's my story and I'm sticking to it!

Steve



sdavids@xxxxxxx
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

02/26/02 08:00 AM
Please respond to platform-swt-dev

       
        To:        platform-swt-dev@xxxxxxxxxxx
        cc:        
        Subject:        [platform-swt-dev] Addition to class Table -- invertSelection


Hi,
org.eclipse.swt.widgets.Table has methods for selecting and deselecting
items but no method to invert the selection.

I think it's quite common to invert the selection of a table.

Below is a possible implementation.

I'm not sure if there's an OS-specific message to move to the next item
which is *not* selected ... I took the code from _getSelectionIndices_ and
adjusted it.

Sebastian Davids

@@ Proposed implementation @@

/**
* Inverts the selection of the receiver.
*
* @exception SWTException <ul>
*    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
*    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that
created the receiver</li>
* </ul>
*/
public void invertSelection () {
   checkWidget ();
   int selectedCount = OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0,
0);
   if (selectedCount == 0)
       selectAll ();
   else {
       int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
       if (selectedCount == itemCount)
           deselectAll ();
       else {
           boolean [] selected = new boolean [itemCount];
           int i = -1;
           while ((i = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i,
OS.LVNI_SELECTED)) != -1) {
               selected[i] = true;
           }
           int invertedSelection [] = new int[itemCount - selectedCount];
           int j = invertedSelection.length;
           for (i = (itemCount - 1); i >= 0; --i) {
               if (!selected[i]) invertedSelection[--j] = i;
           }
           setSelection (invertedSelection);
       }
   }
}

--
>>[ Sebastian Davids - Email: <sdavids@xxxxxx> ICQ: 2267
6231 ]<<
>>[ PGP-FP: 0DF6 5D15 6B32 683D 9CC7 287D 4744 D881 B284
04FE ]<<

GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev



Back to the top