Search in sources :

Example 1 with RowSelectionEvent

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());
}
Also used : ViewportSelectColumnGroupCommand(org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand) RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 2 with RowSelectionEvent

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);
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) CellVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualUpdateEvent) RowVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowVisualUpdateEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CellEditorCreatedEvent(org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent) Control(org.eclipse.swt.widgets.Control) ColumnVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnVisualUpdateEvent) CellSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent) RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) CellVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualUpdateEvent) CellEditorCreatedEvent(org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) CellSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent) ColumnVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnVisualUpdateEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Event(org.eclipse.swt.widgets.Event) RowVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowVisualUpdateEvent) RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) ISelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.ISelectionEvent) ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ISelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.ISelectionEvent)

Example 3 with RowSelectionEvent

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));
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 4 with RowSelectionEvent

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));
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet)

Example 5 with RowSelectionEvent

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));
}
Also used : RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) HashSet(java.util.HashSet)

Aggregations

RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)15 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)9 Test (org.junit.Test)7 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 HashSet (java.util.HashSet)3 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)3 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)3 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)3 HashMap (java.util.HashMap)2 ColumnSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.ColumnSelectionEvent)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)1