use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent in project nebula.widgets.nattable by eclipse.
the class ColumnGroupHeaderLayerSelectionTest method shouldSelectAllCellsInGroup.
@Test
public void shouldSelectAllCellsInGroup() {
this.gridLayer.doCommand(new ViewportSelectColumnGroupCommand(this.gridLayer, 2, 0, false, false));
assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(0));
assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(1));
assertTrue(this.gridLayer.getBodyLayer().getSelectionLayer().isColumnPositionFullySelected(2));
assertEquals(1, this.layerListener.getEventsCount());
assertTrue(this.layerListener.containsInstanceOf(RowSelectionEvent.class));
RowSelectionEvent event = (RowSelectionEvent) this.layerListener.getReceivedEvent(RowSelectionEvent.class);
Collection<Range> rowPositionRanges = event.getRowPositionRanges();
assertEquals(1, rowPositionRanges.size());
assertEquals(new Range(0, this.gridLayer.getBodyLayer().getSelectionLayer().getRowCount()), rowPositionRanges.iterator().next());
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent in project nebula.widgets.nattable by eclipse.
the class NatTable method handleLayerEvent.
// Events /////////////////////////////////////////////////////////////////
@Override
public void handleLayerEvent(ILayerEvent event) {
List<ILayerListener> currentListeners;
this.eventListenerLock.readLock().lock();
try {
currentListeners = this.listeners;
} finally {
this.eventListenerLock.readLock().unlock();
}
for (ILayerListener layerListener : currentListeners) {
layerListener.handleLayerEvent(event);
}
if (event instanceof CellVisualUpdateEvent) {
CellVisualUpdateEvent update = (CellVisualUpdateEvent) event;
repaintCell(update.getColumnPosition(), update.getRowPosition());
return;
}
if (event instanceof ColumnVisualUpdateEvent) {
ColumnVisualUpdateEvent update = (ColumnVisualUpdateEvent) event;
// if more than one column has changed repaint the whole table
Collection<Range> ranges = update.getColumnPositionRanges();
if (ranges.size() == 1) {
Range range = ranges.iterator().next();
if (range.end - range.start == 1) {
repaintColumn(range.start);
return;
}
}
}
if (event instanceof RowVisualUpdateEvent) {
RowVisualUpdateEvent update = (RowVisualUpdateEvent) event;
// if more than one row has changed repaint the whole table
Collection<Range> ranges = update.getRowPositionRanges();
if (ranges.size() == 1) {
Range range = ranges.iterator().next();
if (range.end - range.start == 1) {
repaintRow(range.start);
return;
}
}
}
if (event instanceof ISelectionEvent) {
if (event instanceof CellSelectionEvent || event instanceof RowSelectionEvent) {
Event e = new Event();
e.widget = this;
try {
notifyListeners(SWT.Selection, e);
} catch (RuntimeException re) {
// $NON-NLS-1$
log.error("Error on SWT selection processing", re);
}
}
// in case of selections we redraw immediately
// this is because with Bug 440037 it was reported that
// NatTable is too lazy in handling selections which
// was caused by the EventConflaterChain that only performs
// updates every 100ms to avoid flickering when handling too
// many refresh operations in a short period
redraw();
} else if (event instanceof IVisualChangeEvent) {
this.conflaterChain.addEvent(event);
}
if (event instanceof CellEditorCreatedEvent) {
CellEditorCreatedEvent editorEvent = (CellEditorCreatedEvent) event;
this.activeCellEditor = editorEvent.getEditor();
Control editorControl = this.activeCellEditor.getEditorControl();
if (editorControl != null && !editorControl.isDisposed()) {
editorControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
NatTable.this.activeCellEditor = null;
ActiveCellEditorRegistry.unregisterActiveCellEditor();
}
});
} else {
this.activeCellEditor = null;
ActiveCellEditorRegistry.unregisterActiveCellEditor();
}
ActiveCellEditorRegistry.registerActiveCellEditor(this.activeCellEditor);
}
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent in project nebula.widgets.nattable by eclipse.
the class SelectRegionCommandHandler method selectRegion.
protected void selectRegion(Rectangle region, boolean withShiftMask, boolean withControlMask, int anchorColumn, int anchorRow) {
Range changedRows = null;
if (SelectionUtils.noShiftOrControl(withShiftMask, withControlMask)) {
// no modifier
this.selectionLayer.clear(false);
this.selectionLayer.selectCell(region.x, region.y, false, false);
this.selectionLayer.selectRegion(region.x, region.y, region.width, region.height);
this.selectionLayer.moveSelectionAnchor(anchorColumn < 0 ? region.x : anchorColumn, anchorRow < 0 ? region.y : anchorRow);
changedRows = new Range(region.y, (region.height < Integer.MAX_VALUE) ? region.y + region.height : this.selectionLayer.getRowCount() - region.y);
} else if (SelectionUtils.bothShiftAndControl(withShiftMask, withControlMask) || SelectionUtils.isShiftOnly(withShiftMask, withControlMask)) {
// SHIFT or CTRL + SHIFT modifier enabled
changedRows = selectRegionWithShiftKey(region, anchorColumn, anchorRow);
} else if (SelectionUtils.isControlOnly(withShiftMask, withControlMask)) {
// CTRL modifier enabled
changedRows = selectRegionWithCtrlKey(region, anchorColumn, anchorRow);
}
// Set last selected position to the recently clicked cell
this.selectionLayer.setLastSelectedCell(region.x, region.y);
this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, changedRows, // position
-1, withShiftMask, withControlMask));
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent in project nebula.widgets.nattable by eclipse.
the class SelectRowCommandHandler method selectRows.
/**
* Performs row selection based on the given informations and fires a
* {@link RowSelectionEvent} for the changed selection.
*
* @param columnPosition
* The column position of the {@link SelectRowsCommand}.
* @param rowPositions
* The row position of the {@link SelectRowsCommand}.
* @param withShiftMask
* The shift mask information of the {@link SelectRowsCommand}.
* @param withControlMask
* The control mask information of the {@link SelectRowsCommand}.
* @param rowPositionToMoveIntoViewport
* Information which row should be moved to the viewport,
* transported by the {@link SelectRowsCommand}.
*/
protected void selectRows(int columnPosition, Collection<Integer> rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport) {
Set<Range> changedRowRanges = new HashSet<Range>();
for (int rowPosition : rowPositions) {
changedRowRanges.addAll(internalSelectRow(columnPosition, rowPosition, withShiftMask, withControlMask));
}
Set<Integer> changedRows = new HashSet<Integer>();
for (Range range : changedRowRanges) {
for (int i = range.start; i < range.end; i++) {
changedRows.add(Integer.valueOf(i));
}
}
this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, changedRows, rowPositionToMoveIntoViewport, withShiftMask, withControlMask));
}
use of org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent in project nebula.widgets.nattable by eclipse.
the class SelectRowGroupCommandHandler method selectRows.
protected void selectRows(int columnPosition, List<Integer> rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport, boolean moveAnchorToTopOfGroup) {
Set<Range> changedRowRanges = new HashSet<Range>();
if (rowPositions.size() > 0) {
changedRowRanges.addAll(internalSelectRow(columnPosition, rowPositions.get(0), rowPositions.size(), withShiftMask, withControlMask, moveAnchorToTopOfGroup));
}
Set<Integer> changedRows = new HashSet<Integer>();
for (Range range : changedRowRanges) {
for (int i = range.start; i < range.end; i++) {
changedRows.add(Integer.valueOf(i));
}
}
this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, changedRows, rowPositionToMoveIntoViewport, withShiftMask, withControlMask));
}
Aggregations