Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-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