blob: 537645f832e5d025c6a97559613aaac5615b2b50 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2012, 2021 Stephan Wahlbrink 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, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.ecommons.waltable.selection;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand;
import org.eclipse.statet.ecommons.waltable.coordinate.LRange;
import org.eclipse.statet.ecommons.waltable.layer.ILayerDim;
import org.eclipse.statet.ecommons.waltable.layer.LayerUtil;
/**
* Abstract command to select column(s)/row(s).
*/
public abstract class AbstractSelectDimPositionsCommand extends AbstractDimPositionsCommand {
private final int selectionFlags;
private long positionToReveal;
public AbstractSelectDimPositionsCommand(final ILayerDim dim,
final long position,
final int selectionFlags) {
this(dim, position,
Collections.singletonList(new LRange(position)),
position, selectionFlags );
}
public AbstractSelectDimPositionsCommand(final ILayerDim dim,
final long refPosition, final Collection<LRange> positions,
final long positionToReveal, final int selectionFlags) {
super(dim, refPosition, positions);
this.positionToReveal= positionToReveal;
this.selectionFlags= selectionFlags;
}
protected AbstractSelectDimPositionsCommand(final AbstractSelectDimPositionsCommand command) {
super(command);
this.positionToReveal= command.positionToReveal;
this.selectionFlags= command.selectionFlags;
}
public int getSelectionFlags() {
return this.selectionFlags;
}
public long getPositionToReveal() {
return this.positionToReveal;
}
@Override
protected boolean convertToTargetLayer(final ILayerDim dim, final long refPosition,
final ILayerDim targetDim) {
if (super.convertToTargetLayer(dim, refPosition, targetDim)) {
if (this.positionToReveal != Long.MIN_VALUE) {
this.positionToReveal= (this.positionToReveal == refPosition) ?
getRefPosition() :
LayerUtil.convertPosition(dim, refPosition, this.positionToReveal,
targetDim );
}
return true;
}
return false;
}
}