Bug 413207: Added AbstractDimPositionsCommand supporting command
implementations for both dimensions and range lists
Replaced AbstractMultiColumn/RowCommand by new command to use range lists
and adapted related classes
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/ColumnResizeCommandTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/ColumnResizeCommandTest.java
index 6e6df83..d4ec3c2 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/ColumnResizeCommandTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/ColumnResizeCommandTest.java
@@ -10,15 +10,14 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
-
-import org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider;
-import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
-import org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand;
-import org.eclipse.nebula.widgets.nattable.resize.command.MultiColumnResizeCommand;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider;
+import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
+
public class ColumnResizeCommandTest {
private DataLayer dataLayer;
@@ -45,7 +44,7 @@
public void shouldResizeAllSelectedColumns() {
int columnPositions[] = new int[]{3, 2, 4};
int newWidth = 250;
- MultiColumnResizeCommand columnResizeCommand = new MultiColumnResizeCommand(dataLayer, columnPositions, newWidth);
+ MultiColumnResizeCommand columnResizeCommand = new MultiColumnResizeCommand(dataLayer, new RangeList(columnPositions), newWidth);
dataLayer.doCommand(columnResizeCommand);
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandTest.java
index ea97282..de613ff 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandTest.java
@@ -10,14 +10,15 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
-
-import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
-import org.eclipse.nebula.widgets.nattable.resize.command.MultiColumnResizeCommand;
-import org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnReorderLayerFixture;
-import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture;
import org.junit.Assert;
import org.junit.Test;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
+import org.eclipse.nebula.widgets.nattable.test.fixture.layer.ColumnReorderLayerFixture;
+import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture;
+
+
public class MultiColumnResizeCommandTest {
@Test
@@ -34,7 +35,7 @@
@Test
public void getCommonColumnWidth() throws Exception {
MultiColumnResizeCommand resizeCommand = new MultiColumnResizeCommand(new DataLayerFixture(),
- new int[] { 1, 2 }, 100);
+ new RangeList(1, 2), 100);
Assert.assertEquals(100, resizeCommand.getCommonColumnWidth());
Assert.assertEquals(100, resizeCommand.getColumnWidth(1));
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedColumnsTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedColumnsTest.java
index 06bc41e..0da6c7b 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedColumnsTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedColumnsTest.java
@@ -11,16 +11,16 @@
package org.eclipse.nebula.widgets.nattable.selection;
-import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
-import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand;
-import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand;
-import org.eclipse.nebula.widgets.nattable.selection.SelectColumnCommandHandler;
-import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
-import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand;
+import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand;
+import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture;
+
public class HideSelectedColumnsTest {
private SelectionLayer selectionLayer;
private ColumnHideShowLayer columnHideShowLayer;
@@ -71,7 +71,7 @@
selectionLayer.selectCell(4, 4, false, true);
// Hide selection
- selectionLayer.doCommand(new MultiColumnHideCommand(selectionLayer, new int[]{2, 0, 4}));
+ selectionLayer.doCommand(new MultiColumnHideCommand(selectionLayer, new RangeList(2, 0, 4)));
// Previously selected columns should be hidden
Assert.assertTrue(columnHideShowLayer.isColumnIndexHidden(2));
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedRowsTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedRowsTest.java
index 29cec91..3b7c1e6 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedRowsTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/selection/HideSelectedRowsTest.java
@@ -10,16 +10,16 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.selection;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-import java.util.Arrays;
-
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand;
import org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand;
import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+
public class HideSelectedRowsTest {
private SelectionLayer selectionLayer;
@@ -53,7 +53,7 @@
@Test
public void shouldHideSelectedRow() {
// Select row to hide
- new SelectRowCommandHandler(selectionLayer).selectRows(0, Arrays.asList(Integer.valueOf(2)), false, false, 2);
+ new SelectRowCommandHandler(selectionLayer).selectRows(0, new RangeList(2), false, false, 2);
// Hide row
selectionLayer.doCommand(new MultiRowHideCommand(selectionLayer, 2));
@@ -66,12 +66,12 @@
@Test
public void shouldHideAllSelectedRows() {
// Select cells and rows
- new SelectRowCommandHandler(selectionLayer).selectRows(0, Arrays.asList(Integer.valueOf(2)), false, false, 2);
+ new SelectRowCommandHandler(selectionLayer).selectRows(0, new RangeList(2), false, false, 2);
selectionLayer.selectCell(0, 1, false, true);
selectionLayer.selectCell(4, 4, false, true);
// Hide selection
- selectionLayer.doCommand(new MultiRowHideCommand(selectionLayer, new int[]{2, 0, 4}));
+ selectionLayer.doCommand(new MultiRowHideCommand(selectionLayer, new RangeList(2, 0, 4)));
// Previously selected rows should be hidden
Assert.assertTrue(rowHideShowLayer.isRowIndexHidden(2));
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/columnChooser/ColumnChooserUtils.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/columnChooser/ColumnChooserUtils.java
index 6788cd1..fe8aef6 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/columnChooser/ColumnChooserUtils.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/columnChooser/ColumnChooserUtils.java
@@ -16,6 +16,7 @@
import java.util.Collection;
import java.util.List;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand;
@@ -28,16 +29,18 @@
public static final String RENAMED_COLUMN_INDICATOR = "*"; //$NON-NLS-1$
public static void hideColumnEntries(List<ColumnEntry> removedItems, ColumnHideShowLayer hideShowLayer) {
- MultiColumnHideCommand hideCommand = new MultiColumnHideCommand(
- hideShowLayer, asIntArray(getColumnEntryPositions(removedItems)));
+ MultiColumnHideCommand hideCommand = new MultiColumnHideCommand(hideShowLayer,
+ new RangeList(asIntArray(getColumnEntryPositions(removedItems))));
hideShowLayer.doCommand(hideCommand);
}
public static void hideColumnPositions(List<Integer> removedPositions, ColumnHideShowLayer hideShowLayer) {
- MultiColumnHideCommand hideCommand = new MultiColumnHideCommand(hideShowLayer, asIntArray(removedPositions));
+ MultiColumnHideCommand hideCommand = new MultiColumnHideCommand(hideShowLayer,
+ new RangeList(asIntArray(removedPositions)));
hideShowLayer.doCommand(hideCommand);
}
-
+
+
public static void showColumnEntries(List<ColumnEntry> addedItems, ColumnHideShowLayer hideShowLayer) {
hideShowLayer.doCommand(new MultiColumnShowCommand(getColumnEntryIndexes(addedItems)));
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractDimPositionsCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractDimPositionsCommand.java
new file mode 100644
index 0000000..b10f47d
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractDimPositionsCommand.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Stephan Wahlbrink 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stephan Wahlbrink - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.command;
+
+import java.util.Collection;
+
+import org.eclipse.nebula.widgets.nattable.coordinate.Orientation;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.ILayerDim;
+
+
+public abstract class AbstractDimPositionsCommand implements ILayerCommand {
+
+
+ private final Orientation orientation;
+
+ private ILayerDim layerDim;
+
+ private Collection<Range> positions;
+
+
+ protected AbstractDimPositionsCommand(
+ final ILayerDim layerDim, final Collection<Range> positions) {
+ this.orientation = layerDim.getOrientation();
+ this.layerDim = layerDim;
+ this.positions = positions;
+ }
+
+ protected AbstractDimPositionsCommand(final AbstractDimPositionsCommand command) {
+ this.orientation = command.orientation;
+ this.layerDim = command.layerDim;
+ this.positions = command.positions;
+ }
+
+
+ public final Orientation getOrientation() {
+ return this.orientation;
+ }
+
+ protected final ILayerDim getDim() {
+ return this.layerDim;
+ }
+
+ public Collection<Range> getPositions() {
+ return this.positions;
+ }
+
+
+ @Override
+ public boolean convertToTargetLayer(final ILayer targetLayer) {
+ final ILayerDim targetDim = targetLayer.getDim(this.orientation);
+ if (this.layerDim == targetDim) {
+ return true;
+ }
+
+ return convertToTargetLayer(this.layerDim, targetDim);
+ }
+
+ protected boolean convertToTargetLayer(final ILayerDim dim, final ILayerDim targetDim) {
+ final RangeList targetPositions = new RangeList();
+
+ for (final Range range : this.positions) {
+ for (int position = range.start; position < range.end; position++) {
+ final int targetPosition = LayerCommandUtil.convertPositionToTargetContext(dim,
+ position, targetDim );
+ if (targetPosition != Integer.MIN_VALUE) {
+ targetPositions.values().add(targetPosition);
+ }
+ }
+ }
+
+ if (!targetPositions.isEmpty()) {
+ this.layerDim = targetDim;
+ this.positions = targetPositions;
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractMultiColumnCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractMultiColumnCommand.java
deleted file mode 100644
index e8dee95..0000000
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractMultiColumnCommand.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Original authors and others - initial API and implementation
- ******************************************************************************/
-package org.eclipse.nebula.widgets.nattable.command;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate;
-import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-
-
-public abstract class AbstractMultiColumnCommand implements ILayerCommand {
-
- protected Collection<ColumnPositionCoordinate> columnPositionCoordinates;
-
- protected AbstractMultiColumnCommand(ILayer layer, int...columnPositions) {
- setColumnPositions(layer, columnPositions);
- }
-
- protected AbstractMultiColumnCommand(AbstractMultiColumnCommand command) {
- this.columnPositionCoordinates = new HashSet<ColumnPositionCoordinate>(command.columnPositionCoordinates);
- }
-
- public Collection<Integer> getColumnPositions() {
- Collection<Integer> columnPositions = new HashSet<Integer>();
- for (ColumnPositionCoordinate columnPositionCoordinate : columnPositionCoordinates) {
- columnPositions.add(Integer.valueOf(columnPositionCoordinate.columnPosition));
- }
- return columnPositions;
- }
-
- protected final void setColumnPositions(ILayer layer, int...columnPositions) {
- columnPositionCoordinates = new HashSet<ColumnPositionCoordinate>();
- for (int columnPosition : columnPositions) {
- columnPositionCoordinates.add(new ColumnPositionCoordinate(layer, columnPosition));
- }
- }
-
- public boolean convertToTargetLayer(ILayer targetLayer) {
- Collection<ColumnPositionCoordinate> convertedColumnPositionCoordinates = new HashSet<ColumnPositionCoordinate>();
-
- for (ColumnPositionCoordinate columnPositionCoordinate : columnPositionCoordinates) {
- ColumnPositionCoordinate convertedColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(columnPositionCoordinate, targetLayer);
- if (convertedColumnPositionCoordinate != null) {
- convertedColumnPositionCoordinates.add(convertedColumnPositionCoordinate);
- }
- }
-
- if (convertedColumnPositionCoordinates.size() > 0) {
- columnPositionCoordinates = convertedColumnPositionCoordinates;
- return true;
- } else {
- return false;
- }
- }
-
-}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractMultiRowCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractMultiRowCommand.java
deleted file mode 100644
index 32bc459..0000000
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/AbstractMultiRowCommand.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Original authors and others - initial API and implementation
- ******************************************************************************/
-package org.eclipse.nebula.widgets.nattable.command;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate;
-import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-
-
-public abstract class AbstractMultiRowCommand implements ILayerCommand {
-
- private Collection<RowPositionCoordinate> rowPositionCoordinates;
-
- protected AbstractMultiRowCommand(ILayer layer, int...rowPositions) {
- setRowPositions(layer, rowPositions);
- }
-
- protected AbstractMultiRowCommand(AbstractMultiRowCommand command) {
- this.rowPositionCoordinates = new HashSet<RowPositionCoordinate>(command.rowPositionCoordinates);
- }
-
- public Collection<Integer> getRowPositions() {
- Collection<Integer> rowPositions = new HashSet<Integer>();
- for (RowPositionCoordinate rowPositionCoordinate : rowPositionCoordinates) {
- rowPositions.add(Integer.valueOf(rowPositionCoordinate.rowPosition));
- }
- return rowPositions;
- }
-
- protected final void setRowPositions(ILayer layer, int...rowPositions) {
- rowPositionCoordinates = new HashSet<RowPositionCoordinate>();
- for (int rowPosition : rowPositions) {
- rowPositionCoordinates.add(new RowPositionCoordinate(layer, rowPosition));
- }
- }
-
- public boolean convertToTargetLayer(ILayer targetLayer) {
- Collection<RowPositionCoordinate> convertedRowPositionCoordinates = new HashSet<RowPositionCoordinate>();
- for (RowPositionCoordinate rowPositionCoordinate : rowPositionCoordinates) {
- RowPositionCoordinate convertedRowPositionCoordinate = LayerCommandUtil.convertRowPositionToTargetContext(rowPositionCoordinate, targetLayer);
- if (convertedRowPositionCoordinate != null) {
- convertedRowPositionCoordinates.add(convertedRowPositionCoordinate);
- }
- }
-
- if (convertedRowPositionCoordinates.size() > 0) {
- rowPositionCoordinates = convertedRowPositionCoordinates;
- return true;
- } else {
- return false;
- }
- }
-
-}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/LayerCommandUtil.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/LayerCommandUtil.java
index de47bee..7616acf 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/LayerCommandUtil.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/command/LayerCommandUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -16,6 +16,7 @@
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
import org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.ILayerDim;
public class LayerCommandUtil {
@@ -105,4 +106,30 @@
return null;
}
+ public static int convertPositionToTargetContext(/*@NonNull*/ final ILayerDim dim,
+ final int position, /*@NonNull*/ final ILayerDim targetDim) {
+ if (dim == targetDim) {
+ return position;
+ }
+
+ int underlyingPosition = dim.localToUnderlyingPosition(position);
+ if (underlyingPosition == Integer.MIN_VALUE) {
+ return Integer.MIN_VALUE;
+ }
+
+ final Collection<ILayerDim> underlyingDims = dim.getUnderlyingDimsByPosition(position);
+ if (underlyingDims != null) {
+ for (ILayerDim underlyingDim : underlyingDims) {
+ if (underlyingDim != null) {
+ int targetPosition = convertPositionToTargetContext(underlyingDim,
+ underlyingPosition, targetDim );
+ if (targetPosition != Integer.MIN_VALUE) {
+ return targetPosition;
+ }
+ }
+ }
+ }
+ return Integer.MIN_VALUE;
+ }
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeColumnCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeColumnCommandHandler.java
index 0fd5cbd..025f17b 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeColumnCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeColumnCommandHandler.java
@@ -11,6 +11,7 @@
package org.eclipse.nebula.widgets.nattable.grid.command;
import org.eclipse.nebula.widgets.nattable.command.ILayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand;
@@ -77,7 +78,7 @@
// NatTable itself
targetLayer.doCommand(new TurnViewportOffCommand());
- int[] columnPositions = ObjectUtils.asIntArray(command.getColumnPositions());
+ int[] columnPositions = ObjectUtils.asIntArray(RangeList.listValues(command.getPositions()));
int[] gridColumnPositions = convertFromPositionToCommandLayer(columnPositions);
int[] gridColumnWidths = MaxCellBoundsHelper.getPreferredColumnWidths(
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeRowCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeRowCommandHandler.java
index 46308d6..d260e26 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeRowCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/AutoResizeRowCommandHandler.java
@@ -11,6 +11,7 @@
package org.eclipse.nebula.widgets.nattable.grid.command;
import org.eclipse.nebula.widgets.nattable.command.ILayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand;
@@ -75,7 +76,7 @@
// Need to resize selected rows even if they are outside the viewport
targetLayer.doCommand(new TurnViewportOffCommand());
- int[] rowPositions = ObjectUtils.asIntArray(command.getRowPositions());
+ int[] rowPositions = ObjectUtils.asIntArray(RangeList.listValues(command.getPositions()));
int[] gridRowPositions = convertFromPositionToCommandLayer(rowPositions);
int[] gridRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeColumnsCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeColumnsCommandHandler.java
index ea460ac..f64af19 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeColumnsCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeColumnsCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -11,10 +11,12 @@
package org.eclipse.nebula.widgets.nattable.grid.command;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.resize.command.AutoResizeColumnsCommand;
import org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
+
public class InitializeAutoResizeColumnsCommandHandler extends AbstractLayerCommandHandler<InitializeAutoResizeColumnsCommand> {
private SelectionLayer selectionLayer;
@@ -34,9 +36,9 @@
if (selectionLayer.isColumnPositionFullySelected(columnPosition)) {
initCommand.setSelectedColumnPositions(selectionLayer.getFullySelectedColumnPositions());
} else {
- initCommand.setSelectedColumnPositions(new int[] { columnPosition });
+ initCommand.setSelectedColumnPositions(new RangeList(columnPosition));
}
-
+
// Fire command carrying the selected columns
initCommand.getSourceLayer().doCommand(new AutoResizeColumnsCommand(initCommand));
return true;
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeRowsCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeRowsCommandHandler.java
index 74b261c..0c95502 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeRowsCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/grid/command/InitializeAutoResizeRowsCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -11,10 +11,12 @@
package org.eclipse.nebula.widgets.nattable.grid.command;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.resize.command.AutoResizeRowsCommand;
import org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeRowsCommand;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
+
public class InitializeAutoResizeRowsCommandHandler extends AbstractLayerCommandHandler<InitializeAutoResizeRowsCommand> {
private SelectionLayer selectionLayer;
@@ -35,9 +37,9 @@
if (selectionLayer.isRowPositionFullySelected(rowPosition)) {
initCommand.setSelectedRowPositions(selectionLayer.getFullySelectedRowPositions());
} else {
- initCommand.setSelectedRowPositions(new int[] { rowPosition });
+ initCommand.setSelectedRowPositions(new RangeList(rowPosition));
}
-
+
// Fire command carrying the selected columns
initCommand.getSourceLayer().doCommand(new AutoResizeRowsCommand(initCommand));
return true;
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommand.java
index 2729334..62f889f 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -10,23 +10,32 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.hideshow.command;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiColumnCommand;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.HORIZONTAL;
+
+import java.util.Collection;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-public class MultiColumnHideCommand extends AbstractMultiColumnCommand {
+public class MultiColumnHideCommand extends AbstractDimPositionsCommand {
+
+
public MultiColumnHideCommand(ILayer layer, int columnPosition) {
- this(layer, new int[] { columnPosition });
+ this(layer, new RangeList(columnPosition));
}
-
- public MultiColumnHideCommand(ILayer layer, int[] columnPositions) {
- super(layer, columnPositions);
+
+ public MultiColumnHideCommand(ILayer layer, Collection<Range> columnPositions) {
+ super(layer.getDim(HORIZONTAL), columnPositions);
}
protected MultiColumnHideCommand(MultiColumnHideCommand command) {
super(command);
}
+ @Override
public MultiColumnHideCommand cloneCommand() {
return new MultiColumnHideCommand(this);
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommandHandler.java
index a26aa34..497f870 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiColumnHideCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -11,6 +11,7 @@
package org.eclipse.nebula.widgets.nattable.hideshow.command;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
public class MultiColumnHideCommandHandler extends AbstractLayerCommandHandler<MultiColumnHideCommand> {
@@ -27,7 +28,7 @@
@Override
protected boolean doCommand(MultiColumnHideCommand command) {
- columnHideShowLayer.hideColumnPositions(command.getColumnPositions());
+ columnHideShowLayer.hideColumnPositions(RangeList.listValues(command.getPositions()));
return true;
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommand.java
index e0505f9..7c08e8b 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -10,25 +10,34 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.hideshow.command;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiRowCommand;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.VERTICAL;
+
+import java.util.Collection;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-public class MultiRowHideCommand extends AbstractMultiRowCommand {
+public class MultiRowHideCommand extends AbstractDimPositionsCommand {
+
+
public MultiRowHideCommand(ILayer layer, int rowPosition) {
- this(layer, new int[] { rowPosition });
+ this(layer, new RangeList(rowPosition));
}
-
- public MultiRowHideCommand(ILayer layer, int[] rowPositions) {
- super(layer, rowPositions);
+
+ public MultiRowHideCommand(ILayer layer, Collection<Range> rowPositions) {
+ super(layer.getDim(VERTICAL), rowPositions);
}
protected MultiRowHideCommand(MultiRowHideCommand command) {
super(command);
}
+ @Override
public MultiRowHideCommand cloneCommand() {
return new MultiRowHideCommand(this);
}
-
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommandHandler.java
index 9d14038..3c28798 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/hideshow/command/MultiRowHideCommandHandler.java
@@ -11,6 +11,7 @@
package org.eclipse.nebula.widgets.nattable.hideshow.command;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.hideshow.IRowHideShowCommandLayer;
public class MultiRowHideCommandHandler extends AbstractLayerCommandHandler<MultiRowHideCommand>{
@@ -27,7 +28,7 @@
@Override
protected boolean doCommand(MultiRowHideCommand command) {
- rowHideShowLayer.hideRowPositions(command.getRowPositions());
+ rowHideShowLayer.hideRowPositions(RangeList.listValues(command.getPositions()));
return true;
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeColumnsCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeColumnsCommand.java
index 402173e..2ec4720 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeColumnsCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeColumnsCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -10,11 +10,14 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiColumnCommand;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.HORIZONTAL;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.util.GCFactory;
+
/**
* Command indicating that all selected columns have to be auto resized i.e made
* wide enough to just fit the widest cell. This should also take the column
@@ -23,24 +26,25 @@
* Note: The {@link InitializeAutoResizeColumnsCommand} has to be fired first
* when autoresizing columns.
*/
-
-public class AutoResizeColumnsCommand extends AbstractMultiColumnCommand {
-
+public class AutoResizeColumnsCommand extends AbstractDimPositionsCommand {
+
private final IConfigRegistry configRegistry;
private final GCFactory gcFactory;
-
+
+
public AutoResizeColumnsCommand(InitializeAutoResizeColumnsCommand initCommand) {
- super(initCommand.getSourceLayer(), initCommand.getColumnPositions());
+ super(initCommand.getSourceLayer().getDim(HORIZONTAL), initCommand.getColumnPositions());
this.configRegistry = initCommand.getConfigRegistry();
this.gcFactory = initCommand.getGCFactory();
}
-
+
protected AutoResizeColumnsCommand(AutoResizeColumnsCommand command) {
super(command);
this.configRegistry = command.configRegistry;
this.gcFactory = command.gcFactory;
}
-
+
+ @Override
public ILayerCommand cloneCommand() {
return new AutoResizeColumnsCommand(this);
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeRowsCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeRowsCommand.java
index 5ee25b3..53cd24c 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeRowsCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/AutoResizeRowsCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -10,32 +10,36 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiRowCommand;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.VERTICAL;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.util.GCFactory;
+
/**
* @see AutoResizeColumnsCommand
*/
-
-public class AutoResizeRowsCommand extends AbstractMultiRowCommand {
+public class AutoResizeRowsCommand extends AbstractDimPositionsCommand {
private final IConfigRegistry configRegistry;
private final GCFactory gcFactory;
-
+
+
public AutoResizeRowsCommand(InitializeAutoResizeRowsCommand initCommand) {
- super(initCommand.getSourceLayer(), initCommand.getRowPositions());
+ super(initCommand.getSourceLayer().getDim(VERTICAL), initCommand.getRowPositions());
this.configRegistry = initCommand.getConfigRegistry();
this.gcFactory = initCommand.getGCFactory();
}
-
+
protected AutoResizeRowsCommand(AutoResizeRowsCommand command) {
super(command);
this.configRegistry = command.configRegistry;
this.gcFactory = command.gcFactory;
}
-
+
+ @Override
public ILayerCommand cloneCommand() {
return new AutoResizeRowsCommand(this);
}
@@ -49,4 +53,5 @@
public IConfigRegistry getConfigRegistry() {
return configRegistry;
}
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeColumnsCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeColumnsCommand.java
index 32c7a8a..d5e1b59 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeColumnsCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeColumnsCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -10,14 +10,20 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
+import java.util.Collection;
+import java.util.Collections;
+
import org.eclipse.nebula.widgets.nattable.command.AbstractColumnCommand;
import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.util.GCFactory;
+
/**
* This command triggers the AutoResizeColumms command. It collects the selected
* columns from the {@link SelectionLayer} and fires the
@@ -28,9 +34,11 @@
private final IConfigRegistry configRegistry;
private final GCFactory gcFactory;
+
private final ILayer sourceLayer;
- private int[] selectedColumnPositions = new int[0];
-
+ private Collection<Range> selectedColumnPositions = Collections.emptyList();
+
+
public InitializeAutoResizeColumnsCommand(ILayer layer, int columnPosition, IConfigRegistry configRegistry, GCFactory gcFactory) {
super(layer, columnPosition);
this.configRegistry = configRegistry;
@@ -63,11 +71,17 @@
return sourceLayer;
}
- public void setSelectedColumnPositions(int[] selectedColumnPositions) {
+ @Deprecated
+ public void setSelectedColumnPositions(final int[] selectedColumnPositions) {
+ setSelectedColumnPositions(new RangeList(selectedColumnPositions));
+ }
+
+ public void setSelectedColumnPositions(final Collection<Range> selectedColumnPositions) {
this.selectedColumnPositions = selectedColumnPositions;
}
- public int[] getColumnPositions() {
+ public Collection<Range> getColumnPositions() {
return selectedColumnPositions;
}
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeRowsCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeRowsCommand.java
index d249210..9d7926c 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeRowsCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/InitializeAutoResizeRowsCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -10,23 +10,30 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
+import java.util.Collection;
+import java.util.Collections;
+
import org.eclipse.nebula.widgets.nattable.command.AbstractRowCommand;
import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.util.GCFactory;
+
/**
* @see InitializeAutoResizeColumnsCommand
*/
-
public class InitializeAutoResizeRowsCommand extends AbstractRowCommand {
private final IConfigRegistry configRegistry;
private final GCFactory gcFactory;
+
private final ILayer sourceLayer;
- private int[] selectedRowPositions = new int[0];
-
+ private Collection<Range> selectedRowPositions = Collections.emptyList();
+
+
public InitializeAutoResizeRowsCommand(ILayer layer, int rowPosition, IConfigRegistry configRegistry, GCFactory gcFactory) {
super(layer, rowPosition);
this.configRegistry = configRegistry;
@@ -59,11 +66,17 @@
return sourceLayer;
}
- public void setSelectedRowPositions(int[] selectedRowPositions) {
+ @Deprecated
+ public void setSelectedRowPositions(final int[] selectedRowPositions) {
+ setSelectedRowPositions(new RangeList(selectedRowPositions));
+ }
+
+ public void setSelectedRowPositions(final Collection<Range> selectedRowPositions) {
this.selectedRowPositions = selectedRowPositions;
}
- public int[] getRowPositions() {
+ public Collection<Range> getRowPositions() {
return selectedRowPositions;
}
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommand.java
index 4b770af..6aa46c5 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommand.java
@@ -10,33 +10,39 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.HORIZONTAL;
+
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiColumnCommand;
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
import org.eclipse.nebula.widgets.nattable.command.LayerCommandUtil;
import org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-public class MultiColumnResizeCommand extends AbstractMultiColumnCommand {
+public class MultiColumnResizeCommand extends AbstractDimPositionsCommand {
private int commonColumnWidth = -1;
protected Map<ColumnPositionCoordinate, Integer> colPositionToWidth = new HashMap<ColumnPositionCoordinate, Integer>();
-
+
+
/**
- * All columns are being resized to the same size e.g. during a drag resize
+ * All columns are being resized to the same width e.g. during a drag resize
*/
- public MultiColumnResizeCommand(ILayer layer, int[] columnPositions, int commonColumnWidth) {
- super(layer, columnPositions);
+ public MultiColumnResizeCommand(ILayer layer, Collection<Range> columnPositions, int commonColumnWidth) {
+ super(layer.getDim(HORIZONTAL), columnPositions);
this.commonColumnWidth = commonColumnWidth;
}
-
+
/**
* Each column is being resized to a different size e.g. during auto resize
*/
public MultiColumnResizeCommand(ILayer layer, int[] columnPositions, int[] columnWidths) {
- super(layer, columnPositions);
+ super(layer.getDim(HORIZONTAL), new RangeList(columnPositions));
for (int i = 0; i < columnPositions.length; i++) {
colPositionToWidth.put(new ColumnPositionCoordinate(layer, columnPositions[i]), Integer.valueOf(columnWidths[i]));
}
@@ -47,7 +53,13 @@
this.commonColumnWidth = command.commonColumnWidth;
this.colPositionToWidth = new HashMap<ColumnPositionCoordinate, Integer>(command.colPositionToWidth);
}
-
+
+ @Override
+ public MultiColumnResizeCommand cloneCommand() {
+ return new MultiColumnResizeCommand(this);
+ }
+
+
public int getCommonColumnWidth() {
return commonColumnWidth;
}
@@ -61,13 +73,10 @@
return commonColumnWidth;
}
- /**
- * Convert the column positions to the target layer.
- * Ensure that the width associated with the column is now associated with the
- * converted column position.
- */
@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
+ // Ensure that the width associated with the column is now associated with the converted
+ // column position.
Map<ColumnPositionCoordinate, Integer> newColPositionToWidth = new HashMap<ColumnPositionCoordinate, Integer>();
for (ColumnPositionCoordinate columnPositionCoordinate : colPositionToWidth.keySet()) {
@@ -85,7 +94,4 @@
}
}
- public MultiColumnResizeCommand cloneCommand() {
- return new MultiColumnResizeCommand(this);
- }
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandHandler.java
index 1613e29..0fd02b4 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiColumnResizeCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -11,6 +11,8 @@
package org.eclipse.nebula.widgets.nattable.resize.command;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.IValueIterator;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList.ValueIterator;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
public class MultiColumnResizeCommandHandler extends AbstractLayerCommandHandler<MultiColumnResizeCommand> {
@@ -27,7 +29,8 @@
@Override
protected boolean doCommand(MultiColumnResizeCommand command) {
- for (int columnPosition : command.getColumnPositions()) {
+ for (final IValueIterator columnIter = new ValueIterator(command.getPositions()); columnIter.hasNext(); ) {
+ final int columnPosition = columnIter.nextValue();
dataLayer.setColumnWidthByPosition(columnPosition, command.getColumnWidth(columnPosition));
}
return true;
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommand.java
index 43f4b31..5a52d32 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommand.java
@@ -10,33 +10,39 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.resize.command;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.VERTICAL;
+
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiRowCommand;
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
import org.eclipse.nebula.widgets.nattable.command.LayerCommandUtil;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-public class MultiRowResizeCommand extends AbstractMultiRowCommand {
+public class MultiRowResizeCommand extends AbstractDimPositionsCommand {
private int commonRowHeight = -1;
protected Map<RowPositionCoordinate, Integer> rowPositionToHeight = new HashMap<RowPositionCoordinate, Integer>();
-
+
+
/**
* All rows are being resized to the same height e.g. during a drag resize
*/
- public MultiRowResizeCommand(ILayer layer, int[] rowPositions, int commonRowHeight) {
- super(layer, rowPositions);
+ public MultiRowResizeCommand(ILayer layer, Collection<Range> rowPositions, int commonRowHeight) {
+ super(layer.getDim(VERTICAL), rowPositions);
this.commonRowHeight = commonRowHeight;
}
-
+
/**
* Each row is being resized to a different size e.g. during auto resize
*/
public MultiRowResizeCommand(ILayer layer, int[] rowPositions, int[] rowHeights) {
- super(layer, rowPositions);
+ super(layer.getDim(VERTICAL), new RangeList(rowPositions));
for (int i = 0; i < rowPositions.length; i++) {
rowPositionToHeight.put(new RowPositionCoordinate(layer, rowPositions[i]), Integer.valueOf(rowHeights[i]));
}
@@ -47,7 +53,13 @@
this.commonRowHeight = command.commonRowHeight;
this.rowPositionToHeight = new HashMap<RowPositionCoordinate, Integer>(command.rowPositionToHeight);
}
-
+
+ @Override
+ public MultiRowResizeCommand cloneCommand() {
+ return new MultiRowResizeCommand(this);
+ }
+
+
public int getCommonRowHeight() {
return commonRowHeight;
}
@@ -63,6 +75,8 @@
@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
+ // Ensure that the height associated with the row is now associated with the converted
+ // row position.
Map<RowPositionCoordinate, Integer> newRowPositionToHeight = new HashMap<RowPositionCoordinate, Integer>();
for (RowPositionCoordinate rowPositionCoordinate : rowPositionToHeight.keySet()) {
@@ -80,8 +94,4 @@
}
}
- public MultiRowResizeCommand cloneCommand() {
- return new MultiRowResizeCommand(this);
- }
-
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommandHandler.java
index 495227a..dc81985 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/command/MultiRowResizeCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -11,6 +11,8 @@
package org.eclipse.nebula.widgets.nattable.resize.command;
import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.IValueIterator;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList.ValueIterator;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
public class MultiRowResizeCommandHandler extends AbstractLayerCommandHandler<MultiRowResizeCommand> {
@@ -27,7 +29,8 @@
@Override
protected boolean doCommand(MultiRowResizeCommand command) {
- for (int rowPosition : command.getRowPositions()) {
+ for (final IValueIterator rowIter = new ValueIterator(command.getPositions()); rowIter.hasNext(); ) {
+ final int rowPosition = rowIter.nextValue();
dataLayer.setRowHeightByPosition(rowPosition, command.getRowHeight(rowPosition));
}
return true;
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java
index fe2b4dd..cfacfe9 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java
@@ -22,13 +22,15 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
+
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand;
import org.eclipse.nebula.widgets.nattable.selection.event.ISelectionEvent;
-import org.eclipse.nebula.widgets.nattable.util.ObjectUtils;
+
/**
* Implementation of ISelectionProvider to add support for JFace selection handling.
@@ -159,30 +161,27 @@
listeners.remove(listener);
}
- @SuppressWarnings("unchecked")
@Override
+ @SuppressWarnings("unchecked")
public void setSelection(ISelection selection) {
if (selectionLayer != null && selection instanceof IStructuredSelection) {
if (!addSelectionOnSet) {
selectionLayer.clear(false);
}
if (!selection.isEmpty()) {
- List<T> rowObjects = ((IStructuredSelection) selection).toList();
- Set<Integer> rowPositions = new HashSet<Integer>();
- for (T rowObject : rowObjects) {
- int rowIndex = rowDataProvider.indexOfRowObject(rowObject);
- int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
- rowPositions.add(Integer.valueOf(rowPosition));
- }
- int intValue = -1;
- if (!rowPositions.isEmpty()) {
- Integer max = Collections.max(rowPositions);
- intValue = max.intValue();
+ List<T> rowObjects = ((IStructuredSelection) selection).toList();
+ final RangeList rowPositions = new RangeList();
+ for (T rowObject : rowObjects) {
+ int rowIndex = rowDataProvider.indexOfRowObject(rowObject);
+ int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
+ rowPositions.values().add(rowPosition);
}
- if (intValue >= 0) {
- selectionLayer.doCommand(
- new SelectRowsCommand(selectionLayer, 0, ObjectUtils.asIntArray(rowPositions),
- false, true, intValue));
+ if (!rowPositions.isEmpty()) {
+ final int max = rowPositions.values().last();
+ if (max >= 0) {
+ selectionLayer.doCommand(new SelectRowsCommand(selectionLayer,
+ 0, rowPositions, false, true, max ));
+ }
}
}
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectRowCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectRowCommandHandler.java
index 647b63b..d458bb1 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectRowCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectRowCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Original authors and others.
+ * Copyright (c) 2012, 2013 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
@@ -19,12 +19,17 @@
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.swt.graphics.Rectangle;
+
import org.eclipse.nebula.widgets.nattable.command.ILayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.coordinate.IValueIterator;
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList.ValueIterator;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand;
import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent;
-import org.eclipse.swt.graphics.Rectangle;
+
public class SelectRowCommandHandler implements ILayerCommandHandler<SelectRowsCommand> {
@@ -37,17 +42,18 @@
@Override
public boolean doCommand(ILayer targetLayer, SelectRowsCommand command) {
if (command.convertToTargetLayer(selectionLayer)) {
- selectRows(command.getColumnPosition(), command.getRowPositions(), command.isWithShiftMask(), command.isWithControlMask(), command.getRowPositionToMoveIntoViewport());
+ selectRows(command.getColumnPosition(), command.getPositions(), command.isWithShiftMask(), command.isWithControlMask(), command.getRowPositionToMoveIntoViewport());
return true;
}
return false;
}
- protected void selectRows(int columnPosition, Collection<Integer> rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport) {
- Set<Range> changedRowRanges = new HashSet<Range>();
+ protected void selectRows(int columnPosition, Collection<Range> rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport) {
+ final RangeList changedRowRanges = new RangeList();
- for (int rowPosition : rowPositions) {
- changedRowRanges.addAll(internalSelectRow(columnPosition, rowPosition, withShiftMask, withControlMask));
+ for (final IValueIterator rowIter = new ValueIterator(rowPositions); rowIter.hasNext(); ) {
+ changedRowRanges.addAll(internalSelectRow(columnPosition, rowIter.nextValue(),
+ withShiftMask, withControlMask ));
}
Set<Integer> changedRows = new HashSet<Integer>();
@@ -68,7 +74,7 @@
selectionLayer.selectCell(0, rowPosition, withShiftMask, withControlMask);
selectionLayer.selectRegion(0, rowPosition, Integer.MAX_VALUE, 1);
selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
- changedRowRanges.add(new Range(rowPosition, rowPosition + 1));
+ changedRowRanges.add(new Range(rowPosition));
} else if (bothShiftAndControl(withShiftMask, withControlMask)) {
changedRowRanges.add(selectRowWithShiftKey(rowPosition));
} else if (isShiftOnly(withShiftMask, withControlMask)) {
@@ -104,7 +110,7 @@
selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
}
- return new Range(rowPosition, rowPosition + 1);
+ return new Range(rowPosition);
}
private Range selectRowWithShiftKey(int rowPosition) {
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java
index ea6af9b..9d1fa3c 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java
@@ -10,16 +10,21 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.selection;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+
import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
+import org.eclipse.nebula.widgets.nattable.coordinate.IValueIterator;
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList.ValueIterator;
import org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler;
import org.eclipse.nebula.widgets.nattable.edit.command.EditSelectionCommandHandler;
import org.eclipse.nebula.widgets.nattable.grid.command.InitializeAutoResizeColumnsCommandHandler;
@@ -45,8 +50,6 @@
import org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.style.SelectionStyleLabels;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
/**
* Enables selection of column, rows, cells etc. on the table.
@@ -338,7 +341,7 @@
}
public void selectRow(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) {
- selectRowCommandHandler.selectRows(columnPosition, Arrays.asList(Integer.valueOf(rowPosition)), withShiftMask, withControlMask, rowPosition);
+ selectRowCommandHandler.selectRows(columnPosition, new RangeList(rowPosition), withShiftMask, withControlMask, rowPosition);
}
// ILayer methods
@@ -441,7 +444,7 @@
protected boolean handleColumnHideCommand(ColumnHideCommand command) {
if (isColumnPositionFullySelected(command.getColumnPosition())) {
return handleMultiColumnHideCommand(
- new MultiColumnHideCommand(this, getFullySelectedColumnPositions()));
+ new MultiColumnHideCommand(this, new RangeList(getFullySelectedColumnPositions())));
} else {
return super.doCommand(command);
}
@@ -457,7 +460,8 @@
* @return <code>true</code> if the command has been handled, <code>false</code> otherwise
*/
protected boolean handleMultiColumnHideCommand(MultiColumnHideCommand command) {
- for (int columnPosition : command.getColumnPositions()) {
+ for (final IValueIterator columnIter = new ValueIterator(command.getPositions()); columnIter.hasNext(); ) {
+ final int columnPosition = columnIter.nextValue();
if (isColumnPositionFullySelected(columnPosition)) {
Rectangle selection = new Rectangle(columnPosition, 0, 1, Integer.MAX_VALUE);
clearSelection(selection);
@@ -484,7 +488,7 @@
protected boolean handleRowHideCommand(RowHideCommand command) {
if (isRowPositionFullySelected(command.getRowPosition())) {
return handleMultiRowHideCommand(
- new MultiRowHideCommand(this, getFullySelectedRowPositions()));
+ new MultiRowHideCommand(this, new RangeList(getFullySelectedRowPositions())));
} else {
return super.doCommand(command);
}
@@ -500,7 +504,8 @@
* @return <code>true</code> if the command has been handled, <code>false</code> otherwise
*/
protected boolean handleMultiRowHideCommand(MultiRowHideCommand command) {
- for (int rowPosition : command.getRowPositions()) {
+ for (final IValueIterator rowIter = new ValueIterator(command.getPositions()); rowIter.hasNext(); ) {
+ final int rowPosition = rowIter.nextValue();
if (isRowPositionFullySelected(rowPosition)) {
Rectangle selection = new Rectangle(0, rowPosition, Integer.MAX_VALUE, 1);
clearSelection(selection);
@@ -526,7 +531,7 @@
protected boolean handleColumnResizeCommand(ColumnResizeCommand command) {
if (isColumnPositionFullySelected(command.getColumnPosition())) {
return super.doCommand(
- new MultiColumnResizeCommand(this, selectionModel.getFullySelectedColumnPositions(getRowCount()), command.getNewColumnWidth()));
+ new MultiColumnResizeCommand(this, new RangeList(selectionModel.getFullySelectedColumnPositions(getRowCount())), command.getNewColumnWidth()));
} else {
return super.doCommand(command);
}
@@ -549,7 +554,7 @@
protected boolean handleRowResizeCommand(RowResizeCommand command) {
if (isRowPositionFullySelected(command.getRowPosition())) {
return super.doCommand(
- new MultiRowResizeCommand(this, selectionModel.getFullySelectedRowPositions(getColumnCount()), command.getNewHeight()));
+ new MultiRowResizeCommand(this, new RangeList(selectionModel.getFullySelectedRowPositions(getColumnCount())), command.getNewHeight()));
} else {
return super.doCommand(command);
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectRowsCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectRowsCommand.java
index 898feae..ec75fce 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectRowsCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectRowsCommand.java
@@ -10,32 +10,42 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.selection.command;
-import org.eclipse.nebula.widgets.nattable.command.AbstractMultiRowCommand;
+import static org.eclipse.nebula.widgets.nattable.coordinate.Orientation.VERTICAL;
+
+import java.util.Collection;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractDimPositionsCommand;
import org.eclipse.nebula.widgets.nattable.command.LayerCommandUtil;
import org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate;
+import org.eclipse.nebula.widgets.nattable.coordinate.Range;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-import org.eclipse.nebula.widgets.nattable.util.ArrayUtil;
-public class SelectRowsCommand extends AbstractMultiRowCommand {
+public class SelectRowsCommand extends AbstractDimPositionsCommand {
+
private ColumnPositionCoordinate columnPositionCoordinate;
+
private final boolean withShiftMask;
private final boolean withControlMask;
+
private RowPositionCoordinate rowPositionCoordinateToMoveIntoViewport;
-
+
+
public SelectRowsCommand(ILayer layer, int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) {
- this(layer, columnPosition, ArrayUtil.asIntArray(rowPosition), withShiftMask, withControlMask, rowPosition);
+ this(layer, columnPosition, new RangeList(rowPosition), withShiftMask, withControlMask, rowPosition);
}
-
- public SelectRowsCommand(ILayer layer, int columnPosition, int[] rowPositions, boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport) {
- super(layer, rowPositions);
+
+ public SelectRowsCommand(ILayer layer, int columnPosition, Collection<Range> rowPositions,
+ boolean withShiftMask, boolean withControlMask, int rowPositionToMoveIntoViewport) {
+ super(layer.getDim(VERTICAL), rowPositions);
this.columnPositionCoordinate = new ColumnPositionCoordinate(layer, columnPosition);
this.withControlMask = withControlMask;
this.withShiftMask = withShiftMask;
this.rowPositionCoordinateToMoveIntoViewport = new RowPositionCoordinate(layer, rowPositionToMoveIntoViewport);
}
-
+
protected SelectRowsCommand(SelectRowsCommand command) {
super(command);
this.columnPositionCoordinate = command.columnPositionCoordinate;
@@ -43,7 +53,13 @@
this.withControlMask = command.withControlMask;
this.rowPositionCoordinateToMoveIntoViewport = command.rowPositionCoordinateToMoveIntoViewport;
}
-
+
+ @Override
+ public SelectRowsCommand cloneCommand() {
+ return new SelectRowsCommand(this);
+ }
+
+
@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
ColumnPositionCoordinate targetColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(
@@ -78,8 +94,5 @@
return -1;
}
}
-
- public SelectRowsCommand cloneCommand() {
- return new SelectRowsCommand(this);
- }
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/tree/TreeLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/tree/TreeLayer.java
index 5f9e83a..34494c0 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/tree/TreeLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/tree/TreeLayer.java
@@ -18,6 +18,9 @@
import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.coordinate.IValueIterator;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList.ValueIterator;
import org.eclipse.nebula.widgets.nattable.hideshow.AbstractRowHideShowLayer;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand;
import org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand;
@@ -264,13 +267,12 @@
int rowIndex = getRowIndexByPosition(command.getRowPosition());
if (this.treeRowModel.hasChildren(rowIndex) && !this.treeRowModel.isCollapsed(rowIndex)) {
List<Integer> childIndexes = this.treeRowModel.getChildIndexes(rowIndex);
- int[] childPositions = new int[childIndexes.size()+1];
- childPositions[0] = command.getRowPosition();
+ final RangeList rowPositionsToHide = new RangeList();
+ rowPositionsToHide.values().add(command.getRowPosition());
for (int i = 1; i < childIndexes.size()+1; i++) {
- int childPos = getRowPositionByIndex(childIndexes.get(i-1));
- childPositions[i] = childPos;
+ rowPositionsToHide.values().add(getRowPositionByIndex(childIndexes.get(i-1)));
}
- return super.doCommand(new MultiRowHideCommand(this, childPositions));
+ return super.doCommand(new MultiRowHideCommand(this, rowPositionsToHide));
}
}
return super.doCommand(command);
@@ -285,23 +287,20 @@
protected boolean handleMultiRowHideCommand(MultiRowHideCommand command) {
//transform position to index
if (command.convertToTargetLayer(this)) {
- List<Integer> rowPositionsToHide = new ArrayList<Integer>();
- for (Integer rowPos : command.getRowPositions()) {
- rowPositionsToHide.add(rowPos);
+ final RangeList rowPositionsToHide = new RangeList();
+ for (final IValueIterator rowIter = new ValueIterator(command.getPositions()); rowIter.hasNext(); ) {
+ final int rowPos = rowIter.nextValue();
+ rowPositionsToHide.values().add(rowPos);
int rowIndex = getRowIndexByPosition(rowPos);
if (this.treeRowModel.hasChildren(rowIndex) && !this.treeRowModel.isCollapsed(rowIndex)) {
List<Integer> childIndexes = this.treeRowModel.getChildIndexes(rowIndex);
for (Integer childIndex : childIndexes) {
- rowPositionsToHide.add(getRowPositionByIndex(childIndex));
+ rowPositionsToHide.values().add(getRowPositionByIndex(childIndex));
}
}
}
- int[] childPositions = new int[rowPositionsToHide.size()];
- for (int i = 0; i < rowPositionsToHide.size(); i++) {
- childPositions[i] = rowPositionsToHide.get(i);
- }
- return super.doCommand(new MultiRowHideCommand(this, childPositions));
+ return super.doCommand(new MultiRowHideCommand(this, rowPositionsToHide));
}
return super.doCommand(command);
}
diff --git a/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/test/integration/HideMultipleColumnsIntegrationTest.java b/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/test/integration/HideMultipleColumnsIntegrationTest.java
index 45741e9..befc6e7 100644
--- a/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/test/integration/HideMultipleColumnsIntegrationTest.java
+++ b/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/test/integration/HideMultipleColumnsIntegrationTest.java
@@ -10,8 +10,13 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.extension.glazedlists.test.integration;
+import ca.odell.glazedlists.GlazedLists;
+
+import org.junit.Assert;
+import org.junit.Test;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.coordinate.RangeList;
import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor;
import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand;
import org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent;
@@ -20,10 +25,6 @@
import org.eclipse.nebula.widgets.nattable.test.fixture.data.RowDataFixture;
import org.eclipse.nebula.widgets.nattable.test.fixture.data.RowDataListFixture;
import org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture;
-import org.junit.Assert;
-import org.junit.Test;
-
-import ca.odell.glazedlists.GlazedLists;
public class HideMultipleColumnsIntegrationTest {
@@ -46,8 +47,8 @@
Assert.assertEquals(6, natTableFixture.getColumnCount());
MultiColumnHideCommand hideAllCommand = new MultiColumnHideCommand(natTableFixture,
- new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36});
+ new RangeList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36));
natTableFixture.doCommand(hideAllCommand);
Assert.assertEquals(1, listenerFixture.getEventsCount());