blob: 17f6d8fac4b2ee02e79d05d6e11cd6e05fc81b66 [file] [log] [blame]
/*=============================================================================#
# 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.selection;
import java.util.Collection;
import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand;
import org.eclipse.statet.ecommons.waltable.coordinate.LRange;
import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList;
import org.eclipse.statet.ecommons.waltable.layer.ILayer;
import org.eclipse.statet.ecommons.waltable.layer.ILayerDim;
import org.eclipse.statet.ecommons.waltable.layer.LayerUtil;
public class SelectDimPositionsCommand extends AbstractDimPositionsCommand {
private final int selectionFlags;
private long orthogonalPosition;
private long positionToReveal;
public SelectDimPositionsCommand(final ILayerDim layerDim,
final long position, final long orthogonalPosition,
final int selectionFlags) {
this(layerDim, position, new LRangeList(position), orthogonalPosition, selectionFlags,
position );
}
public SelectDimPositionsCommand(final ILayerDim layerDim,
final long refPosition, final Collection<LRange> positions,
final long orthogonalPosition, final int selectionFlags, final long positionToReveal) {
super(layerDim, refPosition, positions);
this.orthogonalPosition= orthogonalPosition;
this.selectionFlags= selectionFlags;
this.positionToReveal= positionToReveal;
}
protected SelectDimPositionsCommand(final SelectDimPositionsCommand command) {
super(command);
this.orthogonalPosition= command.orthogonalPosition;
this.selectionFlags= command.selectionFlags;
this.positionToReveal= command.positionToReveal;
}
@Override
public SelectDimPositionsCommand cloneCommand() {
return new SelectDimPositionsCommand(this);
}
@Override
public boolean convertToTargetLayer(final ILayer targetLayer) {
final ILayerDim layerDim= getDim();
final long targetOrthogonalPosition= LayerUtil.convertPosition(
layerDim.getLayer().getDim(getOrientation().getOrthogonal()),
this.orthogonalPosition, this.orthogonalPosition,
targetLayer.getDim(getOrientation().getOrthogonal()) );
if (targetOrthogonalPosition != ILayerDim.POSITION_NA
&& super.convertToTargetLayer(targetLayer) ) {
this.orthogonalPosition= targetOrthogonalPosition;
this.positionToReveal= LayerUtil.convertPosition(layerDim,
this.positionToReveal, this.positionToReveal,
targetLayer.getDim(getOrientation()) );
return true;
}
return false;
}
public long getOrthogonalPosition() {
return this.orthogonalPosition;
}
public int getSelectionFlags() {
return this.selectionFlags;
}
public long getPositionToReveal() {
return this.positionToReveal;
}
}