Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-11-22 23:36:07 +0000
committerGerrit Code Review @ Eclipse.org2016-12-05 13:39:57 +0000
commit74502beb31fc59559e17d6a1ac5f3655eb7121e7 (patch)
treeceb655e7c2b198572514aed1ec5d91fe0d56a36e /plugins
parentd273697183d67be8857da2131a2ed674685339ce (diff)
downloadorg.eclipse.papyrus-74502beb31fc59559e17d6a1ac5f3655eb7121e7.tar.gz
org.eclipse.papyrus-74502beb31fc59559e17d6a1ac5f3655eb7121e7.tar.xz
org.eclipse.papyrus-74502beb31fc59559e17d6a1ac5f3655eb7121e7.zip
Bug 504077: [Table] Papyrus table to support percentage sizing offered
by NatTable https://bugs.eclipse.org/bugs/show_bug.cgi?id=504077 Add the named styles: - 'columnsWidthAsPercentage' to manage axis width with percentage. If this named style is managed as true, the 'axisWidth' are managed as percentage too. - 'saveColumnsWidth' to determinate if the 'axisWidth' must be used for the table columns width initialization - Modify the 'stereotype.nattableconfiguration' to manage axisWidth as percentage instead of pixels Change-Id: I2a4b2ea3f6bbd710afa20864051c10f5761f4900 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layer/PapyrusSpanningDataLayer.java217
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java43
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java157
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java8
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java22
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.stereotype.display/config/stereotype.nattableconfiguration10
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/NattablePropertyEditor.java18
7 files changed, 339 insertions, 136 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layer/PapyrusSpanningDataLayer.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layer/PapyrusSpanningDataLayer.java
index 6c35102a9d5..a3293119ccb 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layer/PapyrusSpanningDataLayer.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/layer/PapyrusSpanningDataLayer.java
@@ -1,101 +1,116 @@
-/*****************************************************************************
- * Copyright (c) 2014-2015 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:
- * CEA LIST - Initial API and implementation
- * Camille Letavernier - CEA LIST - Bug 464168 - Use the Context's EditingDomain
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.nattable.layer;
-
-import java.util.List;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.nebula.widgets.nattable.coordinate.Range;
-import org.eclipse.nebula.widgets.nattable.data.ISpanningDataProvider;
-import org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer;
-import org.eclipse.nebula.widgets.nattable.util.ArrayUtil;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-
-/**
- *
- * @author QL238289
- * @see org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer
- *
- *
- */
-public class PapyrusSpanningDataLayer extends SpanningDataLayer {
-
- private TransactionalEditingDomain contextDomain;
-
- private INattableModelManager manager;
-
- /**
- * Constructor.
- *
- * @param dataProvider
- * @param defaultColumnWidth
- * @param defaultRowHeight
- */
- public PapyrusSpanningDataLayer(final TransactionalEditingDomain contextDomain, ISpanningDataProvider dataProvider, int defaultColumnWidth, int defaultRowHeight) {
- super(dataProvider, defaultColumnWidth, defaultRowHeight);
- this.contextDomain = contextDomain;
-
- }
-
- /**
- * Constructor.
- *
- * @param dataProvider
- */
- public PapyrusSpanningDataLayer(final TransactionalEditingDomain contextDomain, ISpanningDataProvider dataProvider) {
- super(dataProvider);
- this.contextDomain = contextDomain;
- }
-
-
- /**
- * Constructor.
- *
- * @param contextEditingDomain
- * @param manager
- * @param spanProvider
- * @param defaultCellWidth
- * @param defaultCellHeight
- */
- public PapyrusSpanningDataLayer(TransactionalEditingDomain contextEditingDomain, INattableModelManager manager,
- ISpanningDataProvider spanProvider, int defaultCellWidth, int defaultCellHeight) {
- super(spanProvider, defaultCellWidth, defaultCellHeight);
- this.contextDomain = contextEditingDomain;
- this.manager = manager;
- }
-
- /**
- * @see org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer#setDataValue(int, int, java.lang.Object)
- *
- * @param columnIndex
- * @param rowIndex
- * @param newValue
- */
- @Override
- public void setDataValue(final int columnIndex, final int rowIndex, final Object newValue) {
- RecordingCommand recordUpdate = new RecordingCommand(this.contextDomain) {
-
- @Override
- protected void doExecute() {
- // AbstractCellManager's setValue() takes care of the compatibility between the cell and the edit types
- // 469109: [Tree Table] set value problem when categories are hidden
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=469109
- PapyrusSpanningDataLayer.super.setDataValue(columnIndex, rowIndex, newValue);
- }
- };
- this.contextDomain.getCommandStack().execute(recordUpdate);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014-2015 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:
+ * CEA LIST - Initial API and implementation
+ * Camille Letavernier - CEA LIST - Bug 464168 - Use the Context's EditingDomain
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 504077
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.layer;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.nebula.widgets.nattable.data.ISpanningDataProvider;
+import org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer;
+import org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+
+/**
+ *
+ * @author QL238289
+ * @see org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer
+ *
+ *
+ */
+public class PapyrusSpanningDataLayer extends SpanningDataLayer {
+
+ private TransactionalEditingDomain contextDomain;
+
+ private INattableModelManager manager;
+
+ /**
+ * Constructor.
+ *
+ * @param dataProvider
+ * @param defaultColumnWidth
+ * @param defaultRowHeight
+ */
+ public PapyrusSpanningDataLayer(final TransactionalEditingDomain contextDomain, ISpanningDataProvider dataProvider, int defaultColumnWidth, int defaultRowHeight) {
+ super(dataProvider, defaultColumnWidth, defaultRowHeight);
+ this.contextDomain = contextDomain;
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param dataProvider
+ */
+ public PapyrusSpanningDataLayer(final TransactionalEditingDomain contextDomain, ISpanningDataProvider dataProvider) {
+ super(dataProvider);
+ this.contextDomain = contextDomain;
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param contextEditingDomain
+ * @param manager
+ * @param spanProvider
+ * @param defaultCellWidth
+ * @param defaultCellHeight
+ */
+ public PapyrusSpanningDataLayer(TransactionalEditingDomain contextEditingDomain, INattableModelManager manager,
+ ISpanningDataProvider spanProvider, int defaultCellWidth, int defaultCellHeight) {
+ super(spanProvider, defaultCellWidth, defaultCellHeight);
+ this.contextDomain = contextEditingDomain;
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer#setDataValue(int, int, java.lang.Object)
+ *
+ * @param columnIndex
+ * @param rowIndex
+ * @param newValue
+ */
+ @Override
+ public void setDataValue(final int columnIndex, final int rowIndex, final Object newValue) {
+ RecordingCommand recordUpdate = new RecordingCommand(this.contextDomain) {
+
+ @Override
+ protected void doExecute() {
+ // AbstractCellManager's setValue() takes care of the compatibility between the cell and the edit types
+ // 469109: [Tree Table] set value problem when categories are hidden
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=469109
+ PapyrusSpanningDataLayer.super.setDataValue(columnIndex, rowIndex, newValue);
+ }
+ };
+ this.contextDomain.getCommandStack().execute(recordUpdate);
+ }
+
+ /**
+ * This allows to set the column width with a percentage.
+ *
+ * @param columnPosition
+ * The column position to modify.
+ * @param width
+ * The width as percentage.
+ * @param fireEvent
+ * Boolean to determinate if layer event must be fire.
+ */
+ public void setColumnWidthPercentageByPosition(int columnPosition, int width, boolean fireEvent) {
+ this.columnWidthConfig.setPercentage(columnPosition, width);
+ if (fireEvent){
+ fireLayerEvent(new ColumnResizeEvent(this, columnPosition));
+ }
+ }
+}
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 e8838ec4ed2..8ff382baafb 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
@@ -9,14 +9,16 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 469289
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 469289, 504077
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.axis;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandWrapper;
@@ -38,6 +40,7 @@ import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.nattable.Activator;
+import org.eclipse.papyrus.infra.nattable.layer.PapyrusSpanningDataLayer;
import org.eclipse.papyrus.infra.nattable.layerstack.BodyLayerStack;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager;
@@ -47,6 +50,8 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisPackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.BooleanValueStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.IntValueStyle;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.NattablestylePackage;
import org.eclipse.papyrus.infra.nattable.utils.DefaultSizeUtils;
@@ -956,9 +961,21 @@ public abstract class AbstractAxisManager implements IAxisManager {
: tableManager.getTable().getCurrentColumnAxisProvider().getAxis();
final BodyLayerStack bodyLayerStack = tableManager.getBodyLayerStack();
// Check if the body layer stack is always constructed
- if(null != bodyLayerStack){
+ if (null != bodyLayerStack) {
final DataLayer tableBodyLayer = bodyLayerStack.getBodyDataLayer();
-
+
+ // Get the named style columns width as percentage management
+ BooleanValueStyle columnsWidthAsPercentage = (BooleanValueStyle) tableManager.getTable().getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.COLUMNS_WIDTH_AS_PERCENTAGE);
+ if (null == columnsWidthAsPercentage) {
+ final TableConfiguration config = tableManager.getTable().getTableConfiguration();
+ columnsWidthAsPercentage = (BooleanValueStyle) config.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.COLUMNS_WIDTH_AS_PERCENTAGE);
+ }
+ boolean isUsedPercentage = null != columnsWidthAsPercentage && columnsWidthAsPercentage.isBooleanValue();
+
+ // Get the axis with non 'axisWidth' named style (to set the correct percentage)
+ Set<Integer> notManagedIndexAxisWidth = new HashSet<Integer>();
+ int remainingPercentage = 100;
+
// Loop on columns axis to reset the width
for (int index = 0; index < notationAxisList.size(); index++) {
final IAxis currentAxis = notationAxisList.get(index);
@@ -978,15 +995,29 @@ public abstract class AbstractAxisManager implements IAxisManager {
final int axisWidth = tableBodyLayer.getColumnWidthByPosition(index);
final IntValueStyle value = (IntValueStyle) currentAxis.getNamedStyle(NattablestylePackage.eINSTANCE.getIntValueStyle(), NamedStyleConstants.AXIS_WIDTH);
if (null != value) {
- // we set the size of the axis in the graphical representation
- tableBodyLayer.setColumnWidthByPosition(index, value.getIntValue(), false);
- } else if (axisWidth != DefaultSizeUtils.getDefaultCellWidth()) {
+ if (isUsedPercentage) {
+ // Set the percentage with the correct function
+ ((PapyrusSpanningDataLayer)tableBodyLayer).setColumnWidthPercentageByPosition(index, value.getIntValue());
+ remainingPercentage -= value.getIntValue();
+ } else {
+ // we set the size of the axis in the graphical representation
+ tableBodyLayer.setColumnWidthByPosition(index, value.getIntValue(), false);
+ }
+ } else if (axisWidth != DefaultSizeUtils.getDefaultCellWidth() && !isUsedPercentage) {
// resets the size in case of an undo to the default table
tableBodyLayer.setColumnWidthByPosition(index, DefaultSizeUtils.getDefaultCellWidth(), false);
+ } else if (isUsedPercentage) {
+ // If the columns width are managed with percentage, we need to recalculate it
+ notManagedIndexAxisWidth.add(index);
}
}
}
}
+
+ // For the axis without 'axisWidth' named style and with the columns width percentage management, set the correct percentage
+ for (int index : notManagedIndexAxisWidth) {
+ ((PapyrusSpanningDataLayer)tableBodyLayer).setColumnWidthPercentageByPosition(index, Math.round(remainingPercentage / notManagedIndexAxisWidth.size()), false);
+ }
}
}
}
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 97301a07485..3d098718951 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
@@ -12,6 +12,7 @@
* Christian W. Damus (CEA) - bug 402525
* Christian W. Damus (CEA) - bug 430880
* Dirk Fauth <dirk.fauth@googlemail.com> - Bug 488234
+ * Nicolas FAUVERGUE(ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 504077
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.table;
@@ -19,8 +20,10 @@ package org.eclipse.papyrus.infra.nattable.manager.table;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.command.Command;
@@ -243,7 +246,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
*/
private BodyLayerStack bodyLayerStack;
- private ILayerListener resizeAxisListener;
+ protected ILayerListener resizeAxisListener;
private ILayerListener resizeRowHeaderListener;
@@ -875,7 +878,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
* @param bodyLayerStack
* the table's body layer
*/
- private void addAxisResizeListener(final BodyLayerStack bodyLayerStack) {
+ protected void addAxisResizeListener(final BodyLayerStack bodyLayerStack) {
resizeAxisListener = new ILayerListener() {
@Override
@@ -889,16 +892,41 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
}
if (event instanceof ColumnResizeEvent) {
+
// get the index of the first column modified by the user
// the assumption is that the user changes only one column at a time in order to resize to its liking
int resizedColumnPosition = getRangeStart(event);
// get the resized value from this column
- int newColumnSize = columnHeaderLayerStack.getColumnWidthByPosition(resizedColumnPosition);
- ICommand cmd = createSetColumnSizeCommand(resizedColumnPosition, newColumnSize);
- if (cmd != null && cmd.canExecute()) {
- resizeCommand.add(cmd);
- }
+ int newColumnSize = getBodyLayerStack().getBodyDataLayer().getColumnWidthByPosition(resizedColumnPosition);
+
+ // If the columns width are managed as percentage, transform the width to the percentage
+ if (isColumnWidthAsPercentage()) {
+ int columnSizePercentage = getInitialColumnWidthPercentage();
+
+ final Composite parent = natTable.getParent();
+ if (null != parent && !parent.isDisposed()) {
+ final int parentSize = parent.getSize().x;
+
+ // Get the columns size without header
+ final int columnsSize = parentSize - PapyrusTableSizeCalculation.getRowHeaderWidth(AbstractNattableWidgetManager.this);
+
+ // Calculate the current percentage of the new width
+ int currentPercentage = Math.round(newColumnSize * 100.0f / columnsSize);
+ // If the current percentage is not equals to the initial percentage, set the named style with the percentage, else do nothing
+ if (currentPercentage != columnSizePercentage) {
+ final ICommand cmd = createSetColumnSizeCommand(resizedColumnPosition, currentPercentage);
+ if (cmd != null && cmd.canExecute()) {
+ resizeCommand.add(cmd);
+ }
+ }
+ }
+ } else {
+ ICommand cmd = createSetColumnSizeCommand(resizedColumnPosition, newColumnSize);
+ if (cmd != null && cmd.canExecute()) {
+ resizeCommand.add(cmd);
+ }
+ }
}
// the process is the same for this event
@@ -924,6 +952,45 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
}
/**
+ * This allows to calculate the initial width percentage for a column without 'axisWidth' named style.
+ *
+ * @return The percentage for a column without 'axisWidth' named style.
+ * @since 3.0
+ */
+ protected int getInitialColumnWidthPercentage() {
+ int remainingPercentage = 100;
+ int numberColumnWithoutDefinedWidth = 0;
+
+ // Get the boolean value style to determinate if we need to use the columns width
+ BooleanValueStyle saveColumnsWidth = (BooleanValueStyle) getTable().getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.SAVE_COLUMNS_WIDTH);
+ if (null == saveColumnsWidth) {
+ final TableConfiguration config = getTable().getTableConfiguration();
+ saveColumnsWidth = (BooleanValueStyle) config.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.SAVE_COLUMNS_WIDTH);
+ }
+
+ List<IAxis> notationColumnsAxisList = getTable().getCurrentColumnAxisProvider().getAxis();
+ // we go through all the elements to find those which have been modified
+ for (int index = 0; index < notationColumnsAxisList.size(); index++) {
+ IAxis currentColumnAxis = notationColumnsAxisList.get(index);
+ // we need both to detect and use the correct value, width or height, of the handled element as the user could have modified the table when the axis was inverted
+ if (!getTable().isInvertAxis()) {
+ int axisWidth = getBodyLayerStack().getBodyDataLayer().getColumnWidthByPosition(index);
+ IntValueStyle value = (IntValueStyle) currentColumnAxis.getNamedStyle(NattablestylePackage.eINSTANCE.getIntValueStyle(), NamedStyleConstants.AXIS_WIDTH);
+ if (value != null && (null == saveColumnsWidth || (null != saveColumnsWidth && saveColumnsWidth.isBooleanValue()))) {
+ remainingPercentage -= axisWidth;
+ } else {
+ numberColumnWithoutDefinedWidth++;
+ }
+ }
+ }
+
+ if (0 == numberColumnWithoutDefinedWidth) {
+ numberColumnWithoutDefinedWidth = 1;
+ }
+ return Math.round(remainingPercentage / numberColumnWithoutDefinedWidth);
+ }
+
+ /**
* Create the set column size command for the column resizing.
*
* @param columnIndex
@@ -1583,6 +1650,24 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
// value, width or height, of the resized column or row
IntValueStyle value = null;
+ // Get the boolean value style to determinate if the width in named style is managed as percentage or as pixels
+ boolean isUsedPercentage = isColumnWidthAsPercentage();
+ if (isUsedPercentage) {
+ // Notify the column percentage management to the body layer
+ tableBodyLayer.setColumnPercentageSizing(true);
+ }
+
+ // Get the boolean value style to determinate if we need to use the columns width
+ BooleanValueStyle saveColumnsWidth = (BooleanValueStyle) getTable().getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.SAVE_COLUMNS_WIDTH);
+ if (null == saveColumnsWidth) {
+ final TableConfiguration config = getTable().getTableConfiguration();
+ saveColumnsWidth = (BooleanValueStyle) config.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.SAVE_COLUMNS_WIDTH);
+ }
+
+ // Get the axis with non 'axisWidth' named style (to set the correct percentage)
+ final Set<Integer> notManagedIndexAxisWidth = new HashSet<Integer>();
+ int remainingPercentage = 100;
+
// we go through all the elements to find those which have been modified
for (int index = 0; index < notationColumnsAxisList.size(); index++) {
IAxis currentColumnAxis = notationColumnsAxisList.get(index);
@@ -1590,12 +1675,21 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
if (!getTable().isInvertAxis()) {
int axisWidth = tableBodyLayer.getColumnWidthByPosition(index);
value = (IntValueStyle) currentColumnAxis.getNamedStyle(NattablestylePackage.eINSTANCE.getIntValueStyle(), NamedStyleConstants.AXIS_WIDTH);
- if (value != null) {
- // we set the size of the axis in the graphical representation
- tableBodyLayer.setColumnWidthByPosition(index, value.getIntValue());
- } else if (axisWidth != DefaultSizeUtils.getDefaultCellWidth()) {
+ if (value != null && (null == saveColumnsWidth || (null != saveColumnsWidth && !saveColumnsWidth.isBooleanValue()))) {
+ if (isUsedPercentage) {
+ // Set the percentage with the correct function
+ tableBodyLayer.setColumnWidthPercentageByPosition(index, value.getIntValue());
+ remainingPercentage -= value.getIntValue();
+ } else {
+ // we set the size of the axis in the graphical representation
+ tableBodyLayer.setColumnWidthByPosition(index, value.getIntValue());
+ }
+ } else if (axisWidth != DefaultSizeUtils.getDefaultCellWidth() && !isUsedPercentage) {
// resets the size in case of an undo to the default table
tableBodyLayer.setColumnWidthByPosition(index, DefaultSizeUtils.getDefaultCellWidth());
+ } else if (isUsedPercentage) {
+ // If the columns width are managed with percentage, we need to recalculate it
+ notManagedIndexAxisWidth.add(index);
}
} else {
int axisHeight = tableBodyLayer.getRowHeightByPosition(index);
@@ -1621,19 +1715,36 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
} else {
int axisWidth = tableBodyLayer.getColumnWidthByPosition(index);
value = (IntValueStyle) currentRowAxis.getNamedStyle(NattablestylePackage.eINSTANCE.getIntValueStyle(), NamedStyleConstants.AXIS_WIDTH);
- if (value != null) {
- tableBodyLayer.setColumnWidthByPosition(index, value.getIntValue());
- } else if (axisWidth != DefaultSizeUtils.getDefaultCellWidth()) {
+ if (value != null && (null == saveColumnsWidth || (null != saveColumnsWidth && !saveColumnsWidth.isBooleanValue()))) {
+ if (isUsedPercentage) {
+ tableBodyLayer.setColumnWidthPercentageByPosition(index, value.getIntValue());
+ remainingPercentage -= value.getIntValue();
+ } else {
+ tableBodyLayer.setColumnWidthByPosition(index, value.getIntValue());
+ }
+ } else if (axisWidth != DefaultSizeUtils.getDefaultCellWidth() && !isUsedPercentage) {
tableBodyLayer.setColumnWidthByPosition(index, DefaultSizeUtils.getDefaultCellWidth());
+ } else if (isUsedPercentage) {
+ // If the columns width are managed with percentage, we need to recalculate it
+ notManagedIndexAxisWidth.add(index);
}
}
}
+ // For the axis without 'axisWidth' named style and with the columns width percentage management, set the correct percentage
+ for (int index : notManagedIndexAxisWidth) {
+ tableBodyLayer.setColumnWidthPercentageByPosition(index, Math.round(remainingPercentage / notManagedIndexAxisWidth.size()));
+ }
+
// 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
if (notationRowsAxisList.size() == 0) {
if (getTable().isInvertAxis()) {
for (int index = 0; index < actualColumnAxisElements; index++) {
- tableBodyLayer.setColumnWidthByPosition(index, DefaultSizeUtils.getDefaultCellWidth());
+ if (isUsedPercentage) {
+ tableBodyLayer.setColumnWidthPercentageByPosition(index, 100 / actualColumnAxisElements);
+ } else {
+ tableBodyLayer.setColumnWidthByPosition(index, DefaultSizeUtils.getDefaultCellWidth());
+ }
}
} else if (!getTable().isInvertAxis()) {
@@ -1679,6 +1790,22 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
}
/**
+ * Get the column width as percentage management value.
+ *
+ * @return <code>true</code> if columns width are managed as percentage, <code>false</code> otherwise.
+ * @since 3.0
+ */
+ protected boolean isColumnWidthAsPercentage() {
+ BooleanValueStyle columnsWidthAsPercentage = (BooleanValueStyle) getTable().getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.COLUMNS_WIDTH_AS_PERCENTAGE);
+ if (null == columnsWidthAsPercentage) {
+ final TableConfiguration config = getTable().getTableConfiguration();
+ columnsWidthAsPercentage = (BooleanValueStyle) config.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.COLUMNS_WIDTH_AS_PERCENTAGE);
+ }
+
+ return null != columnsWidthAsPercentage && columnsWidthAsPercentage.isBooleanValue();
+ }
+
+ /**
*
* Handles the initialization of the table's headers resize styles, on opening, based on the previous changes made by the user.
*
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
index fc7ad24bc4c..2e456fff871 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
@@ -9,7 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 476618, 496905
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 476618, 504077, 496905
* Nicolas Boulay (Esterel Technologies SAS) - Bug 497467
* Sebastien Bordes (Esterel Technologies SAS) - Bug 497738
*
@@ -111,6 +111,7 @@ import org.eclipse.papyrus.infra.nattable.sort.PapyrusCompositeGlazedListSortMod
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.CellMapKey;
import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
import org.eclipse.papyrus.infra.nattable.utils.StringComparator;
import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
@@ -766,7 +767,10 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
}
public void resizeAxis() {
- initTableAxis();
+ // If the columns width is managed by percentage, the table axis don't have to be recalculated
+ if (!isColumnWidthAsPercentage()) {
+ initTableAxis();
+ }
refreshNatTable();
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java
index e0339984245..591f82c06f9 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE(ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 504077
*
*****************************************************************************/
@@ -97,7 +98,7 @@ public class NamedStyleConstants {
/**
* key used to save a filter configuration id state when the system use a filter choosen by the user
- * It is only used as name for a {@link StringValueStyle}, we use a specific key in order to not destroyed it when we unapply filter on a column where filter has been definied by the user
+ * It is only used as name for a {@link StringValueStyle}, we use a specific key in order to not destroyed it when we unapply filter on a column where filter has been defined by the user
*
*
*/
@@ -110,6 +111,25 @@ public class NamedStyleConstants {
/**
* This allows to manage the fill columns size to take all the container space.
+ *
+ * @deprecated since 3.0
*/
+ @Deprecated
public static final String FILL_COLUMNS_SIZE = "fillColumnsSize"; //$NON-NLS-1$
+
+ /**
+ * This allows to determinate if the columns width must be managed as percentage.
+ * This named style is not compatible with 'fillColumnsSize'.
+ *
+ * @since 3.0
+ */
+ public static final String COLUMNS_WIDTH_AS_PERCENTAGE = "columnsWidthAsPercentage"; //$NON-NLS-1$
+
+ /**
+ * This allows to determinate if the columns width must be saved or not.
+ * This named style is not compatible with 'fillColumnsSize'.
+ *
+ * @since 3.0
+ */
+ public static final String SAVE_COLUMNS_WIDTH = "saveColumnsWidth"; //$NON-NLS-1$
}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.stereotype.display/config/stereotype.nattableconfiguration b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.stereotype.display/config/stereotype.nattableconfiguration
index 4db16e6b505..dd9636706cd 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.stereotype.display/config/stereotype.nattableconfiguration
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.stereotype.display/config/stereotype.nattableconfiguration
@@ -36,19 +36,19 @@
</columnHeaderAxisConfiguration>
<columnAxisProviders xsi:type="nattableaxisprovider:SlaveObjectAxisProvider" description="This axis provider provides available columns according to the columns of the table ( features of the object displayed on the other axis)" name="Stereotype display properties axis provider">
<axis xsi:type="nattableaxis:FeatureIdAxis" manager="//@columnHeaderAxisConfiguration/@axisManagers.0" alias="Name Depth" element="stereotype_display_properties:/nameDepth">
- <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="100"/>
+ <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="17"/>
</axis>
<axis xsi:type="nattableaxis:FeatureIdAxis" manager="//@columnHeaderAxisConfiguration/@axisManagers.0" alias="Visible" element="stereotype_display_properties:/isDisplayed">
- <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="100"/>
+ <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="17"/>
</axis>
<axis xsi:type="nattableaxis:FeatureIdAxis" manager="//@columnHeaderAxisConfiguration/@axisManagers.0" alias="In Braces" element="stereotype_display_properties:/isDisplayedInBraces">
- <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="120"/>
+ <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="22"/>
</axis>
<axis xsi:type="nattableaxis:FeatureIdAxis" manager="//@columnHeaderAxisConfiguration/@axisManagers.0" alias="In Comment" element="stereotype_display_properties:/isDisplayedInComment">
- <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="120"/>
+ <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="22"/>
</axis>
<axis xsi:type="nattableaxis:FeatureIdAxis" manager="//@columnHeaderAxisConfiguration/@axisManagers.0" alias="In Compartment" element="stereotype_display_properties:/isDisplayedInCompartment">
- <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="120"/>
+ <styles xsi:type="nattablestyle:IntValueStyle" name="axisWidth" intValue="22"/>
</axis>
</columnAxisProviders>
<rowAxisProviders xsi:type="nattableaxisprovider:MasterObjectAxisProvider" description="This axis provider manages the rows, according to the wanted hierarchy" name="HierarchicalRowAxisManager" disconnectSlave="true"/>
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/NattablePropertyEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/NattablePropertyEditor.java
index c295596b64e..c50c3c189be 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/NattablePropertyEditor.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/NattablePropertyEditor.java
@@ -788,13 +788,19 @@ public class NattablePropertyEditor extends AbstractPropertyEditor {
}
// for the table displayed in property view, we want to use all the available place, so we add a specific named style each time
- BooleanValueStyle fillStyle = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.FILL_COLUMNS_SIZE);
+ // We manage it with percentage named style
+ BooleanValueStyle columnsWidthAsPercentage = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.COLUMNS_WIDTH_AS_PERCENTAGE);
// if the name style already exists we do nothing
- if (null == fillStyle) {
- fillStyle = NattablestyleFactory.eINSTANCE.createBooleanValueStyle();
- fillStyle.setName(NamedStyleConstants.FILL_COLUMNS_SIZE);
- fillStyle.setBooleanValue(true);
- table.getStyles().add(fillStyle);
+ if (null == columnsWidthAsPercentage) {
+ // for the table displayed in property view, we want to use all the available place, so we add a specific named style each time
+ BooleanValueStyle fillStyle = (BooleanValueStyle) table.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.FILL_COLUMNS_SIZE);
+ // if the name style already exists we do nothing
+ if (null == fillStyle) {
+ columnsWidthAsPercentage = NattablestyleFactory.eINSTANCE.createBooleanValueStyle();
+ columnsWidthAsPercentage.setName(NamedStyleConstants.COLUMNS_WIDTH_AS_PERCENTAGE);
+ columnsWidthAsPercentage.setBooleanValue(true);
+ table.getStyles().add(columnsWidthAsPercentage);
+ }
}
// for the table displayed in property view, we expand all directly

Back to the top