Search in sources :

Example 1 with IStructuralChangeEvent

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

the class DataChangeLayer method handleLayerEvent.

@SuppressWarnings("unchecked")
@Override
public void handleLayerEvent(ILayerEvent event) {
    // updated and we remember the modifications via DataUpdateEvent
    if (!this.temporaryDataStorage && this.handleDataUpdateEvents && event instanceof DataUpdateEvent) {
        DataUpdateEvent updateEvent = (DataUpdateEvent) event;
        Object key = this.keyHandler.getKey(updateEvent.getColumnPosition(), updateEvent.getRowPosition());
        synchronized (this.dataChanges) {
            // this ensures that a discard really restores the original
            if (!this.dataChanges.containsKey(key)) {
                this.changedColumns.add(updateEvent.getColumnPosition());
                this.changedRows.add(updateEvent.getRowPosition());
                // store an UpdateDataCommand that can be used to revert the
                // change
                this.dataChanges.put(key, new UpdateDataCommand(this, updateEvent.getColumnPosition(), updateEvent.getRowPosition(), updateEvent.getOldValue()));
            } else if ((this.dataChanges.get(key).getNewValue() != null && this.dataChanges.get(key).getNewValue().equals(updateEvent.getNewValue()) || (this.dataChanges.get(key).getNewValue() == null && updateEvent.getNewValue() == null))) {
                // the value was changed back to the original value in
                // the underlying layer simply remove the local storage
                // to not showing the cell as dirty
                this.dataChanges.remove(this.keyHandler.getKey(updateEvent.getColumnPosition(), updateEvent.getRowPosition()));
                rebuildPositionCollections();
            }
        }
    } else if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.getColumnDiffs() == null && structuralChangeEvent.getRowDiffs() == null && structuralChangeEvent.isHorizontalStructureChanged() && structuralChangeEvent.isVerticalStructureChanged()) {
            // Assume everything changed
            clearDataChanges();
        } else if (structuralChangeEvent.isHorizontalStructureChanged() && structuralChangeEvent.getColumnDiffs() != null) {
            if (this.keyHandler.updateOnHorizontalStructuralChange()) {
                Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getColumnDiffs();
                StructuralChangeEventHelper.handleColumnDelete(structuralDiffs, this.dataChanges, this.keyHandler);
                StructuralChangeEventHelper.handleColumnInsert(structuralDiffs, this.dataChanges, this.keyHandler);
            } else {
                removeChangesForDeletedObjects();
            }
        } else if (structuralChangeEvent.isVerticalStructureChanged() && structuralChangeEvent.getRowDiffs() != null) {
            if (this.keyHandler.updateOnVerticalStructuralChange()) {
                Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getRowDiffs();
                StructuralChangeEventHelper.handleRowDelete(structuralDiffs, this.dataChanges, this.keyHandler);
                StructuralChangeEventHelper.handleRowInsert(structuralDiffs, this.dataChanges, this.keyHandler);
            } else {
                removeChangesForDeletedObjects();
            }
        }
        rebuildPositionCollections();
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) DataUpdateEvent(org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Collection(java.util.Collection)

Example 2 with IStructuralChangeEvent

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

the class HierarchicalTreeLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isVerticalStructureChanged()) {
            // recalculate node row indexes
            // build a new collection of nodes to avoid duplication clashes
            // as nodes are equal per column and row index
            int negativeIndex = -1;
            Set<HierarchicalTreeNode> updatedCollapsedNodes = new HashSet<HierarchicalTreeNode>();
            for (HierarchicalTreeNode node : this.collapsedNodes) {
                int newRowIndex = findTopRowIndex(node.columnIndex, node.rowObject);
                // the underlying collection
                if (newRowIndex >= 0) {
                    updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, newRowIndex, this.underlyingList.get(newRowIndex)));
                } else if (this.retainRemovedRowObjectNodes) {
                    updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, negativeIndex, node.rowObject));
                    negativeIndex--;
                }
            }
            this.collapsedNodes.clear();
            this.collapsedNodes.addAll(updatedCollapsedNodes);
            // recalculate hidden rows based on updated collapsed nodes
            Set<Integer> updatedHiddenRows = new HashSet<Integer>();
            for (HierarchicalTreeNode node : this.collapsedNodes) {
                updatedHiddenRows.addAll(getChildIndexes(node.columnIndex, node.rowIndex));
            }
            getHiddenRowIndexes().clear();
            getHiddenRowIndexes().addAll(updatedHiddenRows);
        }
    } else if (event instanceof SearchEvent) {
        PositionCoordinate coord = ((SearchEvent) event).getCellCoordinate();
        if (coord != null) {
            Integer foundIndex = coord.getLayer().getRowIndexByPosition(coord.rowPosition);
            if (getHiddenRowIndexes().contains(foundIndex)) {
                if (this.expandOnSearch) {
                    // not collapsible
                    for (int level = this.nodeColumnMapping.size() - 2; level >= 0; level--) {
                        ILayerCell nodeCell = coord.getLayer().getCellByPosition(this.nodeColumnMapping.get(level), coord.rowPosition);
                        int colIdx = coord.getLayer().getColumnIndexByPosition(nodeCell.getOriginColumnPosition());
                        int rowIdx = coord.getLayer().getRowIndexByPosition(nodeCell.getOriginRowPosition());
                        if (this.collapsedNodes.contains(new HierarchicalTreeNode(colIdx, rowIdx, null))) {
                            expandOrCollapse(colIdx, rowIdx);
                        }
                    }
                } else {
                    // only make the single row visible again
                    getHiddenRowIndexes().remove(foundIndex);
                }
            }
            invalidateCache();
            fireLayerEvent(new ShowRowPositionsEvent(this, Arrays.asList(foundIndex)));
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) SearchEvent(org.eclipse.nebula.widgets.nattable.search.event.SearchEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) HashSet(java.util.HashSet)

Example 3 with IStructuralChangeEvent

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

the class ColumnHideShowLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isHorizontalStructureChanged()) {
            Collection<StructuralDiff> columnDiffs = structuralChangeEvent.getColumnDiffs();
            if (columnDiffs != null && !columnDiffs.isEmpty() && !StructuralChangeEventHelper.isReorder(columnDiffs)) {
                StructuralChangeEventHelper.handleColumnDelete(columnDiffs, this.underlyingLayer, this.hiddenColumnIndexes, false);
                StructuralChangeEventHelper.handleColumnInsert(columnDiffs, this.underlyingLayer, this.hiddenColumnIndexes, false);
            }
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)

