Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 278346 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/swt/internal/widgets/ListModel.java (-10 / +19 lines)
Lines 45-51 Link Here
45
    System.arraycopy( selection, 0, result, 0, selection.length );
45
    System.arraycopy( selection, 0, result, 0, selection.length );
46
    return result;
46
    return result;
47
  }
47
  }
48
  
48
49
  public int getSelectionCount() {
49
  public int getSelectionCount() {
50
    return selection.length;
50
    return selection.length;
51
  }
51
  }
Lines 86-92 Link Here
86
      }
86
      }
87
    }
87
    }
88
  }
88
  }
89
  
89
90
  public void setSelection( final int start, final int end ) {
90
  public void setSelection( final int start, final int end ) {
91
    deselectAll();
91
    deselectAll();
92
    if( end >= 0 && start <= end && start <= getItemCount() - 1 ) {
92
    if( end >= 0 && start <= end && start <= getItemCount() - 1 ) {
Lines 106-112 Link Here
106
      }
106
      }
107
    }
107
    }
108
  }
108
  }
109
  
109
110
  public void setSelection( final String[] selection ) {
110
  public void setSelection( final String[] selection ) {
111
    if( selection == null ) {
111
    if( selection == null ) {
112
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
112
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
Lines 161-170 Link Here
161
  public void deselectAll() {
161
  public void deselectAll() {
162
    this.selection = EMPTY_SELECTION;
162
    this.selection = EMPTY_SELECTION;
163
  }
163
  }
164
  
164
165
  ////////////////////////////////
165
  ////////////////////////////////
166
  // Methods to maintain the items
166
  // Methods to maintain the items
167
  
167
168
  public void add( final String string ) {
168
  public void add( final String string ) {
169
    if( string == null ) {
169
    if( string == null ) {
170
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
170
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
Lines 195-201 Link Here
195
      remove( i );
195
      remove( i );
196
    }
196
    }
197
  }
197
  }
198
  
198
199
  public void remove( final int[] indices ) {
199
  public void remove( final int[] indices ) {
200
    if( indices == null ) {
200
    if( indices == null ) {
201
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
201
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
Lines 237-243 Link Here
237
  public void setItems( final String[] items ) {
237
  public void setItems( final String[] items ) {
238
    if( items == null ) {
238
    if( items == null ) {
239
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
239
      SWT.error( SWT.ERROR_NULL_ARGUMENT );
240
    } 
240
    }
241
    for( int i = 0; i < items.length; i++ ) {
241
    for( int i = 0; i < items.length; i++ ) {
242
      if( items[ i ] == null ) {
242
      if( items[ i ] == null ) {
243
        SWT.error( SWT.ERROR_INVALID_ARGUMENT );
243
        SWT.error( SWT.ERROR_INVALID_ARGUMENT );
Lines 264-271 Link Here
264
  }
264
  }
265
265
266
  //////////////////
266
  //////////////////
267
  // Helping methods 
267
  // Helping methods
268
  
268
269
  /* If the given index is contained in the selection, it will be removed. */
269
  /* If the given index is contained in the selection, it will be removed. */
270
  private void removeFromSelection( final int index ) {
270
  private void removeFromSelection( final int index ) {
271
    boolean found = false;
271
    boolean found = false;
Lines 281-288 Link Here
281
        found = true;
281
        found = true;
282
      }
282
      }
283
    }
283
    }
284
    adjustSelectionIndices( index );
285
  }
286
287
  private void adjustSelectionIndices( final int removedIndex ) {
288
    for( int i = 0; i < selection.length; i++ ) {
289
      if( selection[ i ] >= removedIndex ) {
290
        selection[ i ] = selection[ i ] - 1;
291
      }
292
    }
284
  }
293
  }
285
  
294
286
  private int indexOf( final String string ) {
295
  private int indexOf( final String string ) {
287
    return items.indexOf( string );
296
    return items.indexOf( string );
288
  }
297
  }
(-)src/org/eclipse/swt/widgets/List_Test.java (-1 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2008 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2002, 2009 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 757-762 Link Here
757
    assertEquals( 0, list.getSelectionIndices()[ 0 ] );
757
    assertEquals( 0, list.getSelectionIndices()[ 0 ] );
758
    assertEquals( 1, list.getSelectionIndices()[ 1 ] );
758
    assertEquals( 1, list.getSelectionIndices()[ 1 ] );
759
    assertEquals( 2, list.getSelectionIndices()[ 2 ] );
759
    assertEquals( 2, list.getSelectionIndices()[ 2 ] );
760
761
    // Ensure that no selection indices after remove all items one by one
762
    list.removeAll();
763
    list.add( "item0" );
764
    list.add( "item1" );
765
    list.add( "item2" );
766
    list.select( new int[] { 0, 1, 2 } );
767
    String[] listSelection = list.getSelection();
768
    for( int i = 0; i < listSelection.length; i++ ) {
769
      list.remove( listSelection[ i ] );
770
    }
771
    assertEquals( 0, list.getSelectionCount() );
772
773
    // Ensure that no selection indices after remove selected items one by one
774
    list.removeAll();
775
    list.add( "item0" );
776
    list.add( "item1" );
777
    list.add( "item2" );
778
    list.select( new int[] { 0, 1 } );
779
    listSelection = list.getSelection();
780
    for( int i = 0; i < listSelection.length; i++ ) {
781
      list.remove( listSelection[ i ] );
782
    }
783
    assertEquals( 0, list.getSelectionCount() );
760
  }
784
  }
761
785
762
  public void testSetItem() {
786
  public void testSetItem() {

Return to bug 278346