Search in sources :

Example 1 with SortDirectionEnum

use of org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum in project nebula.widgets.nattable by eclipse.

the class SortCommandHandler method doCommand.

@Override
public boolean doCommand(final SortColumnCommand command) {
    final int columnIndex = command.getLayer().getColumnIndexByPosition(command.getColumnPosition());
    final SortDirectionEnum newSortDirection = (command.getSortDirection()) != null ? command.getSortDirection() : this.sortModel.getSortDirection(columnIndex).getNextSortDirection();
    // Fire command - with busy indicator
    Runnable sortRunner = new Runnable() {

        @Override
        public void run() {
            SortCommandHandler.this.sortModel.sort(columnIndex, newSortDirection, command.isAccumulate());
        }
    };
    BusyIndicator.showWhile(null, sortRunner);
    // Fire event
    SortColumnEvent sortEvent = new SortColumnEvent(this.sortHeaderLayer, command.getColumnPosition());
    this.sortHeaderLayer.fireLayerEvent(sortEvent);
    return true;
}
Also used : SortColumnEvent(org.eclipse.nebula.widgets.nattable.sort.event.SortColumnEvent) SortDirectionEnum(org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum)

Example 2 with SortDirectionEnum

use of org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum in project tdq-studio-se by Talend.

the class DataSampleTable method sortByColumn.

// sort by the current selected column
public void sortByColumn(List<ModelElement> columns) {
    if (columns == null || columns.size() < 1) {
        return;
    }
    // if the next sort direction is back to original
    SortDirectionEnum nextSortDirection = sortState.getNextSortDirection();
    List<Object[]> sortedData = bodyDataProvider.getList();
    if (SortDirectionEnum.NONE.equals(nextSortDirection) && isContainGID) {
        // if the data has GID, back to order by GID
        sortedData = MatchRuleAnlaysisUtils.sortResultByGID(propertyNames, sortedData);
    } else {
        sortedData = MatchRuleAnlaysisUtils.sortDataByColumn(sortState, sortedData, columns);
    }
    // refresh the table by the sorted data
    Composite parent = this.natTable.getParent();
    createTableControl(parent, sortedData);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    // add sort data function
    natTable.addConfiguration(new DefaultSortConfiguration());
    natTable.configure();
    this.natTable.redraw();
    parent.getParent().layout();
    parent.layout();
}
Also used : DefaultSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration) Composite(org.eclipse.swt.widgets.Composite) SortDirectionEnum(org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum)

Example 3 with SortDirectionEnum

use of org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayer method update.

@Override
public void update(Observable o, Object arg) {
    // if we know the sort model, we need to clear the sort model to avoid
    // strange side effects while updating the tree structure (e.g. not
    // applied sorting although showing the sort indicator)
    // for better user experience we remember the sort state and reapply it
    // after the tree update
    List<Integer> sortedIndexes = null;
    List<SortDirectionEnum> sortDirections = null;
    if (this.treeFormat.getSortModel() != null) {
        sortedIndexes = this.treeFormat.getSortModel().getSortedColumnIndexes();
        sortDirections = new ArrayList<SortDirectionEnum>();
        for (Integer index : sortedIndexes) {
            sortDirections.add(this.treeFormat.getSortModel().getSortDirection(index));
        }
        this.treeFormat.getSortModel().clear();
    }
    updateTree();
    // re-apply the sorting after the tree update
    if (this.treeFormat.getSortModel() != null) {
        for (int i = 0; i < sortedIndexes.size(); i++) {
            Integer index = sortedIndexes.get(i);
            this.treeFormat.getSortModel().sort(index, sortDirections.get(i), true);
        }
    }
    fireLayerEvent(new RowStructuralRefreshEvent(this));
}
Also used : RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) SortDirectionEnum(org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum)

Example 4 with SortDirectionEnum

use of org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum in project nebula.widgets.nattable by eclipse.

the class HierarchicalWrapperSortModel method getComparatorsForColumnIndex.

@SuppressWarnings("rawtypes")
@Override
public List<Comparator> getComparatorsForColumnIndex(int columnIndex) {
    SortDirectionEnum sort = this.sortingState.get(columnIndex);
    // we only support one comparator per column
    if (sort == null) {
        return null;
    } else {
        List<Comparator> result = new ArrayList<Comparator>();
        result.add(getColumnComparator(columnIndex));
        return result;
    }
// this does not compile with Java 6 but would with Java 8
// return sort != null ? Arrays.asList(getColumnComparator(columnIndex))
// : null;
}
Also used : ArrayList(java.util.ArrayList) SortDirectionEnum(org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum) NullComparator(org.eclipse.nebula.widgets.nattable.config.NullComparator) Comparator(java.util.Comparator) HierarchicalWrapperComparator(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator)

Example 5 with SortDirectionEnum

use of org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum in project nebula.widgets.nattable by eclipse.

the class SortableTreeComparator method compare.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int compare(T o1, T o2) {
    int treeComparatorResult = this.treeComparator.compare(o1, o2);
    if (treeComparatorResult == 0) {
        return 0;
    } else {
        List<Integer> sortedColumnIndexes = this.sortModel.getSortedColumnIndexes();
        if (sortedColumnIndexes != null && sortedColumnIndexes.size() > 0) {
            List<Comparator<T>> comparators = new ArrayList<Comparator<T>>();
            for (int sortedColumnIndex : sortedColumnIndexes) {
                // get comparator for column index... somehow
                List<Comparator> columnComparators = this.sortModel.getComparatorsForColumnIndex(sortedColumnIndex);
                if (columnComparators != null) {
                    SortDirectionEnum sortDirection = this.sortModel.getSortDirection(sortedColumnIndex);
                    for (Comparator columnComparator : columnComparators) {
                        switch(sortDirection) {
                            case ASC:
                                comparators.add(columnComparator);
                                break;
                            case DESC:
                                comparators.add(Collections.reverseOrder(columnComparator));
                                break;
                        }
                    }
                }
            }
            comparators.add(this.treeComparator);
            return new ComparatorChain<T>(comparators).compare(o1, o2);
        } else {
            return treeComparatorResult;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SortDirectionEnum(org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum) Comparator(java.util.Comparator)

Aggregations

SortDirectionEnum (org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum)5 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 NullComparator (org.eclipse.nebula.widgets.nattable.config.NullComparator)1 HierarchicalWrapperComparator (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator)1 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)1 DefaultSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration)1 SortColumnEvent (org.eclipse.nebula.widgets.nattable.sort.event.SortColumnEvent)1 Composite (org.eclipse.swt.widgets.Composite)1