Example 4 with IStructuralChangeEvent

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

the class RowHideShowLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isVerticalStructureChanged()) {
            Collection<StructuralDiff> rowDiffs = structuralChangeEvent.getRowDiffs();
            if (rowDiffs != null && !rowDiffs.isEmpty() && !StructuralChangeEventHelper.isReorder(rowDiffs)) {
                StructuralChangeEventHelper.handleRowDelete(rowDiffs, this.underlyingLayer, this.hiddenRowIndexes, false);
                StructuralChangeEventHelper.handleRowInsert(rowDiffs, this.underlyingLayer, this.hiddenRowIndexes, false);
            }
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)

Example 5 with IStructuralChangeEvent

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

the class ColumnReorderLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isHorizontalStructureChanged()) {
            Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getColumnDiffs();
            if (structuralDiffs == null) {
                // Assume everything changed
                populateIndexOrder();
            } else {
                // only react on ADD or DELETE and not on CHANGE
                StructuralChangeEventHelper.handleColumnDelete(structuralDiffs, this.underlyingLayer, this.columnIndexOrder, true);
                StructuralChangeEventHelper.handleColumnInsert(structuralDiffs, this.underlyingLayer, this.columnIndexOrder, true);
                // update index-position mapping
                refreshIndexPositionMapping();
            }
            invalidateCache();
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)

Aggregations

IStructuralChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent)6 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)5 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)1 DataUpdateEvent (org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent)1 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)1