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 365747
Collapse All | Expand All

(-)src/org/eclipse/swt/widgets/Table.java (-5 / +20 lines)
Lines 1605-1624 Link Here
1605
      int index = indexOf( column );
1605
      int index = indexOf( column );
1606
      if( 0 <= index && index < getColumnCount() ) {
1606
      if( 0 <= index && index < getColumnCount() ) {
1607
        int leftColumnsWidth = 0;
1607
        int leftColumnsWidth = 0;
1608
        int rightColumnsWidth = 0;
1608
        int columnWidth = column.getWidth();
1609
        int columnWidth = column.getWidth();
1609
        int clientWidth = getClientArea().width;
1610
        int clientWidth = getClientArea().width;
1610
        int[] columnOrder = getColumnOrder();
1611
        int[] columnOrder = getColumnOrder();
1611
        boolean found = false;
1612
        boolean found = false;
1612
        for( int i = 0; i < columnOrder.length && !found; i++ ) {
1613
        for( int i = 0; i < columnOrder.length; i++ ) {
1613
          found = index == columnOrder[ i ];
1614
          if( index != columnOrder[ i ] ) {
1614
          if( !found && !isFixedColumn( i ) ) {
1615
            int currentColumnWidth = getColumn( columnOrder[ i ] ).getWidth();
1615
            leftColumnsWidth += getColumn( columnOrder[ i ] ).getWidth();
1616
            if( found ) {
1617
              rightColumnsWidth += currentColumnWidth;
1618
            } else {
1619
              if( isFixedColumn( columnOrder[ i ] ) ) {
1620
                clientWidth -= currentColumnWidth;
1621
              } else {
1622
                leftColumnsWidth += currentColumnWidth;
1623
              }
1624
            }
1625
          } else {
1626
            found = true;
1616
          }
1627
          }
1617
        }
1628
        }
1618
        if( getColumnLeftOffset( index ) > leftColumnsWidth ) {
1629
        if( getColumnLeftOffset( index ) > leftColumnsWidth ) {
1619
          leftOffset = leftColumnsWidth;
1630
          leftOffset = leftColumnsWidth;
1620
        } else if( leftOffset < leftColumnsWidth + columnWidth - clientWidth ) {
1631
        } else if( leftOffset < leftColumnsWidth + columnWidth - clientWidth ) {
1621
          leftOffset = leftColumnsWidth + columnWidth - clientWidth;
1632
          if( columnWidth + rightColumnsWidth < clientWidth ) {
1633
            leftOffset = leftColumnsWidth + columnWidth + rightColumnsWidth - clientWidth;
1634
          } else {
1635
            leftOffset = leftColumnsWidth;
1636
          }
1622
        }
1637
        }
1623
      }
1638
      }
1624
    }
1639
    }
(-)src/org/eclipse/swt/widgets/Table_Test.java (-19 / +31 lines)
Lines 2183-2203 Link Here
2183
2183
2184
  public void testShowColumn() {
2184
  public void testShowColumn() {
2185
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
2185
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
2186
    shell.setSize( 800, 600 );
2187
    Table table = new Table( shell, SWT.NONE );
2186
    Table table = new Table( shell, SWT.NONE );
2188
    table.setSize( 300, 100 );
2187
    table.setSize( 325, 100 );
2189
    for( int i = 0; i < 10; i++ ) {
2188
    for( int i = 0; i < 10; i++ ) {
2190
      TableColumn column = new TableColumn( table, SWT.NONE );
2189
      TableColumn column = new TableColumn( table, SWT.NONE );
2191
      column.setWidth( 50 );
2190
      column.setWidth( 50 );
2192
    }
2191
    }
2193
    for( int i = 0; i < 10; i++ ) {
2192
    ITableAdapter adapter = ( ITableAdapter )table.getAdapter( ITableAdapter.class );
2194
      new TableItem( table, SWT.NONE );
2195
    }
2196
    ITableAdapter adapter
2197
      = ( ITableAdapter )table.getAdapter( ITableAdapter.class );
2198
    assertEquals( 0, adapter.getLeftOffset() );
2193
    assertEquals( 0, adapter.getLeftOffset() );
2199
    table.showColumn( table.getColumn( 8 ) );
2194
    table.showColumn( table.getColumn( 8 ) );
2200
    assertEquals( 165, adapter.getLeftOffset() );
2195
    assertEquals( 175, adapter.getLeftOffset() );
2201
    table.showColumn( table.getColumn( 1 ) );
2196
    table.showColumn( table.getColumn( 1 ) );
2202
    assertEquals( 50, adapter.getLeftOffset() );
2197
    assertEquals( 50, adapter.getLeftOffset() );
2203
    table.showColumn( table.getColumn( 3 ) );
2198
    table.showColumn( table.getColumn( 3 ) );
Lines 2222-2228 Link Here
2222
    table.showColumn( table.getColumn( 8 ) );
2217
    table.showColumn( table.getColumn( 8 ) );
2223
    assertEquals( 0, adapter.getLeftOffset() );
2218
    assertEquals( 0, adapter.getLeftOffset() );
2224
    table.showColumn( table.getColumn( 5 ) );
2219
    table.showColumn( table.getColumn( 5 ) );
2225
    assertEquals( 115, adapter.getLeftOffset() );
2220
    assertEquals( 125, adapter.getLeftOffset() );
2226
  }
2221
  }
