Exemplo n.º 1
0
  public static void sortTable(Table table, Comparator<TableItem> comparator) {
    int columnCount = table.getColumnCount();
    String[] values = new String[columnCount];
    TableItem[] items = table.getItems();
    for (int i = 1; i < items.length; i++) {
      for (int j = 0; j < i; j++) {
        TableItem item = items[i];
        if (comparator.compare(item, items[j]) < 0) {
          for (int k = 0; k < columnCount; k++) {
            values[k] = item.getText(k);
          }
          Object data = item.getData();
          boolean checked = item.getChecked();
          item.dispose();

          item = new TableItem(table, SWT.NONE, j);
          item.setText(values);
          item.setData(data);
          item.setChecked(checked);
          items = table.getItems();
          break;
        }
      }
    }
  }
Exemplo n.º 2
0
 public static void maxTableColumnsWidth(Table table) {
   table.setRedraw(false);
   try {
     int columnCount = table.getColumnCount();
     if (columnCount > 0) {
       int totalWidth = 0;
       final TableColumn[] columns = table.getColumns();
       for (TableColumn tc : columns) {
         tc.pack();
         totalWidth += tc.getWidth();
       }
       final Rectangle clientArea = table.getClientArea();
       if (totalWidth < clientArea.width) {
         int extraSpace = clientArea.width - totalWidth;
         extraSpace /= columnCount;
         for (TableColumn tc : columns) {
           tc.setWidth(tc.getWidth() + extraSpace);
         }
       }
     }
   } finally {
     table.setRedraw(true);
   }
 }