use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerSummaryRowConcurrencyTest method shouldCorrectlyCalculateSummaryValues.
// summary value == 55
@Test
public void shouldCorrectlyCalculateSummaryValues() {
this.summaryRowLayer.addLayerListener(new ILayerListener() {
@Override
public synchronized void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellVisualChangeEvent) {
GroupByDataLayerSummaryRowConcurrencyTest.this.calcCount++;
}
}
});
assertNull(this.summaryRowLayer.getDataValueByPosition(0, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(1, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(2, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(3, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(4, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(5, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(6, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(7, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(8, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(9, 0));
assertNull(this.summaryRowLayer.getDataValueByPosition(10, 0));
while (this.calcCount < 11) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(0, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(1, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(2, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(3, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(4, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(5, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(6, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(7, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(8, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(9, 0));
assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(10, 0));
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class RowSelectionIntegrationTest method onlySelectRowEventsFired.
@Test
public void onlySelectRowEventsFired() {
this.nattable.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellSelectionEvent) {
fail("CellSelectionEvent fired for row selection");
}
}
});
this.nattable.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 0, false, false));
// the second call first clears the selection and then applies the new
// one clearing by default also fires a CellSelectionEvent with negative
// values
this.nattable.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 3, false, false));
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class GlazedListsEventLayer method getEventNotifier.
/**
* Fires a NatTable refresh event, if any glazed list events have occurred.
*/
protected Runnable getEventNotifier() {
return new Runnable() {
@Override
public void run() {
if (GlazedListsEventLayer.this.eventsToProcess && GlazedListsEventLayer.this.active) {
ILayerEvent layerEvent;
if (GlazedListsEventLayer.this.structuralChangeEventsToProcess) {
layerEvent = new RowStructuralRefreshEvent(getUnderlyingLayer());
} else {
layerEvent = new VisualRefreshEvent(getUnderlyingLayer());
}
fireEventFromSWTDisplayThread(layerEvent);
GlazedListsEventLayer.this.eventsToProcess = false;
GlazedListsEventLayer.this.structuralChangeEventsToProcess = false;
}
}
};
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project tdq-studio-se by Talend.
the class DataSampleTable method addCustomSelectionBehaviour.
private void addCustomSelectionBehaviour() {
natTable.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof ColumnHeaderSelectionEvent) {
ColumnHeaderSelectionEvent columnEvent = (ColumnHeaderSelectionEvent) event;
Collection<Range> ranges = columnEvent.getColumnPositionRanges();
if (ranges.size() > 0) {
Range range = ranges.iterator().next();
handleColumnSelectionChange(range.start);
}
} else if (event instanceof ColumnReorderEvent) {
if (ColumnIndexMap == null) {
ColumnIndexMap = new HashMap<String, Integer>();
} else {
ColumnIndexMap.clear();
}
// save propertyNames oder into lastTimePropertyNameOrder
initPropertyNameOrder();
// Fill elements into ColumnIndexMap before the order change ones.
fillPreElement();
// Fill the oder all of elements which display on the table into ColumnIndexMap
fillElementWhichDisplayOnTable();
// Fill the oder all of elements which after the order change ones.
fillEndElement();
// update newest order state on the lastTimePropertyNameOrder list
savePropertyNameState();
notifyObservers();
}
}
/**
* DOC talend Comment method "fillElementWhichDisplayOnTable". copy by #fillElementWhichDisplayOnTable
*/
private void fillElementWhichDisplayOnTable() {
for (int index = 1; index < natTable.getColumnCount(); index++) {
int columnIndexByPosition = natTable.getColumnIndexByPosition(index);
ColumnIndexMap.put(propertyNames[columnIndexByPosition], ColumnIndexMap.size());
}
}
private void fillEndElement() {
for (int index = ColumnIndexMap.size(); index < propertyNames.length; index++) {
ColumnIndexMap.put(lastTimePropertyNameOrder.get(index), index);
}
}
private void fillPreElement() {
int disColumnCount = natTable.getColumnCount() - 1;
// display all case so that no preElement one need to be filled
if (disColumnCount >= lastTimePropertyNameOrder.size()) {
return;
}
// not all display
String endName = propertyNames[natTable.getColumnIndexByPosition(1)];
int firstOneLastPosition = lastTimePropertyNameOrder.indexOf(endName);
endName = propertyNames[natTable.getColumnIndexByPosition(2)];
int secondOneLastPosition = lastTimePropertyNameOrder.indexOf(endName);
if (secondOneLastPosition - firstOneLastPosition > 0) {
// 1 is not be change order case
endName = lastTimePropertyNameOrder.get(firstOneLastPosition);
// For example 1->2+
if (secondOneLastPosition - firstOneLastPosition == 1) {
String moveColName = findMoveColumnName(firstOneLastPosition - 1);
if (moveColName != null) {
endName = moveColName;
}
}
// For example 1->2,2+->1
} else if (secondOneLastPosition - firstOneLastPosition < 0) {
// in fact the value shoud be
// firstOneLastPosition+secondOneLastPosition-firstOneLastPosition
endName = lastTimePropertyNameOrder.get(secondOneLastPosition);
}
// ~ not all display
int index = 0;
for (String propertyName : lastTimePropertyNameOrder) {
if (endName.equals(propertyName)) {
break;
}
ColumnIndexMap.put(propertyName, index++);
}
}
/**
* Find the column name which be moved on the ui
*
* @param spacing
* @return
*/
private String findMoveColumnName(int spacing) {
for (int index = 3; index < natTable.getColumnCount() - 1; index++) {
String propertyName = propertyNames[natTable.getColumnIndexByPosition(index)];
int lastPosition = lastTimePropertyNameOrder.indexOf(propertyName);
if (spacing > lastPosition - index) {
return propertyName;
} else if (spacing == lastPosition - index) {
continue;
} else {
break;
}
}
return null;
}
});
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent in project nebula.widgets.nattable by eclipse.
the class SearchGridCommandHandlerTest method doTestOnSelection.
private void doTestOnSelection() throws PatternSyntaxException {
// Register call back
final ILayerListener listener = new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof SearchEvent) {
// Check event, coordinate should be in composite layer
// coordinates
SearchEvent searchEvent = (SearchEvent) event;
if (SearchGridCommandHandlerTest.this.expected != null) {
assertEquals(SearchGridCommandHandlerTest.this.expected.columnPosition, searchEvent.getCellCoordinate().getColumnPosition());
assertEquals(SearchGridCommandHandlerTest.this.expected.rowPosition, searchEvent.getCellCoordinate().getRowPosition());
} else {
assertNull(searchEvent.getCellCoordinate());
}
}
}
};
this.gridLayer.addLayerListener(listener);
try {
SelectionLayer selectionLayer = this.gridLayer.getBodyLayer().getSelectionLayer();
final SelectionSearchStrategy gridSearchStrategy = new SelectionSearchStrategy(this.configRegistry, this.isColumnFirst);
final SearchCommand searchCommand = new SearchCommand(this.searchText, selectionLayer, gridSearchStrategy, this.isForward ? ISearchDirection.SEARCH_FORWARD : ISearchDirection.SEARCH_BACKWARDS, this.isWrapSearch, this.isCaseSensitive, this.isWholeWord, this.isIncremental, this.isRegex, this.isIncludeCollapsed, new CellValueAsStringComparator<>());
this.commandHandler.doCommand(selectionLayer, searchCommand);
final PositionCoordinate searchResultCellCoordinate = this.commandHandler.getSearchResultCellCoordinate();
if (this.expected != null) {
assertEquals(this.expected.columnPosition, searchResultCellCoordinate.columnPosition);
assertEquals(this.expected.rowPosition, searchResultCellCoordinate.rowPosition);
assertEquals(50, selectionLayer.getSelectedCellPositions().length);
assertEquals(this.expected.columnPosition, selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(this.expected.rowPosition, selectionLayer.getSelectionAnchor().getRowPosition());
} else {
assertNull(searchResultCellCoordinate);
}
} finally {
this.gridLayer.removeLayerListener(listener);
}
}
Aggregations