Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-05-04 07:17:04 +0000
committerGerrit Code Review @ Eclipse.org2016-05-12 15:05:35 +0000
commita58fd4ea17e841daa8b2a9a8462b16e9244e2bd3 (patch)
tree6a215665b91442fce653fa2e3936a6d208258bf4 /plugins/infra/nattable
parentefeca3c6b32becad454cc87f21a34f5377ce5b7e (diff)
downloadorg.eclipse.papyrus-a58fd4ea17e841daa8b2a9a8462b16e9244e2bd3.tar.gz
org.eclipse.papyrus-a58fd4ea17e841daa8b2a9a8462b16e9244e2bd3.tar.xz
org.eclipse.papyrus-a58fd4ea17e841daa8b2a9a8462b16e9244e2bd3.zip
Bug 489720: [Table] In Property View, Tables are not resized based on
the view size and layout option https://bugs.eclipse.org/bugs/show_bug.cgi?id=489720 Manage an utils class for the width calculation + JUnit test. Change-Id: I5903c9a3f7053c3a28ed8cf8a1bd1da9de3494b0 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/infra/nattable')
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java22
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PapyrusTableSizeCalculation.java64
2 files changed, 70 insertions, 16 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 2f7d57ac55e..c0a2bcd3876 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
@@ -136,6 +136,7 @@ import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagemen
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.TableEditingDomainUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableGridRegion;
import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
@@ -678,7 +679,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
* @since 2.0
*/
public MenuManager createAndRegisterMenuManagerAndSelectionProvider(final NatTable natTable, final IWorkbenchPartSite site, ISelectionProvider selectionProvider) {
- final MenuManager menuManager = new MenuManager("#PopUp", "org.eclipse.papyrus.infra.nattable.widget.menu") ; //$NON-NLS-1$ //$NON-NLS-2$
+ final MenuManager menuManager = new MenuManager("#PopUp", "org.eclipse.papyrus.infra.nattable.widget.menu"); //$NON-NLS-1$ //$NON-NLS-2$
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.setRemoveAllWhenShown(true);
return menuManager;
@@ -1461,21 +1462,10 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
if (null != parent && !parent.isDisposed()) {
final int parentSize = parent.getSize().x;
- // Calculate the rows header width
- if(0 < parentSize){
- int headerWidth = 0;
- if (null != getRowHeaderLayerStack()) {
- for (int headerColumnIndex = 0; headerColumnIndex < getRowHeaderLayerStack().getColumnCount(); headerColumnIndex++) {
- headerWidth += getRowHeaderLayerStack().getColumnWidthByPosition(headerColumnIndex);
- }
- }
-
- // Remove the rows header size from the parent size
- final int allColumnsSize = parentSize - headerWidth;
-
- // Divide the width of all columns by the number of column to calculate the width by column
- final int columnSize = allColumnsSize / getBodyLayerStack().getColumnHideShowLayer().getColumnCount();
-
+ // Get the column width needed
+ final int columnSize = PapyrusTableSizeCalculation.getColumnFillWidth(this, parentSize);
+
+ if (0 < columnSize) {
// Affext the width to the column
for (int columnPosition = 0; columnPosition < getBodyLayerStack().getColumnHideShowLayer().getColumnCount(); columnPosition++) {
getBodyLayerStack().getBodyDataLayer().setColumnWidthByPosition(columnPosition, columnSize);
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PapyrusTableSizeCalculation.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PapyrusTableSizeCalculation.java
new file mode 100644
index 00000000000..cffd0228748
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PapyrusTableSizeCalculation.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * 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;
+
+import org.eclipse.papyrus.infra.nattable.manager.table.AbstractNattableWidgetManager;
+
+/**
+ * This allows to manage the size calculation of header, rows and columns.
+ *
+ * @since 2.0
+ */
+public class PapyrusTableSizeCalculation {
+
+ /**
+ * Get the row header width of the current table.
+ *
+ * @param nattableModelManager The nattable model manager.
+ * @return The row header width.
+ */
+ public static int getRowHeaderWidth(final AbstractNattableWidgetManager nattableModelManager){
+ int headerWidth = 0;
+ if (null != nattableModelManager.getRowHeaderLayerStack()) {
+ for (int headerColumnIndex = 0; headerColumnIndex < nattableModelManager.getRowHeaderLayerStack().getColumnCount(); headerColumnIndex++) {
+ headerWidth += nattableModelManager.getRowHeaderLayerStack().getColumnWidthByPosition(headerColumnIndex);
+ }
+ }
+ return headerWidth;
+ }
+
+ /**
+ * This allows to calculate the column width when it is needed to fill the column to the parent.
+ *
+ * @param nattableWidgetManager The nattable model manager.
+ * @param parentSize The parent size.
+ * @return The optimized column width.
+ */
+ public static int getColumnFillWidth(final AbstractNattableWidgetManager nattableWidgetManager, final int parentSize){
+ int columnSize=0;
+
+ if(0 < parentSize){
+ int headerWidth = getRowHeaderWidth(nattableWidgetManager);
+
+ // Remove the rows header size from the parent size
+ final int allColumnsSize = parentSize - headerWidth;
+
+ // Divide the width of all columns by the number of column to calculate the width by column
+ columnSize = allColumnsSize / nattableWidgetManager.getBodyLayerStack().getColumnHideShowLayer().getColumnCount();
+ }
+
+ return columnSize;
+ }
+
+}

Back to the top