diff options
| author | Nicolas FAUVERGUE | 2016-12-05 15:40:03 +0000 |
|---|---|---|
| committer | Gerrit Code Review @ Eclipse.org | 2016-12-05 15:45:40 +0000 |
| commit | b070b1933c7e1f792730acbde937ff0f789cbc8a (patch) | |
| tree | 386fd4f0f05572887c9cbeb17ce7dee133705cc0 | |
| parent | 15357a858aeef74d10a9714b0c5b374c390fa568 (diff) | |
| download | org.eclipse.papyrus-b070b1933c7e1f792730acbde937ff0f789cbc8a.tar.gz org.eclipse.papyrus-b070b1933c7e1f792730acbde937ff0f789cbc8a.tar.xz org.eclipse.papyrus-b070b1933c7e1f792730acbde937ff0f789cbc8a.zip | |
Bug 504077: [Table] Papyrus table to support percentage sizing offered
by NatTable https://bugs.eclipse.org/bugs/show_bug.cgi?id=504077
Improve percentage calculation to fill to exactly 100%.
Change-Id: I953d387b6914e137e2f11b0e6011c56ea64289f5
Signed-off-by: Nicolas FAUVERGUE <nicolasfauvergue@gmail.com>
3 files changed, 54 insertions, 4 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java index 8ff382baafb..d4b2ac94b30 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java @@ -56,6 +56,7 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.IntValueS import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage; import org.eclipse.papyrus.infra.nattable.utils.DefaultSizeUtils; import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants; +import org.eclipse.papyrus.infra.nattable.utils.PercentageCalculationUtils; import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; import org.eclipse.papyrus.infra.widgets.editors.InputDialog; @@ -997,7 +998,7 @@ public abstract class AbstractAxisManager implements IAxisManager { if (null != value) { if (isUsedPercentage) { // Set the percentage with the correct function - ((PapyrusSpanningDataLayer)tableBodyLayer).setColumnWidthPercentageByPosition(index, value.getIntValue()); + ((PapyrusSpanningDataLayer) tableBodyLayer).setColumnWidthPercentageByPosition(index, value.getIntValue()); remainingPercentage -= value.getIntValue(); } else { // we set the size of the axis in the graphical representation @@ -1015,8 +1016,10 @@ public abstract class AbstractAxisManager implements IAxisManager { } // For the axis without 'axisWidth' named style and with the columns width percentage management, set the correct percentage + int numberIndex = 0; for (int index : notManagedIndexAxisWidth) { - ((PapyrusSpanningDataLayer)tableBodyLayer).setColumnWidthPercentageByPosition(index, Math.round(remainingPercentage / notManagedIndexAxisWidth.size()), false); + ((PapyrusSpanningDataLayer) tableBodyLayer).setColumnWidthPercentageByPosition(index, PercentageCalculationUtils.calculatePercentageToSet(numberIndex, remainingPercentage, notManagedIndexAxisWidth.size()), false); + numberIndex++; } } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java index 3d098718951..c5abacaf519 100755 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java @@ -143,6 +143,7 @@ import org.eclipse.papyrus.infra.nattable.utils.LocationValue; import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants; import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes; import org.eclipse.papyrus.infra.nattable.utils.PapyrusTableSizeCalculation; +import org.eclipse.papyrus.infra.nattable.utils.PercentageCalculationUtils; import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; import org.eclipse.papyrus.infra.nattable.utils.TableGridRegion; import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper; @@ -1732,8 +1733,10 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan } // For the axis without 'axisWidth' named style and with the columns width percentage management, set the correct percentage + int numberIndex = 0; for (int index : notManagedIndexAxisWidth) { - tableBodyLayer.setColumnWidthPercentageByPosition(index, Math.round(remainingPercentage / notManagedIndexAxisWidth.size())); + tableBodyLayer.setColumnWidthPercentageByPosition(index, PercentageCalculationUtils.calculatePercentageToSet(numberIndex, remainingPercentage, notManagedIndexAxisWidth.size())); + numberIndex++; } // this method is used to resize by default. In the actual state, only the rows, representing the table's core elements, are missing from the notation file @@ -1755,7 +1758,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan } } } - + /** * This allows to manage the fill columns size named style by managing the width of columns to fill all the parent space. * diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PercentageCalculationUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PercentageCalculationUtils.java new file mode 100644 index 00000000000..14ad41b208e --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PercentageCalculationUtils.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST 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: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.nattable.utils; + +/** + * This allows to manage percentage calculation utils method. + */ +public class PercentageCalculationUtils { + + /** + * This allows to calculate the correct round percentage. + * + * @param index + * The index of the item to manage. + * @param sumPercentage + * The sum of the percentage. + * @param fragmentSize + * The number of fragment. + * @return The correct percentage to set. + */ + public static int calculatePercentageToSet(final int index, final int sumPercentage, final int fragmentSize) { + int roundPercentage = Math.round(sumPercentage / fragmentSize); + + int remainingPercentage = sumPercentage - (fragmentSize * roundPercentage); + + if (0 < remainingPercentage && index < remainingPercentage) { + roundPercentage++; + } + + return roundPercentage; + } + +} |
