| /*=============================================================================# |
| # Copyright (c) 2012, 2021 Original NatTable authors and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 |
| # |
| # Contributors: |
| # Original NatTable authors and others - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.ecommons.waltable.layer.event; |
| |
| import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; |
| |
| import java.util.ArrayList; |
| import java.util.Arrays; |
| import java.util.Collection; |
| |
| import org.eclipse.statet.ecommons.waltable.coordinate.LRange; |
| import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; |
| import org.eclipse.statet.ecommons.waltable.layer.ILayer; |
| |
| |
| public abstract class RowVisualChangeEvent implements IVisualChangeEvent { |
| |
| private ILayer layer; |
| |
| private Collection<LRange> rowPositionRanges= new ArrayList<>(); |
| |
| public RowVisualChangeEvent(final ILayer layer, final LRange...rowPositionRanges) { |
| this(layer, Arrays.asList(rowPositionRanges)); |
| } |
| |
| public RowVisualChangeEvent(final ILayer layer, final Collection<LRange> rowPositionRanges) { |
| this.layer= layer; |
| this.rowPositionRanges= rowPositionRanges; |
| } |
| |
| // Copy constructor |
| protected RowVisualChangeEvent(final RowVisualChangeEvent event) { |
| this.layer= event.layer; |
| this.rowPositionRanges= event.rowPositionRanges; |
| } |
| |
| @Override |
| public ILayer getLayer() { |
| return this.layer; |
| } |
| |
| public Collection<LRange> getRowPositionRanges() { |
| return this.rowPositionRanges; |
| } |
| |
| @Override |
| public boolean convertToLocal(final ILayer localLayer) { |
| this.rowPositionRanges= localLayer.getDim(VERTICAL).underlyingToLocalPositions( |
| this.layer.getDim(VERTICAL), this.rowPositionRanges ); |
| this.layer= localLayer; |
| |
| return this.rowPositionRanges != null && this.rowPositionRanges.size() > 0; |
| } |
| |
| @Override |
| public Collection<LRectangle> getChangedPositionRectangles() { |
| final Collection<LRectangle> changedPositionRectangles= new ArrayList<>(); |
| |
| final long columnCount= this.layer.getColumnCount(); |
| for (final LRange lRange : this.rowPositionRanges) { |
| changedPositionRectangles.add(new LRectangle(0, lRange.start, columnCount, lRange.end - lRange.start)); |
| } |
| |
| return changedPositionRectangles; |
| } |
| |
| @Override |
| public String toString() { |
| return getClass().getSimpleName(); |
| } |
| |
| } |