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;
}
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();
}
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));
}
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;
}
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;
}
}
}
Aggregations