Bug 547963 - [Freeze] Add option to include cell on
FreezePositionCommand
Change-Id: Id1c077cea509ba28f5ce5097de478ba33f876a2b
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezeCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezeCommandHandler.java
index 461f451..c269e34 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezeCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezeCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2018 Original authors and others.
+ * Copyright (c) 2012, 2019 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -63,8 +63,9 @@
// freeze for a given position
FreezePositionCommand freezePositionCommand = (FreezePositionCommand) command;
IFreezeCoordinatesProvider coordinatesProvider = new FreezePositionStrategy(
- this.freezeLayer, this.viewportLayer, freezePositionCommand.getColumnPosition(),
- freezePositionCommand.getRowPosition());
+ this.freezeLayer, this.viewportLayer,
+ freezePositionCommand.getColumnPosition(), freezePositionCommand.getRowPosition(),
+ freezePositionCommand.isInclude());
handleFreezeCommand(coordinatesProvider,
freezePositionCommand.isToggle(),
command.isOverrideFreeze());
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionCommand.java
index 5871c18..e931f92 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Original authors and others.
+ * Copyright (c) 2012, 2019 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,8 +17,7 @@
/**
* Command to freeze at the specified position.
*/
-public class FreezePositionCommand extends AbstractPositionCommand implements
- IFreezeCommand {
+public class FreezePositionCommand extends AbstractPositionCommand implements IFreezeCommand {
/**
* Indicates whether this command should toggle the frozen state between
@@ -33,6 +32,12 @@
private boolean overrideFreeze;
/**
+ * Indicates whether this command should include the selected cell to the
+ * frozen region or not.
+ */
+ private final boolean include;
+
+ /**
* Creates a FreezePositionCommand for the given column and row positions
* related to the given layer, that doesn't toggle or override a current
* frozen state.
@@ -46,8 +51,7 @@
* The row position that will be the bottom row in the frozen
* part.
*/
- public FreezePositionCommand(ILayer layer, int columnPosition,
- int rowPosition) {
+ public FreezePositionCommand(ILayer layer, int columnPosition, int rowPosition) {
this(layer, columnPosition, rowPosition, false);
}
@@ -70,8 +74,7 @@
* frozen and unfrozen, or if it should always result in a frozen
* state.
*/
- public FreezePositionCommand(ILayer layer, int columnPosition,
- int rowPosition, boolean toggle) {
+ public FreezePositionCommand(ILayer layer, int columnPosition, int rowPosition, boolean toggle) {
this(layer, columnPosition, rowPosition, toggle, false);
}
@@ -96,11 +99,43 @@
* whether this command should override a current frozen state or
* if it should be skipped if a frozen state is already applied.
*/
- public FreezePositionCommand(ILayer layer, int columnPosition,
- int rowPosition, boolean toggle, boolean overrideFreeze) {
+ public FreezePositionCommand(ILayer layer, int columnPosition, int rowPosition, boolean toggle, boolean overrideFreeze) {
+ this(layer, columnPosition, rowPosition, toggle, overrideFreeze, false);
+ }
+
+ /**
+ * Creates a FreezePositionCommand for the given column and row positions
+ * related to the given layer. If it should toggle or override the current
+ * frozen state can be specified by parameter.
+ *
+ * @param layer
+ * The layer to which the position coordinates match.
+ * @param columnPosition
+ * The column position that will be the right most column in the
+ * frozen part.
+ * @param rowPosition
+ * The row position that will be the bottom row in the frozen
+ * part.
+ * @param toggle
+ * whether this command should toggle the frozen state between
+ * frozen and unfrozen, or if it should always result in a frozen
+ * state.
+ * @param overrideFreeze
+ * whether this command should override a current frozen state or
+ * if it should be skipped if a frozen state is already applied.
+ * @param include
+ * whether the selected cell should be included in the freeze
+ * region or not. Include means the freeze borders will be to the
+ * right and bottom, while exclude means the freeze borders are
+ * to the left and top. Default is <code>false</code>.
+ *
+ * @since 1.6
+ */
+ public FreezePositionCommand(ILayer layer, int columnPosition, int rowPosition, boolean toggle, boolean overrideFreeze, boolean include) {
super(layer, columnPosition, rowPosition);
this.toggle = toggle;
this.overrideFreeze = overrideFreeze;
+ this.include = include;
}
/**
@@ -113,6 +148,7 @@
super(command);
this.toggle = command.toggle;
this.overrideFreeze = command.overrideFreeze;
+ this.include = command.include;
}
@Override
@@ -125,6 +161,19 @@
return this.overrideFreeze;
}
+ /**
+ *
+ * @return Whether the selected cell should be included to the frozen region
+ * or not. Included means the freeze borders will be to the right
+ * and bottom, exclude means the freeze borders are to the top and
+ * left. Default is <code>false</code>.
+ *
+ * @since 1.6
+ */
+ public boolean isInclude() {
+ return this.include;
+ }
+
@Override
public ILayerCommand cloneCommand() {
return new FreezePositionCommand(this);
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionStrategy.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionStrategy.java
index aa59bf8..41228a3 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionStrategy.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/freeze/command/FreezePositionStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2018 Original authors and others.
+ * Copyright (c) 2012, 2019 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -40,10 +40,32 @@
* @since 1.5
*/
public FreezePositionStrategy(FreezeLayer freezeLayer, ViewportLayer viewportLayer, int columnPosition, int rowPosition) {
+ this(freezeLayer, viewportLayer, columnPosition, rowPosition, false);
+ }
+
+ /**
+ * @param freezeLayer
+ * The {@link FreezeLayer} for the {@link PositionCoordinate}.
+ * @param viewportLayer
+ * The {@link ViewportLayer} needed to calculate the viewport
+ * relative position.
+ * @param columnPosition
+ * The column position based on the CompositeFreezeLayer.
+ * @param rowPosition
+ * The row position based on the CompositeFreezeLayer.
+ * @param include
+ * Whether the last selected cell should be included in the
+ * freeze region or not. Include means the freeze borders will be
+ * to the right and bottom, while exclude means the freeze
+ * borders are to the left and top. Default is
+ * <code>false</code>.
+ * @since 1.6
+ */
+ public FreezePositionStrategy(FreezeLayer freezeLayer, ViewportLayer viewportLayer, int columnPosition, int rowPosition, boolean include) {
this.freezeLayer = freezeLayer;
this.viewportLayer = viewportLayer;
- this.columnPosition = columnPosition;
- this.rowPosition = rowPosition;
+ this.columnPosition = !include ? columnPosition : columnPosition + 1;
+ this.rowPosition = !include ? rowPosition : rowPosition + 1;
}
@Override