Пример #1
0
  private void fillColumnCombo(ItemListener listener) {
    // sort column names alphabetically
    final int columnCount = this.list.getTableModel().getColumnCount();
    final String[][] names = new String[columnCount][];
    final int[] indexes = new int[columnCount];
    for (int i = 0; i < columnCount; i++) {
      names[i] = this.list.getColumnNames(i);
      indexes[i] = 0;
    }
    // use column index as columns names are not unique
    final SortedMap<String, Integer> map = solve(names, indexes);
    final List<Column> cols = new ArrayList<Column>(columnCount);
    cols.add(TOUT);
    for (final Entry<String, Integer> e : map.entrySet()) {
      final int colIndex = e.getValue().intValue();
      final String[] colNames = names[colIndex];
      cols.add(new Column(e.getKey(), colNames[colNames.length - 1], colIndex));
    }

    // don't fire when filling, we will fire when selecting
    this.comboColonnePourRecherche.removeItemListener(listener);
    final ListComboBoxModel comboModel =
        (ListComboBoxModel) this.comboColonnePourRecherche.getModel();
    assert !comboModel.isSelectOnAdd() : "Otherwise our following select might not fire";
    comboModel.removeAllElements();
    comboModel.addAll(cols);
    this.comboColonnePourRecherche.addItemListener(listener);
  }