Bug 568712 - Add commands for hiding columns/rows by index
Change-Id: I1f4ed0c6bf7ed8b1ccd2a33fdaa6f50f06181ec7
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnCommandTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnCommandTest.java
index 9758103..6145bb6 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnCommandTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnCommandTest.java
@@ -47,4 +47,20 @@ public void shouldHideColumn() {
() -> assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(3)));
}
+ @Test
+ public void shouldHideColumnByIndex() {
+ ILayerCommand hideColumnCommand = new HideColumnByIndexCommand(2);
+
+ assertEquals(5, this.columnHideShowLayer.getColumnCount());
+
+ this.columnHideShowLayer.doCommand(hideColumnCommand);
+
+ assertAll("column hidden",
+ () -> assertEquals(4, this.columnHideShowLayer.getColumnCount()),
+ () -> assertEquals(0, this.columnHideShowLayer.getColumnIndexByPosition(0)),
+ () -> assertEquals(1, this.columnHideShowLayer.getColumnIndexByPosition(1)),
+ () -> assertEquals(3, this.columnHideShowLayer.getColumnIndexByPosition(2)),
+ () -> assertEquals(4, this.columnHideShowLayer.getColumnIndexByPosition(3)));
+ }
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowCommandTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowCommandTest.java
index 815a101..a182260 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowCommandTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowCommandTest.java
@@ -51,6 +51,24 @@ public void shouldHideRow() {
}
@Test
+ public void shouldHideRowByIndex() {
+ ILayerCommand hideRowCommand = new HideRowByIndexCommand(2);
+
+ assertEquals(7, this.rowHideShowLayer.getRowCount());
+
+ this.rowHideShowLayer.doCommand(hideRowCommand);
+
+ assertAll("row hidden",
+ () -> assertEquals(6, this.rowHideShowLayer.getRowCount()),
+ () -> assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0)),
+ () -> assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1)),
+ () -> assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(2)),
+ () -> assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(3)),
+ () -> assertEquals(5, this.rowHideShowLayer.getRowIndexByPosition(4)),
+ () -> assertEquals(6, this.rowHideShowLayer.getRowIndexByPosition(5)));
+ }
+
+ @Test
public void shouldNotConvertOnInvalidPosition() {
RowReorderLayer layer = new RowReorderLayer(this.rowHideShowLayer);
ILayerCommand hideRowCommand = new MultiRowHideCommand(layer, 10);
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ColumnHideShowLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ColumnHideShowLayer.java
index cabd26a..8869950 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ColumnHideShowLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ColumnHideShowLayer.java
@@ -23,6 +23,7 @@
import org.eclipse.collections.impl.factory.primitive.IntSets;
import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnShowCommandHandler;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.HideColumnByIndexCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnShowCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommandHandler;
@@ -61,6 +62,7 @@ public ColumnHideShowLayer(IUniqueIndexLayer underlyingLayer) {
registerCommandHandler(new ShowAllColumnsCommandHandler(this));
registerCommandHandler(new MultiColumnShowCommandHandler(this));
registerCommandHandler(new ColumnShowCommandHandler(this));
+ registerCommandHandler(new HideColumnByIndexCommandHandler(this));
}
@Override
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ResizeColumnHideShowLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ResizeColumnHideShowLayer.java
index 8e44bd1..c75302b 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ResizeColumnHideShowLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/ResizeColumnHideShowLayer.java
@@ -27,6 +27,7 @@
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnShowCommandHandler;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.HideColumnByIndexCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnShowCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommandHandler;
@@ -96,6 +97,7 @@ public ResizeColumnHideShowLayer(IUniqueIndexLayer underlyingLayer, DataLayer bo
registerCommandHandler(new ShowAllColumnsCommandHandler(this));
registerCommandHandler(new MultiColumnShowCommandHandler(this));
registerCommandHandler(new ColumnShowCommandHandler(this));
+ registerCommandHandler(new HideColumnByIndexCommandHandler(this));
}
// Persistence
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowHideShowLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowHideShowLayer.java
index 0fc2832..dec153d 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowHideShowLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowHideShowLayer.java
@@ -21,6 +21,7 @@
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.factory.primitive.IntLists;
import org.eclipse.collections.impl.factory.primitive.IntSets;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.HideRowByIndexCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowShowCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommandHandler;
@@ -54,6 +55,7 @@ public RowHideShowLayer(IUniqueIndexLayer underlyingLayer) {
registerCommandHandler(new MultiRowShowCommandHandler(this));
registerCommandHandler(new RowPositionHideCommandHandler(this));
registerCommandHandler(new RowShowCommandHandler(this));
+ registerCommandHandler(new HideRowByIndexCommandHandler(this));
}
@Override
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowIdHideShowLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowIdHideShowLayer.java
index d71b4d5..64ca335 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowIdHideShowLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/RowIdHideShowLayer.java
@@ -29,6 +29,7 @@
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor;
import org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.HideRowByIndexCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowShowCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommandHandler;
@@ -84,6 +85,7 @@ public RowIdHideShowLayer(IUniqueIndexLayer underlyingLayer, IRowDataProvider<T>
registerCommandHandler(new MultiRowShowCommandHandler(this));
registerCommandHandler(new RowPositionHideCommandHandler(this));
registerCommandHandler(new RowShowCommandHandler(this));
+ registerCommandHandler(new HideRowByIndexCommandHandler(this));
}
@Override
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnByIndexCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnByIndexCommand.java
new file mode 100644
index 0000000..103084f
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnByIndexCommand.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Original 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 authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.hideshow.command;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractContextFreeCommand;
+
+/**
+ * Hide a column by index instead of position. Intended to be used to
+ * programmatically hide columns in complex compositions.
+ *
+ * @since 2.0
+ */
+public class HideColumnByIndexCommand extends AbstractContextFreeCommand {
+
+ private int[] columnIndexes;
+
+ /**
+ *
+ * @param columnIndexes
+ * The column indexes that should be hidden.
+ */
+ public HideColumnByIndexCommand(int... columnIndexes) {
+ this.columnIndexes = columnIndexes;
+ }
+
+ /**
+ * Clone constructor.
+ *
+ * @param command
+ * The command to clone.
+ */
+ protected HideColumnByIndexCommand(HideColumnByIndexCommand command) {
+ this.columnIndexes = command.columnIndexes;
+ }
+
+ @Override
+ public HideColumnByIndexCommand cloneCommand() {
+ return new HideColumnByIndexCommand(this);
+ }
+
+ /**
+ *
+ * @return The column indexes that should be hidden.
+ */
+ public int[] getColumnIndexes() {
+ return this.columnIndexes;
+ }
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnByIndexCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnByIndexCommandHandler.java
new file mode 100644
index 0000000..af84cd7
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideColumnByIndexCommandHandler.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Original 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 authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.hideshow.command;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.command.ILayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.hideshow.IColumnHideShowLayer;
+
+/**
+ * {@link ILayerCommandHandler} for the {@link HideColumnByIndexCommand}. Hides
+ * columns identified by index via {@link IColumnHideShowLayer}.
+ *
+ * @since 2.0
+ */
+public class HideColumnByIndexCommandHandler extends AbstractLayerCommandHandler<HideColumnByIndexCommand> {
+
+ private final IColumnHideShowLayer columnHideShowLayer;
+
+ /**
+ *
+ * @param columnHideShowLayer
+ * The {@link IColumnHideShowLayer} on which this command handler
+ * should operate.
+ */
+ public HideColumnByIndexCommandHandler(IColumnHideShowLayer columnHideShowLayer) {
+ this.columnHideShowLayer = columnHideShowLayer;
+ }
+
+ @Override
+ public Class<HideColumnByIndexCommand> getCommandClass() {
+ return HideColumnByIndexCommand.class;
+ }
+
+ @Override
+ protected boolean doCommand(HideColumnByIndexCommand command) {
+ this.columnHideShowLayer.hideColumnIndexes(command.getColumnIndexes());
+ return true;
+ }
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowByIndexCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowByIndexCommand.java
new file mode 100644
index 0000000..0750915
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowByIndexCommand.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Original 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 authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.hideshow.command;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractContextFreeCommand;
+
+/**
+ * Hide a row by index instead of position. Intended to be used to
+ * programmatically hide rows in complex compositions.
+ *
+ * @since 2.0
+ */
+public class HideRowByIndexCommand extends AbstractContextFreeCommand {
+
+ private int[] rowIndexes;
+
+ /**
+ *
+ * @param rowIndexes
+ * The row indexes that should be hidden.
+ */
+ public HideRowByIndexCommand(int... rowIndexes) {
+ this.rowIndexes = rowIndexes;
+ }
+
+ /**
+ * Clone constructor.
+ *
+ * @param command
+ * The command to clone.
+ */
+ protected HideRowByIndexCommand(HideRowByIndexCommand command) {
+ this.rowIndexes = command.rowIndexes;
+ }
+
+ @Override
+ public HideRowByIndexCommand cloneCommand() {
+ return new HideRowByIndexCommand(this);
+ }
+
+ /**
+ *
+ * @return The row indexes that should be hidden.
+ */
+ public int[] getRowIndexes() {
+ return this.rowIndexes;
+ }
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowByIndexCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowByIndexCommandHandler.java
new file mode 100644
index 0000000..bb21294
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/HideRowByIndexCommandHandler.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Original 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 authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.hideshow.command;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.command.ILayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.hideshow.IRowHideShowLayer;
+
+/**
+ * {@link ILayerCommandHandler} for the {@link HideRowByIndexCommand}. Hides
+ * rows identified by index via {@link IRowHideShowLayer}.
+ *
+ * @since 2.0
+ */
+public class HideRowByIndexCommandHandler extends AbstractLayerCommandHandler<HideRowByIndexCommand> {
+
+ private final IRowHideShowLayer rowHideShowLayer;
+
+ /**
+ *
+ * @param rowHideShowLayer
+ * The {@link IRowHideShowLayer} on which this command handler
+ * should operate.
+ */
+ public HideRowByIndexCommandHandler(IRowHideShowLayer rowHideShowLayer) {
+ this.rowHideShowLayer = rowHideShowLayer;
+ }
+
+ @Override
+ public Class<HideRowByIndexCommand> getCommandClass() {
+ return HideRowByIndexCommand.class;
+ }
+
+ @Override
+ protected boolean doCommand(HideRowByIndexCommand command) {
+ this.rowHideShowLayer.hideRowIndexes(command.getRowIndexes());
+ return true;
+ }
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/hideshow/GlazedListsRowHideShowLayer.java b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/hideshow/GlazedListsRowHideShowLayer.java
index 1a98757..e084582 100644
--- a/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/hideshow/GlazedListsRowHideShowLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.extension.glazedlists/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/hideshow/GlazedListsRowHideShowLayer.java
@@ -29,6 +29,7 @@
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
import org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor;
import org.eclipse.nebula.widgets.nattable.hideshow.IRowHideShowLayer;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.HideRowByIndexCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowShowCommandHandler;
import org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommandHandler;
@@ -218,6 +219,7 @@ protected void registerCommandHandlers() {
registerCommandHandler(new ShowAllRowsCommandHandler(this));
registerCommandHandler(new MultiRowShowCommandHandler(this));
registerCommandHandler(new RowPositionHideCommandHandler(this));
+ registerCommandHandler(new HideRowByIndexCommandHandler(this));
}
/**