public int[] getSeletedModelRows() {
    int[] selectedViewRows = _table.getSelectedRows();

    int[] ret = new int[selectedViewRows.length];

    for (int i = 0; i < selectedViewRows.length; i++) {
      ret[i] = (((SortableTableModel) _table.getModel()).transfromToModelRow(selectedViewRows[i]));
    }

    return ret;
  }
  @Override
  public void switchColumnHeader(ColumnHeaderDisplay columnHeaderDisplay) {
    for (Enumeration e = _table.getColumnModel().getColumns(); e.hasMoreElements(); ) {
      ExtTableColumn col = (ExtTableColumn) e.nextElement();

      if (ColumnHeaderDisplay.COLUMN_NAME == columnHeaderDisplay) {
        col.setHeaderValue(col.getColumnDisplayDefinition().getColumnName());
      } else if (ColumnHeaderDisplay.COLUMN_LABEL == columnHeaderDisplay) {
        col.setHeaderValue(col.getColumnDisplayDefinition().getLabel());
      }
    }

    _table.getTableHeader().repaint();
  }
  public int getColumnWidthForHeader(String header) {
    TableColumnModel columnModel = _table.getColumnModel();

    for (int i = 0; i < columnModel.getColumnCount(); i++) {
      if (columnModel.getColumn(i).getHeaderValue().equals(header)) {
        return columnModel.getColumn(i).getWidth();
      }
    }

    throw new IllegalStateException("No col with header: " + header);
  }
  /** Part of print code coped from Sun */
  public void printTablePart(Graphics2D g2, PageFormat pageFormat, int rowIndex, int columnIndex) {

    String pageNumber = "Page: " + (rowIndex + 1);
    if (subTableSplitSize > 1) {
      pageNumber += "-" + (columnIndex + 1);
    }

    int pageLeft = subTableSplit[columnIndex];
    int pageRight = subTableSplit[columnIndex + 1];

    int pageWidth = pageRight - pageLeft;

    // page number message (in smaller type)
    g2.setFont(new Font(g2.getFont().getName(), g2.getFont().getStyle(), 8));
    g2.drawString(pageNumber, pageWidth / 2 - 35, (int) (pageHeight - fontHeight));

    double clipHeight =
        Math.min(tableHeightOnFullPage, tableHeight - rowIndex * tableHeightOnFullPage);

    g2.translate(-subTableSplit[columnIndex], 0);
    g2.setClip(pageLeft, 0, pageWidth, (int) headerHeight);

    g2.scale(scale, scale);
    tableHeader.paint(g2); // draw the header on every page
    g2.scale(1 / scale, 1 / scale);
    g2.translate(0, headerHeight);
    g2.translate(0, -tableHeightOnFullPage * rowIndex);

    // cut table image and draw on the page

    g2.setClip(pageLeft, (int) tableHeightOnFullPage * rowIndex, pageWidth, (int) clipHeight);
    g2.scale(scale, scale);
    _table.paint(g2);
    g2.scale(1 / scale, 1 / scale);

    double pageTop = tableHeightOnFullPage * rowIndex - headerHeight;
    //		double pageBottom = pageTop +  clipHeight + headerHeight;
    g2.drawRect(pageLeft, (int) pageTop, pageWidth, (int) (clipHeight + headerHeight));
  }
  public void init(
      IDataSetUpdateableModel updateableModel,
      int listSelectionMode,
      IDataModelImplementationDetails dataModelImplementationDetails,
      ISession session) {
    if (null != dataModelImplementationDetails) {
      _dataModelImplementationDetails = dataModelImplementationDetails;
    }

    _table = new MyJTable(this, updateableModel, listSelectionMode, session);
    _continueReadHandler = new ContinueReadHandler(_table);
    _selectionHandler = new DataSetViewerTableListSelectionHandler(_table);
    _updateableModel = updateableModel;

    _table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                onSelectionChanged();
              }
            });
  }
  /** Part of print code coped from Sun */
  public void getPageInfo(Graphics g, PageFormat pageFormat) {

    subTableSplit = null;
    subTableSplitSize = 0;
    subPageIndex = 0;
    prevPageIndex = 0;

    fontHeight = (int) (g.getFontMetrics().getHeight() * scale);
    fontDesent = (int) (g.getFontMetrics().getDescent() * scale);

    tableHeader = _table.getTableHeader();
    //		double headerWidth = tableHeader.getWidth() * scale;
    headerHeight = tableHeader.getHeight() + _table.getRowMargin() * scale;

    pageHeight = pageFormat.getImageableHeight();
    pageWidth = pageFormat.getImageableWidth();

    //		double tableWidth =_table.getColumnModel().getTotalColumnWidth() * scale;
    tableHeight = _table.getHeight() * scale;
    rowHeight = _table.getRowHeight() + _table.getRowMargin() * scale;

    tableHeightOnFullPage = (int) (pageHeight - headerHeight - fontHeight * 2);
    tableHeightOnFullPage = tableHeightOnFullPage / rowHeight * rowHeight;

    TableColumnModel tableColumnModel = tableHeader.getColumnModel();
    int columns = tableColumnModel.getColumnCount();
    int columnMargin = (int) (tableColumnModel.getColumnMargin() * scale);

    int[] temp = new int[columns];
    int columnIndex = 0;
    temp[0] = 0;
    int columnWidth;
    int length = 0;
    subTableSplitSize = 0;
    while (columnIndex < columns) {

      columnWidth = (int) (tableColumnModel.getColumn(columnIndex).getWidth() * scale);

      if (length + columnWidth + columnMargin > pageWidth) {
        temp[subTableSplitSize + 1] = temp[subTableSplitSize] + length;
        length = columnWidth;
        subTableSplitSize++;
      } else {
        length += columnWidth + columnMargin;
      }
      columnIndex++;
    } // while

    if (length > 0) { // if are more columns left, part page
      temp[subTableSplitSize + 1] = temp[subTableSplitSize] + length;
      subTableSplitSize++;
    }

    subTableSplitSize++;
    subTableSplit = new int[subTableSplitSize];
    for (int i = 0; i < subTableSplitSize; i++) {
      subTableSplit[i] = temp[i];
    }
    totalNumPages = (int) (tableHeight / tableHeightOnFullPage);
    if (tableHeight % tableHeightOnFullPage >= rowHeight) { // at least 1 more row left
      totalNumPages++;
    }

    totalNumPages *= (subTableSplitSize - 1);
    pageinfoCalculated = true;
  }
 public FindService createFindService() {
   return new DefaultFindService(_table, getColumnDefinitions(), _table.getTypedModel());
 }
 public int[] getSeletedRows() {
   return _table.getSelectedRows();
 }
 public void setShowRowNumbers(boolean showRowNumbers) {
   _table.setShowRowNumbers(showRowNumbers);
 }
 /*
  * @see BaseDataSetViewerDestination#allRowsAdded()
  */
 protected void allRowsAdded() {
   _typedModel.fireTableStructureChanged();
   _table.initColWidths();
 }
 public void moveToTop() {
   if (_table.getRowCount() > 0) {
     _table.setRowSelectionInterval(0, 0);
   }
 }
 public void setColumnDefinitions(ColumnDisplayDefinition[] colDefs) {
   super.setColumnDefinitions(colDefs);
   _table.setColumnDefinitions(colDefs);
 }
 private void onSelectionChanged() {
   if (null != _rowColSelectedCountListener) {
     _rowColSelectedCountListener.rowColSelectedCountChanged(
         _table.getSelectedRowCount(), _table.getSelectedColumnCount());
   }
 }