| /*=============================================================================# |
| # 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 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; |
| |
| |
| /** |
| * Event indicating a change in the structure of the columns. |
| * This event carried ColumnDiffs (Collection<StructuralDiff>) indicating the columns which have changed. |
| */ |
| public abstract class ColumnStructuralChangeEvent extends ColumnVisualChangeEvent implements IStructuralChangeEvent { |
| |
| /** |
| * Creates a new ColumnStructuralChangeEvent based on the given information. |
| * @param layer The ILayer to which the given column positions match. |
| * @param columnPositionRanges The column position ranges for the columns that have changed. |
| */ |
| public ColumnStructuralChangeEvent(final ILayer layer, final LRange...columnPositionRanges) { |
| this(layer, Arrays.asList(columnPositionRanges)); |
| } |
| |
| /** |
| * Creates a new ColumnStructuralChangeEvent based on the given information. |
| * @param layer The ILayer to which the given column positions match. |
| * @param columnPositionRanges The column position ranges for the columns that have changed. |
| */ |
| public ColumnStructuralChangeEvent(final ILayer layer, final Collection<LRange> columnPositionRanges) { |
| super(layer, columnPositionRanges); |
| } |
| |
| /** |
| * Creates a new ColumnStructuralChangeEvent based on the given instance. |
| * Mainly needed for cloning. |
| * @param event The ColumnStructuralChangeEvent out of which the new instance should be created. |
| */ |
| protected ColumnStructuralChangeEvent(final ColumnStructuralChangeEvent event) { |
| super(event); |
| } |
| |
| @Override |
| public Collection<LRectangle> getChangedPositionRectangles() { |
| final Collection<LRectangle> changedPositionRectangles= new ArrayList<>(); |
| |
| final Collection<LRange> columnPositionRanges= getColumnPositionRanges(); |
| if (columnPositionRanges != null && columnPositionRanges.size() > 0) { |
| long leftmostColumnPosition= Long.MAX_VALUE; |
| for (final LRange lRange : columnPositionRanges) { |
| if (lRange.start < leftmostColumnPosition) { |
| leftmostColumnPosition= lRange.start; |
| } |
| } |
| |
| final long columnCount= getLayer().getColumnCount(); |
| final long rowCount= getLayer().getRowCount(); |
| changedPositionRectangles.add(new LRectangle(leftmostColumnPosition, 0, columnCount - leftmostColumnPosition, rowCount)); |
| } |
| |
| return changedPositionRectangles; |
| } |
| |
| @Override |
| public boolean isHorizontalStructureChanged() { |
| return true; |
| } |
| |
| @Override |
| public boolean isVerticalStructureChanged() { |
| return false; |
| } |
| |
| @Override |
| public Collection<StructuralDiff> getRowDiffs() { |
| return null; |
| } |
| |
| } |