Search in sources :

Example 1 with IRowSorter

use of de.jaret.util.ui.table.model.IRowSorter in project translationstudio8 by heartsome.

the class JaretTable method updateRowList.

/**
     * Update the internal rowlist according to filter and sorter.
     * 
     */
private void updateRowList() {
    _rows = new ArrayList<IRow>();
    if (_model != null) {
        for (int i = 0; i < _model.getRowCount(); i++) {
            IRow row = _model.getRow(i);
            if (i < _fixedRows) {
                // fixed rows are exluded from filtering
                _rows.add(row);
            } else if (_rowFilter == null || (_rowFilter != null && _rowFilter.isInResult(row))) {
                if (!_autoFilterEnabled || _autoFilter.isInResult(row)) {
                    if (!_rows.contains(row)) {
                        _rows.add(row);
                    }
                }
            }
        }
    }
    // sort either by column sort order or by a set row sorter
    RowComparator comparator = new RowComparator();
    IRowSorter rs = null;
    if (comparator.canSort()) {
        rs = comparator;
    } else {
        rs = _rowSorter;
    }
    if (rs != null) {
        List<IRow> fixedRows = new ArrayList<IRow>();
        // the exclusion of the fixed rows may be solved more elegant ...
        if (_excludeFixedRowsFromSorting) {
            for (int i = 0; i < _fixedRows; i++) {
                fixedRows.add(_rows.remove(0));
            }
        }
        Collections.sort(_rows, rs);
        if (_excludeFixedRowsFromSorting) {
            for (int i = fixedRows.size() - 1; i >= 0; i--) {
                _rows.add(0, fixedRows.get(i));
            }
        }
    }
    // to be sure no one misses this
    updateYScrollBar();
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IRowSorter(de.jaret.util.ui.table.model.IRowSorter) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point)

Example 2 with IRowSorter

use of de.jaret.util.ui.table.model.IRowSorter in project translationstudio8 by heartsome.

the class JaretTable method setRowSorter.

/**
     * Set a row sorter. A row sorter will be overruled by sorting setup on columns.
     * 
     * @param rowSorter The rowSorter to set.
     */
public void setRowSorter(IRowSorter rowSorter) {
    IRowSorter oldValue = _rowSorter;
    if (_rowSorter != null) {
        _rowSorter.removePropertyChangeListener(this);
    }
    _rowSorter = rowSorter;
    if (_rowSorter != null) {
        _rowSorter.addPropertyChangeListener(this);
    }
    updateRowList();
    redraw();
    // fire the change for the sorter object
    firePropertyChange(PROPERTYNAME_ROWSORTER, oldValue, _rowSorter);
    // fire the general sorting change
    firePropertyChange(PROPERTYNAME_SORTING, null, "x");
}
Also used : IRowSorter(de.jaret.util.ui.table.model.IRowSorter)

Aggregations

IRowSorter (de.jaret.util.ui.table.model.IRowSorter)2 IRow (de.jaret.util.ui.table.model.IRow)1 ArrayList (java.util.ArrayList)1 Point (org.eclipse.swt.graphics.Point)1