2227
2222
2228
  public void testShowFixedColumn() {
2223
  public void testShowFixedColumn() {
Lines 2243-2266 Link Here
2243
    assertEquals( 100, adapter.getLeftOffset() );
2238
    assertEquals( 100, adapter.getLeftOffset() );
2244
  }
2239
  }
2245
2240
2246
  public void testShowColumnBehindFixedColumn() {
2241
  public void testShowColumnWithFixedColumns_ScrolledToLeft() {
2247
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
2242
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
2248
    shell.setSize( 800, 600 );
2249
    Table table = createFixedColumnsTable();
2243
    Table table = createFixedColumnsTable();
2250
    table.setSize( 300, 100 );
2244
    int numColumns = 4;
2251
    for( int i = 0; i < 10; i++ ) {
2245
    int columnWidth = 100;
2246
    table.setSize( columnWidth  * ( numColumns - 1 ), 100 );
2247
    for( int i = 0; i < numColumns; i++ ) {
2252
      TableColumn column = new TableColumn( table, SWT.NONE );
2248
      TableColumn column = new TableColumn( table, SWT.NONE );
2253
      column.setWidth( 50 );
2249
      column.setWidth( columnWidth );
2254
    }
2255
    for( int i = 0; i < 10; i++ ) {
2256
      new TableItem( table, SWT.NONE );
2257
    }
2250
    }
2258
    ITableAdapter adapter = ( ITableAdapter )table.getAdapter( ITableAdapter.class );
2251
    ITableAdapter adapter = ( ITableAdapter )table.getAdapter( ITableAdapter.class );
2259
    adapter.setLeftOffset( 100 );
2252
    adapter.setLeftOffset( 100 );
2260
    table.showColumn( table.getColumn( 1 ) );
2253
2254
    table.showColumn( table.getColumn( 2 ) );
2255
2261
    assertEquals( 0, adapter.getLeftOffset() );
2256
    assertEquals( 0, adapter.getLeftOffset() );
2262
  }
2257
  }
2263
2258
2259
  public void testShowColumnWithFixedColumns_ScrolledToRight() {
2260
    Fixture.fakePhase( PhaseId.PROCESS_ACTION );
2261
    int numColumns = 4;
2262
    int columnWidth = 100;
2263
    Table table = createFixedColumnsTable();
2264
    table.setSize( columnWidth  * ( numColumns - 1 ), 100 );
2265
    for( int i = 0; i < numColumns; i++ ) {
2266
      TableColumn column = new TableColumn( table, SWT.NONE );
2267
      column.setWidth( columnWidth );
2268
    }
2269
2270
    table.showColumn( table.getColumn( 3 ) );
2271
2272
    ITableAdapter adapter = ( ITableAdapter )table.getAdapter( ITableAdapter.class );
2273
    assertEquals( 100, adapter.getLeftOffset() );
2274
  }
2275
2264
  public void testScrollBars() {
2276
  public void testScrollBars() {
2265
    Table table = new Table( shell, SWT.NONE );
2277
    Table table = new Table( shell, SWT.NONE );
2266
    assertNotNull( table.getHorizontalBar() );
2278
    assertNotNull( table.getHorizontalBar() );
Lines 2382-2388 Link Here
2382
2394
2383
  private Table createFixedColumnsTable() {
2395
  private Table createFixedColumnsTable() {
2384
    Table table = new Table( shell, SWT.NONE );
2396
    Table table = new Table( shell, SWT.NONE );
2385
    table.setData( "fixedColumns", new Integer( 1 ) );
2397
    table.setData( "fixedColumns", new Integer( 2 ) );
2386
    return table;
2398
    return table;
2387
  }
2399
  }
2388
2400

Return to bug 365747