use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RowSelectionModel method getSelectedRowPositions.
@Override
public Set<Range> getSelectedRowPositions() {
Set<Range> selectedRowRanges = new HashSet<Range>();
this.selectionsLock.readLock().lock();
try {
for (Serializable rowId : this.selectedRows.keySet()) {
int rowPosition = getRowPositionById(rowId);
selectedRowRanges.add(new Range(rowPosition, rowPosition + 1));
}
} finally {
this.selectionsLock.readLock().unlock();
}
return selectedRowRanges;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class RowSelectionModel method handleLayerEvent.
@Override
public void handleLayerEvent(IStructuralChangeEvent event) {
// handling for deleting rows
if (event.isVerticalStructureChanged()) {
// the change is already done and we don't know about indexes, so we
// need to check if the selected objects still exist
Collection<Serializable> keysToRemove = new ArrayList<Serializable>();
for (Map.Entry<Serializable, R> entry : this.selectedRows.entrySet()) {
int rowIndex = this.rowDataProvider.indexOfRowObject(entry.getValue());
if (rowIndex == -1) {
keysToRemove.add(entry.getKey());
}
}
this.selectionsLock.readLock().lock();
try {
for (Serializable toRemove : keysToRemove) {
this.selectedRows.remove(toRemove);
}
} finally {
this.selectionsLock.readLock().unlock();
}
// change for all deleted rows
if (!keysToRemove.isEmpty()) {
Collection<Integer> rowPositions = new HashSet<Integer>();
Collection<StructuralDiff> diffs = event.getRowDiffs();
if (diffs != null) {
for (StructuralDiff rowDiff : diffs) {
if (rowDiff.getDiffType() != null && rowDiff.getDiffType().equals(DiffTypeEnum.DELETE)) {
Range beforePositionRange = rowDiff.getBeforePositionRange();
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
rowPositions.add(i);
}
}
}
}
// if there is no diff in the event we assume everything has
// changed, in such a case we are not able to fire an
// appropriate event the layer stack upwards since it will be
// stopped while converting it to the target layer
// for the RowSelectionProvider this is sufficient because it
// registers itself as a listener to the SelectionLayer and
// therefore gets informed about the selection change
this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, rowPositions, -1, false, false));
}
}
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class SelectionUtils method getSelectedRowObjects.
/**
* Inspects the current selection on the given {@link SelectionLayer} and
* returns a list of the corresponding list item objects. Uses the
* {@link IRowDataProvider} to be able to determine the row objects per
* selected row position.
*
* @param selectionLayer
* The {@link SelectionLayer} to retrieve the selected row
* indexes from.
* @param rowDataProvider
* The {@link IRowDataProvider} to retrieve the object for the
* row index.
* @param fullySelectedRowsOnly
* Flag to determine if only fully selected rows should be taken
* into account.
* @return The list of all objects that are currently marked as selected.
* Never <code>null</code>.
*
* @since 1.4
*/
public static <T> List<T> getSelectedRowObjects(SelectionLayer selectionLayer, IRowDataProvider<T> rowDataProvider, boolean fullySelectedRowsOnly) {
List<RowObjectIndexHolder<T>> rows = new ArrayList<RowObjectIndexHolder<T>>();
if (selectionLayer != null) {
if (fullySelectedRowsOnly) {
for (int rowPosition : selectionLayer.getFullySelectedRowPositions()) {
addToSelection(rows, rowPosition, selectionLayer, rowDataProvider);
}
} else {
Set<Range> rowRanges = selectionLayer.getSelectedRowPositions();
for (Range rowRange : rowRanges) {
for (int rowPosition = rowRange.start; rowPosition < rowRange.end; rowPosition++) {
addToSelection(rows, rowPosition, selectionLayer, rowDataProvider);
}
}
}
}
Collections.sort(rows);
List<T> rowObjects = new ArrayList<T>(rows.size());
for (RowObjectIndexHolder<T> holder : rows) {
rowObjects.add(holder.getRow());
}
return rowObjects;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModel method getSelectedRowPositions.
@Override
public Set<Range> getSelectedRowPositions() {
HashSet<Range> visiblySelectedRowPositions = new HashSet<Range>();
this.selectionsLock.readLock().lock();
try {
for (Selections.Row<T> row : this.selections.getRows()) {
int rowPosition = getRowPositionByRowObject(row.getRowObject());
if (isRowVisible(rowPosition)) {
visiblySelectedRowPositions.add(new Range(rowPosition, rowPosition + 1));
}
}
} finally {
this.selectionsLock.readLock().unlock();
}
return visiblySelectedRowPositions;
}
use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.
the class ViewportLayer method processColumnSelection.
/**
* Handle {@link ColumnSelectionEvent}
*
* @param selectionEvent
* The event to handle
*/
private void processColumnSelection(ColumnSelectionEvent selectionEvent) {
for (Range columnPositionRange : selectionEvent.getColumnPositionRanges()) {
moveColumnPositionIntoViewport(columnPositionRange.end - 1);
adjustHorizontalScrollBar();
}
}
Aggregations