diff options
author | Jan Dockx | 2014-02-14 19:12:29 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2014-02-26 15:43:36 +0000 |
commit | 869ac6e13d99a15a81f24dce9e09b9636008ddde (patch) | |
tree | acd4aa876e22940ad82bd4c83ef1591ac30ee90a | |
parent | a02de565e7a605bc0507de1fc6eea959ef4d781c (diff) | |
download | org.eclipse.nebula.widgets.nattable-869ac6e13d99a15a81f24dce9e09b9636008ddde.tar.gz org.eclipse.nebula.widgets.nattable-869ac6e13d99a15a81f24dce9e09b9636008ddde.tar.xz org.eclipse.nebula.widgets.nattable-869ac6e13d99a15a81f24dce9e09b9636008ddde.zip |
Bug 428183 - Minor: Resizing rows with different heights improvement
Added same logic for Column Resizing.
Removed trailing white spaces.
Change-Id: I26a2b25f65093abbd7bb495e9bafde962aef5bff
Signed-off-by: Jan Dockx <jan.dockx@outlook.com>
7 files changed, 288 insertions, 67 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigPercentageTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigPercentageTest.java index 9d4a64c2..04afec70 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigPercentageTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigPercentageTest.java @@ -4,7 +4,7 @@ * 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: * Dirk Fauth ******************************************************************************/ @@ -127,6 +127,42 @@ public class SizeConfigPercentageTest { Assert.assertEquals(1000, sizeConfigCalculationMode.getAggregateSize(20)); } + @Test + public void getAggregateSizeCalculationModeSpaceChangeCacheCheck() throws Exception { + // Change the space and positionCount to test the cached aggregated size values. + sizeConfigCalculationMode.calculatePercentages(1000, 20); + + Assert.assertEquals(100, sizeConfigCalculationMode.getAggregateSize(2)); + Assert.assertEquals(200, sizeConfigCalculationMode.getAggregateSize(4)); + Assert.assertEquals(300, sizeConfigCalculationMode.getAggregateSize(6)); + Assert.assertEquals(400, sizeConfigCalculationMode.getAggregateSize(8)); + Assert.assertEquals(500, sizeConfigCalculationMode.getAggregateSize(10)); + + sizeConfigCalculationMode.calculatePercentages(500, 20); + + Assert.assertEquals(50, sizeConfigCalculationMode.getAggregateSize(2)); + Assert.assertEquals(100, sizeConfigCalculationMode.getAggregateSize(4)); + Assert.assertEquals(150, sizeConfigCalculationMode.getAggregateSize(6)); + Assert.assertEquals(200, sizeConfigCalculationMode.getAggregateSize(8)); + Assert.assertEquals(250, sizeConfigCalculationMode.getAggregateSize(10)); + + sizeConfigCalculationMode.calculatePercentages(500, 10); + + Assert.assertEquals(100, sizeConfigCalculationMode.getAggregateSize(2)); + Assert.assertEquals(200, sizeConfigCalculationMode.getAggregateSize(4)); + Assert.assertEquals(300, sizeConfigCalculationMode.getAggregateSize(6)); + Assert.assertEquals(400, sizeConfigCalculationMode.getAggregateSize(8)); + Assert.assertEquals(500, sizeConfigCalculationMode.getAggregateSize(10)); + } + + @Test + public void getAggregateSizeCalculationModeSizeChangeCacheCheck() throws Exception { + Assert.assertEquals(500, sizeConfigCalculationMode.getAggregateSize(5)); + + sizeConfigCalculationMode.setPercentage(5, 20); + + Assert.assertEquals(440, sizeConfigCalculationMode.getAggregateSize(5)); + } @Test public void getSizeConfigFixedMode() throws Exception { @@ -169,7 +205,7 @@ public class SizeConfigPercentageTest { sizeConfigFixedMode.setPercentage(2, 50); sizeConfigFixedMode.setPercentage(3, 50); - //the correct double value would be 127.5 - because of the rounding as there are no + //the correct double value would be 127.5 - because of the rounding as there are no //double pixels, the values for the first 3 positions will be 127 Assert.assertEquals(127, sizeConfigFixedMode.getSize(0)); Assert.assertEquals(127, sizeConfigFixedMode.getSize(1)); @@ -222,6 +258,34 @@ public class SizeConfigPercentageTest { } @Test + public void getAggregateSizeFixedModeSpaceChangeCacheCheck() throws Exception { + Assert.assertEquals(127, sizeConfigFixedMode.getAggregateSize(1)); + Assert.assertEquals(255, sizeConfigFixedMode.getAggregateSize(2)); + + sizeConfigFixedMode.calculatePercentages(500, 2); + + Assert.assertEquals(250, sizeConfigFixedMode.getAggregateSize(1)); + Assert.assertEquals(500, sizeConfigFixedMode.getAggregateSize(2)); + + sizeConfigFixedMode.calculatePercentages(255, 3); + + Assert.assertEquals(127, sizeConfigFixedMode.getSize(0)); + Assert.assertEquals(127, sizeConfigFixedMode.getSize(1)); + Assert.assertEquals(1, sizeConfigFixedMode.getSize(2)); + } + + @Test + public void getAggregateSizeFixedModeSizeChangeCacheCheck() throws Exception { + Assert.assertEquals(127, sizeConfigFixedMode.getAggregateSize(1)); + Assert.assertEquals(255, sizeConfigFixedMode.getAggregateSize(2)); + + sizeConfigFixedMode.setPercentage(1, 40); + + Assert.assertEquals(127, sizeConfigFixedMode.getAggregateSize(1)); + Assert.assertEquals(229, sizeConfigFixedMode.getAggregateSize(2)); + } + + @Test public void getSizeConfigMixedPercentageMode() throws Exception { Assert.assertEquals(300, sizeConfigMixedPercentageMode.getSize(0)); Assert.assertEquals(400, sizeConfigMixedPercentageMode.getSize(1)); @@ -322,6 +386,33 @@ public class SizeConfigPercentageTest { } @Test + public void getAggregateSizeMixedModeSpaceChangeCacheCheck() throws Exception { + Assert.assertEquals(300, sizeConfigMixedPercentageMode.getAggregateSize(1)); + Assert.assertEquals(700, sizeConfigMixedPercentageMode.getAggregateSize(2)); + Assert.assertEquals(1000, sizeConfigMixedPercentageMode.getAggregateSize(3)); + + sizeConfigMixedPercentageMode.calculatePercentages(1000, 4); + + Assert.assertEquals(300, sizeConfigMixedPercentageMode.getAggregateSize(1)); + Assert.assertEquals(500, sizeConfigMixedPercentageMode.getAggregateSize(2)); + Assert.assertEquals(800, sizeConfigMixedPercentageMode.getAggregateSize(3)); + Assert.assertEquals(1000, sizeConfigMixedPercentageMode.getAggregateSize(4)); + } + + @Test + public void getAggregateSizeMixedModeSizeChangeCacheCheck() throws Exception { + Assert.assertEquals(300, sizeConfigMixedPercentageMode.getAggregateSize(1)); + Assert.assertEquals(700, sizeConfigMixedPercentageMode.getAggregateSize(2)); + Assert.assertEquals(1000, sizeConfigMixedPercentageMode.getAggregateSize(3)); + + sizeConfigMixedPercentageMode.setPercentage(2, 40); + + Assert.assertEquals(300, sizeConfigMixedPercentageMode.getAggregateSize(1)); + Assert.assertEquals(600, sizeConfigMixedPercentageMode.getAggregateSize(2)); + Assert.assertEquals(1000, sizeConfigMixedPercentageMode.getAggregateSize(3)); + } + + @Test public void getSizeConfigMixedMode() throws Exception { Assert.assertEquals(100, sizeConfigMixedMode.getSize(0)); Assert.assertEquals(100, sizeConfigMixedMode.getSize(1)); @@ -392,7 +483,7 @@ public class SizeConfigPercentageTest { Assert.assertEquals(100, sizeConfigMixedMode.getSize(0)); Assert.assertEquals(100, sizeConfigMixedMode.getSize(1)); - //this column does not have a percentage width set, so it will be 0 if + //this column does not have a percentage width set, so it will be 0 if //other columns with fixed percentage widths are added Assert.assertEquals(0, sizeConfigMixedMode.getSize(2)); //4 additional percentage sized positions that have the same percentage size @@ -403,4 +494,45 @@ public class SizeConfigPercentageTest { Assert.assertEquals(100, sizeConfigMixedMode.getSize(6)); } + @Test + public void getAggregateMixedModeSpaceChangeCacheCheck() throws Exception { + Assert.assertEquals(100, sizeConfigMixedMode.getAggregateSize(1)); + Assert.assertEquals(200, sizeConfigMixedMode.getAggregateSize(2)); + Assert.assertEquals(500, sizeConfigMixedMode.getAggregateSize(3)); + + sizeConfigMixedMode.calculatePercentages(1000, 3); + + Assert.assertEquals(100, sizeConfigMixedMode.getAggregateSize(1)); + Assert.assertEquals(200, sizeConfigMixedMode.getAggregateSize(2)); + Assert.assertEquals(1000, sizeConfigMixedMode.getAggregateSize(3)); + + sizeConfigMixedMode.calculatePercentages(500, 4); + + Assert.assertEquals(100, sizeConfigMixedMode.getAggregateSize(1)); + Assert.assertEquals(200, sizeConfigMixedMode.getAggregateSize(2)); + Assert.assertEquals(350, sizeConfigMixedMode.getAggregateSize(3)); + Assert.assertEquals(500, sizeConfigMixedMode.getAggregateSize(4)); + } + + @Test + public void getAggregateMixedModeSizeChangeCacheCheck() throws Exception { + Assert.assertEquals(100, sizeConfigMixedMode.getAggregateSize(1)); + Assert.assertEquals(200, sizeConfigMixedMode.getAggregateSize(2)); + Assert.assertEquals(500, sizeConfigMixedMode.getAggregateSize(3)); + + sizeConfigMixedMode.setPercentage(2, 25); + sizeConfigMixedMode.setPercentage(3, 25); + sizeConfigMixedMode.setPercentage(4, 25); + sizeConfigMixedMode.setPercentage(5, 25); + + sizeConfigMixedMode.calculatePercentages(1000, 6); + + Assert.assertEquals(100, sizeConfigMixedMode.getAggregateSize(1)); + Assert.assertEquals(200, sizeConfigMixedMode.getAggregateSize(2)); + Assert.assertEquals(400, sizeConfigMixedMode.getAggregateSize(3)); + Assert.assertEquals(600, sizeConfigMixedMode.getAggregateSize(4)); + Assert.assertEquals(800, sizeConfigMixedMode.getAggregateSize(5)); + Assert.assertEquals(1000, sizeConfigMixedMode.getAggregateSize(6)); + } + } diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigTest.java index 3839c461..333fa6d1 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigTest.java @@ -4,7 +4,7 @@ * 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 ******************************************************************************/ @@ -92,4 +92,20 @@ public class SizeConfigTest { Assert.assertEquals(100, sc.getAggregateSize(4)); } + + @Test + public void testAggregateSizeCache() { + final SizeConfig sc = new SizeConfig(100); + sc.setSize(0, 50); + Assert.assertEquals(450, sc.getAggregateSize(5)); + sc.setSize(1, 50); + Assert.assertEquals(400, sc.getAggregateSize(5)); + sc.setSize(2, 50); + Assert.assertEquals(350, sc.getAggregateSize(5)); + sc.setDefaultSize(75); + Assert.assertEquals(300, sc.getAggregateSize(5)); + sc.setSize(2, 100); + Assert.assertEquals(350, sc.getAggregateSize(5)); + } + } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java index 7b9637e9..a5548b1a 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java @@ -211,14 +211,18 @@ public class DataLayer extends AbstractLayer implements IUniqueIndexLayer { @Override public int getColumnWidthByPosition(int columnPosition) { - return columnWidthConfig.getSize(columnPosition); - } + return columnWidthConfig.getSize(columnPosition); + } public void setColumnWidthByPosition(int columnPosition, int width) { + setColumnWidthByPosition(columnPosition, width, true); + } + + public void setColumnWidthByPosition(int columnPosition, int width, boolean fireEvent) { columnWidthConfig.setSize(columnPosition, width); - fireLayerEvent(new ColumnResizeEvent(this, columnPosition)); + if (fireEvent) fireLayerEvent(new ColumnResizeEvent(this, columnPosition)); } - + public void setColumnWidthPercentageByPosition(int columnPosition, int width) { columnWidthConfig.setPercentage(columnPosition, width); fireLayerEvent(new ColumnResizeEvent(this, columnPosition)); @@ -325,10 +329,14 @@ public class DataLayer extends AbstractLayer implements IUniqueIndexLayer { } public void setRowHeightByPosition(int rowPosition, int height) { + setRowHeightByPosition(rowPosition, height, true); + } + + public void setRowHeightByPosition(int rowPosition, int height, boolean fireEvent) { rowHeightConfig.setSize(rowPosition, height); - fireLayerEvent(new RowResizeEvent(this, rowPosition)); + if (fireEvent) fireLayerEvent(new RowResizeEvent(this, rowPosition)); } - + public void setRowHeightPercentageByPosition(int rowPosition, int height) { rowHeightConfig.setPercentage(rowPosition, height); fireLayerEvent(new ColumnResizeEvent(this, rowPosition)); diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java index 24768c7e..8d9e3bf4 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java @@ -4,13 +4,14 @@ * 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.layer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -23,9 +24,9 @@ import org.eclipse.nebula.widgets.nattable.persistence.IPersistable; /** * This class stores the size configuration of rows/columns within the NatTable. - * + * * Mixed mode (fixed/percentage sizing):<br> - * The mixed mode is only working if percentage sizing is enabled globally, and + * The mixed mode is only working if percentage sizing is enabled globally, and * the fixed sized positions are marked separately. */ public class SizeConfig implements IPersistable { @@ -75,6 +76,12 @@ public class SizeConfig implements IPersistable { * This map is not persisted as it will be calculated on resize. */ private final Map<Integer, Integer> realSizeMap = new TreeMap<Integer, Integer>(); + /** + * Map that contains the cached aggregated sizes. + * The boolean tells if the cache is still valid. + */ + private final Map<Integer, Integer> aggregatedSizeCacheMap = new HashMap<Integer, Integer>(); + private boolean isAggregatedSizeCacheValid = true; /** * Create a new {@link SizeConfig} with the given default size. @@ -116,7 +123,8 @@ public class SizeConfig implements IPersistable { defaultSizeMap.clear(); sizeMap.clear(); resizablesMap.clear(); - + aggregatedSizeCacheMap.clear(); + String persistedDefaultSize = properties.getProperty(prefix + PERSISTENCE_KEY_DEFAULT_SIZE); if (!StringUtils.isEmpty(persistedDefaultSize)) { defaultSize = Integer.valueOf(persistedDefaultSize).intValue(); @@ -171,6 +179,7 @@ public class SizeConfig implements IPersistable { throw new IllegalArgumentException("size < 0"); //$NON-NLS-1$ } this.defaultSize = size; + this.isAggregatedSizeCacheValid = false; } public void setDefaultSize(int position, int size) { @@ -178,6 +187,7 @@ public class SizeConfig implements IPersistable { throw new IllegalArgumentException("size < 0"); //$NON-NLS-1$ } defaultSizeMap.put(position, size); + this.isAggregatedSizeCacheValid = false; } private int getDefaultSize(int position) { @@ -201,32 +211,17 @@ public class SizeConfig implements IPersistable { //and not as pixel values, therefore another value needs to be considered return position * defaultSize; } else { - int resizeAggregate = 0; - int resizedColumns = 0; - - Map<Integer, Integer> mapToUse = isPercentageSizing() ? realSizeMap : sizeMap; - - for (Integer resizedPosition : mapToUse.keySet()) { - if (resizedPosition.intValue() < position) { - resizedColumns++; - resizeAggregate += mapToUse.get(resizedPosition); - } else { - break; - } + // See if the cache is valid, if not clear it. + if (!isAggregatedSizeCacheValid) { + aggregatedSizeCacheMap.clear(); + isAggregatedSizeCacheValid = true; } - //also take into account the default size configuration per position - for (Integer defaultPosition : defaultSizeMap.keySet()) { - if (defaultPosition.intValue() < position) { - if (!mapToUse.containsKey(defaultPosition)) { - resizedColumns++; - resizeAggregate += defaultSizeMap.get(defaultPosition).intValue(); - } - } else { - break; - } + if (!aggregatedSizeCacheMap.containsKey(position)) { + int aggregatedSize = calculateAggregatedSize(position); + aggregatedSizeCacheMap.put(position, aggregatedSize); } - return (position * defaultSize) + (resizeAggregate - (resizedColumns * defaultSize)); + return aggregatedSizeCacheMap.get(position); } } @@ -253,7 +248,7 @@ public class SizeConfig implements IPersistable { * <p> * If you want to use percentage sizing you should use {@link SizeConfig#setPercentage(int, int)} * for manual size configuration to avoid unnecessary calculations. - * + * * @param position The position for which the size should be set. * @param size The size in pixels to set for the given position. */ @@ -271,9 +266,9 @@ public class SizeConfig implements IPersistable { sizeMap.put(position, percentage.intValue()); } } - - if (isPercentageSizing()) - calculatePercentages(availableSpace, realSizeMap.size()); + + calculatePercentages(availableSpace, realSizeMap.size()); + isAggregatedSizeCacheValid = false; } } @@ -296,7 +291,7 @@ public class SizeConfig implements IPersistable { calculatePercentages(availableSpace, realSizeMap.size()); } } - + // Resizable /** @@ -361,13 +356,14 @@ public class SizeConfig implements IPersistable { } return this.percentageSizing; } - + /** * @param percentageSizing <code>true</code> if the size of the positions should be interpreted percentaged, * <code>false</code> if the size of the positions should be interpreted by pixel. */ public void setPercentageSizing(boolean percentageSizing) { this.percentageSizing = percentageSizing; + this.isAggregatedSizeCacheValid = false; } /** @@ -393,6 +389,7 @@ public class SizeConfig implements IPersistable { */ public void setPercentageSizing(int position, boolean percentageSizing) { percentageSizingMap.put(position, percentageSizing); + isAggregatedSizeCacheValid = false; } /** @@ -402,10 +399,11 @@ public class SizeConfig implements IPersistable { */ public void calculatePercentages(int space, int positionCount) { if (isPercentageSizing()) { + this.isAggregatedSizeCacheValid = false; this.availableSpace = space; - + int percentageSpace = calculateAvailableSpace(space); - + int sum = 0; int real = 0; int realSum = 0; @@ -427,18 +425,18 @@ public class SizeConfig implements IPersistable { this.realSizeMap.put(i, real); } else { //remember the position for which no size information exists - //needed to calculate the size for those positions dependent on the + //needed to calculate the size for those positions dependent on the //remaining space noInfoPositions.add(i); } } - + int[] correction = correctPercentageValues(sum, positionCount); if (correction != null) { sum = correction[0]; realSum = correction[1] + fixedSum; } - + if (!noInfoPositions.isEmpty()) { //now calculate the size for the remaining columns double remaining = new Double(space) - realSum; @@ -462,7 +460,7 @@ public class SizeConfig implements IPersistable { valueSum += entry.getValue(); lastPos = Math.max(lastPos, entry.getKey()); } - + if (valueSum < space) { int lastPosValue = this.realSizeMap.get(lastPos); this.realSizeMap.put(lastPos, lastPosValue + (space - valueSum)); @@ -470,7 +468,7 @@ public class SizeConfig implements IPersistable { } } } - + /** * @param percentage The percentage value. * @param space The available space @@ -502,7 +500,7 @@ public class SizeConfig implements IPersistable { } } return space; - } + } /** * This method is used to correct the calculated percentage values in case a user configured @@ -510,7 +508,7 @@ public class SizeConfig implements IPersistable { * 100 percent. * @param sum The sum of all configured percentage sized positions. * @param positionCount The number of positions to check. - * @return Integer array with the sum value at first position and the new calculated real pixel + * @return Integer array with the sum value at first position and the new calculated real pixel * sum at second position in case a corrections took place. Will return <code>null</code> * in case no correction happened. */ @@ -527,7 +525,7 @@ public class SizeConfig implements IPersistable { if (sum > 100) { //calculate the factor which needs to be used to normalize the values double factor = Double.valueOf(100) / Double.valueOf(sum); - + //update the percentage size values by the calculated factor int realSum = 0; for (Map.Entry<Integer, Integer> mod : toModify.entrySet()) { @@ -536,12 +534,42 @@ public class SizeConfig implements IPersistable { realSum += newValue; this.realSizeMap.put(mod.getKey(), newValue); } - + return new int[] {100, realSum}; } - + //the given sum is not greater than 100 so we do not have to modify anything return null; } + private int calculateAggregatedSize(int position) { + int resizeAggregate = 0; + int resizedColumns = 0; + + Map<Integer, Integer> mapToUse = isPercentageSizing() ? realSizeMap : sizeMap; + + for (Integer resizedPosition : mapToUse.keySet()) { + if (resizedPosition.intValue() < position) { + resizedColumns++; + resizeAggregate += mapToUse.get(resizedPosition); + } else { + break; + } + } + + //also take into account the default size configuration per position + for (Integer defaultPosition : defaultSizeMap.keySet()) { + if (defaultPosition.intValue() < position) { + if (!mapToUse.containsKey(defaultPosition)) { + resizedColumns++; + resizeAggregate += defaultSizeMap.get(defaultPosition).intValue(); + } + } else { + break; + } + } + + return (position * defaultSize) + (resizeAggregate - (resizedColumns * defaultSize)); + } + } 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 1613e290..974991de 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 @@ -4,14 +4,20 @@ * 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.resize.command; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler; +import org.eclipse.nebula.widgets.nattable.coordinate.PositionUtil; +import org.eclipse.nebula.widgets.nattable.coordinate.Range; import org.eclipse.nebula.widgets.nattable.layer.DataLayer; +import org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent; public class MultiColumnResizeCommandHandler extends AbstractLayerCommandHandler<MultiColumnResizeCommand> { @@ -20,16 +26,26 @@ public class MultiColumnResizeCommandHandler extends AbstractLayerCommandHandler public MultiColumnResizeCommandHandler(DataLayer dataLayer) { this.dataLayer = dataLayer; } - + + @Override public Class<MultiColumnResizeCommand> getCommandClass() { return MultiColumnResizeCommand.class; } @Override protected boolean doCommand(MultiColumnResizeCommand command) { + List<Integer> columnPositions = new ArrayList<Integer>(); + for (int columnPosition : command.getColumnPositions()) { - dataLayer.setColumnWidthByPosition(columnPosition, command.getColumnWidth(columnPosition)); + columnPositions.add(columnPosition); + dataLayer.setColumnWidthByPosition(columnPosition, command.getColumnWidth(columnPosition), false); } + + List<Range> ranges = PositionUtil.getRanges(columnPositions); + for (Range range : ranges) { + dataLayer.fireLayerEvent(new ColumnResizeEvent(dataLayer, range)); + } + return true; } 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 495227a6..653351de 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 @@ -10,8 +10,14 @@ ******************************************************************************/ package org.eclipse.nebula.widgets.nattable.resize.command; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler; +import org.eclipse.nebula.widgets.nattable.coordinate.PositionUtil; +import org.eclipse.nebula.widgets.nattable.coordinate.Range; import org.eclipse.nebula.widgets.nattable.layer.DataLayer; +import org.eclipse.nebula.widgets.nattable.resize.event.RowResizeEvent; public class MultiRowResizeCommandHandler extends AbstractLayerCommandHandler<MultiRowResizeCommand> { @@ -20,16 +26,25 @@ public class MultiRowResizeCommandHandler extends AbstractLayerCommandHandler<Mu public MultiRowResizeCommandHandler(DataLayer dataLayer) { this.dataLayer = dataLayer; } - + public Class<MultiRowResizeCommand> getCommandClass() { return MultiRowResizeCommand.class; } @Override protected boolean doCommand(MultiRowResizeCommand command) { + List<Integer> rowPositions = new ArrayList<Integer>(); + for (int rowPosition : command.getRowPositions()) { - dataLayer.setRowHeightByPosition(rowPosition, command.getRowHeight(rowPosition)); + rowPositions.add(rowPosition); + dataLayer.setRowHeightByPosition(rowPosition, command.getRowHeight(rowPosition), false); } + + List<Range> ranges = PositionUtil.getRanges(rowPositions); + for (Range range : ranges) { + dataLayer.fireLayerEvent(new RowResizeEvent(dataLayer, range)); + } + return true; } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/event/ColumnResizeEvent.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/event/ColumnResizeEvent.java index f81ef61c..8a934090 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/event/ColumnResizeEvent.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/event/ColumnResizeEvent.java @@ -4,7 +4,7 @@ * 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 ******************************************************************************/ @@ -25,23 +25,29 @@ public class ColumnResizeEvent extends ColumnStructuralChangeEvent { public ColumnResizeEvent(ILayer layer, int columnPosition) { super(layer, new Range(columnPosition, columnPosition + 1)); } - + + public ColumnResizeEvent(ILayer layer, Range columnPositionRange) { + super(layer, columnPositionRange); + } + protected ColumnResizeEvent(ColumnResizeEvent event) { super(event); } - + + @Override public ColumnResizeEvent cloneEvent() { return new ColumnResizeEvent(this); } - + + @Override public Collection<StructuralDiff> getColumnDiffs() { Collection<StructuralDiff> rowDiffs = new ArrayList<StructuralDiff>(); - + for (Range range : getColumnPositionRanges()) { rowDiffs.add(new StructuralDiff(DiffTypeEnum.CHANGE, range, range)); } - + return rowDiffs; } - + } |