Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-12-02 12:57:49 +0000
committerGerrit Code Review @ Eclipse.org2016-12-05 13:13:48 +0000
commit8c0dfdb1d3bd4dafbd9ae522a133107d96a347a1 (patch)
tree216b66f09791eb992c30d09af945fb1a268cf01c
parente93c0f1448be40026aebf67ec63c16a264cbe5a0 (diff)
downloadorg.eclipse.papyrus-8c0dfdb1d3bd4dafbd9ae522a133107d96a347a1.tar.gz
org.eclipse.papyrus-8c0dfdb1d3bd4dafbd9ae522a133107d96a347a1.tar.xz
org.eclipse.papyrus-8c0dfdb1d3bd4dafbd9ae522a133107d96a347a1.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: I6ae7b15bb9d82e897dac0e1213dee0412f242cbb Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java5
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PercentageCalculationUtils.java44
2 files changed, 48 insertions, 1 deletions
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 fc7288e0e6c..4ccd68f3bf2 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
@@ -142,6 +142,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;
@@ -1617,8 +1618,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
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;
+ }
+
+}

Back to the top