Ejemplo n.º 1
0
  /**
   * Gets the model indexes for the given row indexes.
   *
   * @param table the table.
   * @param viewIndexes the view indexes.
   * @return the model indexes.
   * @see #getModelIndex(JTable, Integer)
   * @see #getViewIndexes(JTable, List)
   */
  public static List<Integer> getModelIndexes(JTable table, List<Integer> viewIndexes) {

    Assert.notNull(table, TableUtils.TABLE);
    Assert.notNull(viewIndexes, "viewIndexes");

    final List<Integer> modelIndexes = new ArrayList<Integer>(viewIndexes.size());
    for (int i = 0; i < viewIndexes.size(); ++i) {
      modelIndexes.add(TableUtils.getModelIndex(table, viewIndexes.get(i)));
    }

    return modelIndexes;
  }
Ejemplo n.º 2
0
  /**
   * Gets the entities currently being shown.
   *
   * @param <Q> the type of the rows.
   * @param table the table.
   * @return the visible entities.
   */
  @SuppressWarnings("unchecked")
  public static <Q> List<Q> getVisibleEntities(JTable table) {

    Assert.notNull(table, TableUtils.TABLE);
    Assert.notNull(table.getModel(), "table.getModel()");
    Assert.isTrue(
        table.getModel() instanceof GlazedTableModel,
        "table.getModel() instanceof GlazedTableModel");

    final GlazedTableModel tableModel = (GlazedTableModel) table.getModel();

    final List<Q> rows = new ArrayList<Q>(table.getRowCount());
    for (int i = 0; i < table.getRowCount(); ++i) {

      // JAF, 20100411, fixed a BIG bug retrieving elements: rows.add((Q)
      // tableModel.getElementAt(i));
      rows.add((Q) tableModel.getElementAt(TableUtils.getModelIndex(table, i)));
    }

    return rows;
  }