Search in sources :

Example 1 with IVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class ViewportLayerTest method settingViewportRowOriginFireEvent.

@Test
public void settingViewportRowOriginFireEvent() throws Exception {
    this.viewportLayer.addLayerListener(this.layerListener);
    this.viewportLayer.setOriginY(this.viewportLayer.getStartYOfRowPosition(1));
    assertEquals(1, this.viewportLayer.getRowIndexByPosition(0));
    ILayerEvent event = this.layerListener.getReceivedEvents().get(0);
    assertTrue(event instanceof IVisualChangeEvent);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Test(org.junit.Test)

Example 2 with IVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent 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 IVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class ViewportLayerTest method settingViewportColumnOriginFiresEvent.

@Test
public void settingViewportColumnOriginFiresEvent() throws Exception {
    this.viewportLayer.addLayerListener(this.layerListener);
    this.viewportLayer.setOriginX(this.viewportLayer.getStartXOfColumnPosition(2));
    ILayerEvent event = this.layerListener.getReceivedEvents().get(0);
    assertTrue(event instanceof IVisualChangeEvent);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Test(org.junit.Test)

Example 4 with IVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class ViewportLayerTest method testMoveColumnPositionIntoViewportFiresEvent.

/*
     * Scrolling Events fired when origin changes
     */
@Test
public void testMoveColumnPositionIntoViewportFiresEvent() throws Exception {
    this.viewportLayer.addLayerListener(this.layerListener);
    this.viewportLayer.moveColumnPositionIntoViewport(4);
    ILayerEvent event = this.layerListener.getReceivedEvents().get(0);
    assertTrue(event instanceof IVisualChangeEvent);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Test(org.junit.Test)

Aggregations

ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)4 IVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent)4 Test (org.junit.Test)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)1 CellEditorCreatedEvent (org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent)1 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)1 CellVisualUpdateEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualUpdateEvent)1 ColumnVisualUpdateEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnVisualUpdateEvent)1 RowVisualUpdateEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowVisualUpdateEvent)1 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)1 ISelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.ISelectionEvent)1 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)1 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 Control (org.eclipse.swt.widgets.Control)1 Event (org.eclipse.swt.widgets.Event)1