void tableMouseDown(Event event) {
   if (isDisposed() || !isVisible()) return;
   Point pt = new Point(event.x, event.y);
   int lineWidth = table.getLinesVisible() ? table.getGridLineWidth() : 0;
   TableItem item = table.getItem(pt);
   if ((table.getStyle() & SWT.FULL_SELECTION) != 0) {
     if (item == null) return;
   } else {
     int start = item != null ? table.indexOf(item) : table.getTopIndex();
     int end = table.getItemCount();
     Rectangle clientRect = table.getClientArea();
     for (int i = start; i < end; i++) {
       TableItem nextItem = table.getItem(i);
       Rectangle rect = nextItem.getBounds(0);
       if (pt.y >= rect.y && pt.y < rect.y + rect.height + lineWidth) {
         item = nextItem;
         break;
       }
       if (rect.y > clientRect.y + clientRect.height) return;
     }
     if (item == null) return;
   }
   TableColumn newColumn = null;
   int columnCount = table.getColumnCount();
   if (columnCount == 0) {
     if ((table.getStyle() & SWT.FULL_SELECTION) == 0) {
       Rectangle rect = item.getBounds(0);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (!rect.contains(pt)) return;
     }
   } else {
     for (int i = 0; i < columnCount; i++) {
       Rectangle rect = item.getBounds(i);
       rect.width += lineWidth;
       rect.height += lineWidth;
       if (rect.contains(pt)) {
         newColumn = table.getColumn(i);
         break;
       }
     }
     if (newColumn == null) {
       if ((table.getStyle() & SWT.FULL_SELECTION) == 0) return;
       newColumn = table.getColumn(0);
     }
   }
   setRowColumn(item, newColumn, true);
   setFocus();
   return;
 }
Example #2
0
 /**
  * Returns a rectangle describing the receiver's size and location relative to its parent at a
  * column in the table.
  *
  * @param index the index that specifies the column
  * @return the receiver's bounding column rectangle
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public Rectangle getBounds(final int index) {
   checkWidget();
   if (!parent.checkData(this, parent.indexOf(this))) {
     error(SWT.ERROR_WIDGET_DISPOSED);
   }
   Rectangle result;
   int columnCount = parent.getColumnCount();
   if (columnCount > 0 && (index < 0 || index >= columnCount)) {
     result = new Rectangle(0, 0, 0, 0);
   } else {
     Rectangle textBounds = getTextBounds(index);
     int left = getLeft(index);
     int itemIndex = parent.indexOf(this);
     int top = getTop(itemIndex);
     int width = 0;
     if (index == 0 && columnCount == 0) {
       Rectangle imageBounds = getImageBounds(index);
       int spacing = getSpacing(index);
       int paddingWidth = parent.getCellPadding().width;
       width = imageBounds.width + spacing + textBounds.width + paddingWidth;
     } else if (index >= 0 && index < columnCount) {
       width = parent.getColumn(index).getWidth() - getCheckWidth(index);
     }
     int height = getHeight(index);
     result = new Rectangle(left, top, width, height);
   }
   return result;
 }
Example #3
0
  private void sort(int column) {
    if (table.getItemCount() <= 1) return;

    TableItem[] items = table.getItems();
    String[][] data = new String[items.length][table.getColumnCount()];
    for (int i = 0; i < items.length; i++) {
      for (int j = 0; j < table.getColumnCount(); j++) {
        data[i][j] = items[i].getText(j);
      }
    }

    Arrays.sort(data, new RowComparator(column));

    if (lastSortColumn != column) {
      table.setSortColumn(table.getColumn(column));
      table.setSortDirection(SWT.DOWN);
      for (int i = 0; i < data.length; i++) {
        items[i].setText(data[i]);
      }
      lastSortColumn = column;
    } else {
      // reverse order if the current column is selected again
      table.setSortDirection(SWT.UP);
      int j = data.length - 1;
      for (int i = 0; i < data.length; i++) {
        items[i].setText(data[j--]);
      }
      lastSortColumn = -1;
    }
  }
Example #4
0
 private int getLeft(final int index) {
   int result = 0;
   int columnCount = parent.getColumnCount();
   if (index == 0 && columnCount == 0) {
     result = getCheckWidth(index) - parent.leftOffset;
   } else if (index >= 0 && index < columnCount) {
     // TODO [rh] consider applying the leftOffset already in Column#getLeft()
     int columnLeft = parent.getColumn(index).getLeft();
     result = getCheckWidth(index) + columnLeft - parent.leftOffset;
   }
   return result;
 }
Example #5
0
 private int getColumnWidth(final int index) {
   TableColumn column = parent.getColumn(index);
   return column.getWidth() - getCheckWidth(index);
 }
 void setRowColumn(int row, int column, boolean notify) {
   TableItem item = row == -1 ? null : table.getItem(row);
   TableColumn col = column == -1 || table.getColumnCount() == 0 ? null : table.getColumn(column);
   setRowColumn(item, col, notify);
 }