Search in sources :

Example 16 with ILayerEvent

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));
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) CellVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent) Test(org.junit.Test)

Example 17 with ILayerEvent

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));
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) CellSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 18 with ILayerEvent

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;
            }
        }
    };
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) VisualRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.VisualRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)

Example 19 with ILayerEvent

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;
        }
    });
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ColumnHeaderSelectionEvent(org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent) Collection(java.util.Collection) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 20 with ILayerEvent

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);
    }
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) SearchEvent(org.eclipse.nebula.widgets.nattable.search.event.SearchEvent) SelectionSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy)

Aggregations

ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)28 Test (org.junit.Test)17 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)14 HashSet (java.util.HashSet)4 IVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)4 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 BigDecimal (java.math.BigDecimal)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)3 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)3 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)2 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)2