use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class TickUpdateCommandHandlerTest method shouldNotThrowExceptionOnNoSelection.
@Test
public void shouldNotThrowExceptionOnNoSelection() {
// if no exception occurs this test succeeds
// we also check that no update has been triggered
this.selectionLayer.clear();
this.selectionLayer.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellVisualChangeEvent) {
fail("update triggered");
}
}
});
this.commandHandler.doCommand(new TickUpdateCommand(this.testConfigRegistry, true));
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent 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);
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent 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.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class _5053_SelectionEventsExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
final IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(parent, gridLayer);
// Events are fired whenever selection occurs. These can be use to
// trigger external actions as required.
//
// This adds a custom ILayerListener that will listen and handle
// selection events on NatTable level
natTable.addLayerListener(new ILayerListener() {
// Default selection behavior selects cells by default.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellSelectionEvent) {
CellSelectionEvent cellEvent = (CellSelectionEvent) event;
log("Selected cell: [" + cellEvent.getRowPosition() + ", " + cellEvent.getColumnPosition() + "], " + natTable.getDataValueByPosition(cellEvent.getColumnPosition(), cellEvent.getRowPosition()));
} else if (event instanceof ColumnSelectionEvent) {
ColumnSelectionEvent columnEvent = (ColumnSelectionEvent) event;
log("Selected Column: " + columnEvent.getColumnPositionRanges());
} else if (event instanceof RowSelectionEvent) {
// directly ask the SelectionLayer about the selected rows
// and access the data via IRowDataProvider
Collection<Range> selections = selectionLayer.getSelectedRowPositions();
StringBuilder builder = new StringBuilder("Selected Persons: ").append(selectionLayer.getSelectedRowPositions()).append("[");
for (Range r : selections) {
for (int i = r.start; i < r.end; i++) {
Person p = bodyDataProvider.getRowObject(i);
if (p != null) {
if (!builder.toString().endsWith("[")) {
builder.append(", ");
}
builder.append(p.getFirstName()).append(" ").append(p.getLastName());
}
}
}
builder.append("]");
log(builder.toString());
}
}
});
// Layout widgets
parent.setLayout(new GridLayout(1, true));
natTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
// add a log area to the example to show the log entries
setupTextArea(parent);
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class HideMultipleColumnsIntegrationTest method hideAllColumnsWithColumnGroupsEnabled.
/**
* Exposing bug: http://nattable.org/jira/browse/NTBL-471
*/
@Test
public void hideAllColumnsWithColumnGroupsEnabled() throws Exception {
BodyLayerStackFixture<RowDataFixture> bodyLayerStackFixture = new BodyLayerStackFixture<RowDataFixture>(GlazedLists.eventList(RowDataListFixture.getList()), new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()), new ConfigRegistry());
NatTableFixture natTableFixture = new NatTableFixture(bodyLayerStackFixture);
LayerListenerFixture listenerFixture = new LayerListenerFixture();
natTableFixture.addLayerListener(listenerFixture);
Assert.assertEquals(37, bodyLayerStackFixture.getBodyDataProvider().getColumnCount());
Assert.assertEquals(6, natTableFixture.getColumnCount());
MultiColumnHideCommand hideAllCommand = new MultiColumnHideCommand(natTableFixture, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 });
natTableFixture.doCommand(hideAllCommand);
Assert.assertEquals(1, listenerFixture.getEventsCount());
ILayerEvent receivedEvent = listenerFixture.getReceivedEvent(HideColumnPositionsEvent.class);
Assert.assertNotNull(receivedEvent);
}
Aggregations