Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-04-27 08:07:39 +0000
committerGerrit Code Review @ Eclipse.org2016-04-28 15:44:11 +0000
commit0ec28fa6dce52335f9154e8920ae4305def34ec0 (patch)
tree24dce4952530b4c083718d1f33e8549d6c426b21
parent5449ae4aa9434f5159e377161754cdd45b7686be (diff)
downloadorg.eclipse.papyrus-0ec28fa6dce52335f9154e8920ae4305def34ec0.tar.gz
org.eclipse.papyrus-0ec28fa6dce52335f9154e8920ae4305def34ec0.tar.xz
org.eclipse.papyrus-0ec28fa6dce52335f9154e8920ae4305def34ec0.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 the fill columns size by named style. JUnit tests will be created later. Change-Id: I2005539ff05eec48959d6e4bf3e3d543c352dc6e 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.java53
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java13
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NamedStyleConstants.java5
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/NattablePropertyEditor.java27
4 files changed, 85 insertions, 13 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 aa08930346a..c3a1f180e49 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
@@ -117,6 +117,7 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfigurati
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.LocalTableHeaderAxisConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationPackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TableHeaderAxisConfiguration;
+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.NamedStyle;
@@ -401,6 +402,9 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
initTableHeaders();
initTableMerge();
+ // Fill the columns size
+ doFillColumnsSize();
+
addColumnReorderListener(this.bodyLayerStack.getColumnReorderLayer());
addAxisResizeListener(this.bodyLayerStack);
addColumnHeaderResizeListener(getColumnHeaderLayerStack());
@@ -637,7 +641,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
protected DecorationService getDecorationService() {
// Bug 490067: We need to check if the resource of the context is existing before to get the decoration service (to avoid useless log exception)
// The resource of the context is not existing in the case of deletion (EObject was already deleted but the reference of table always exists)
- if(null != this.table.getContext().eResource()){
+ if (null != this.table.getContext().eResource()) {
try {
ServicesRegistry serviceRegistry = ServiceUtilsForEObject.getInstance().getServiceRegistry(this.table.getContext());// get context and NOT get table for the usecase where the table is not in a resource
return serviceRegistry.getService(DecorationService.class);
@@ -1151,10 +1155,10 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
}
- if (resizeRowHeaderCommand.canExecute() && !resizeRowHeaderCommand.isEmpty()
- // If the local row header axis is created, check that this is not the single command to execute
- // because we need to manage the named style with this command
- && ((!isLocalRowHeaderAxisCreation) || (isLocalRowHeaderAxisCreation && 1 < resizeRowHeaderCommand.size()))) {
+ if (resizeRowHeaderCommand.canExecute() && !resizeRowHeaderCommand.isEmpty()
+ // If the local row header axis is created, check that this is not the single command to execute
+ // because we need to manage the named style with this command
+ && ((!isLocalRowHeaderAxisCreation) || (isLocalRowHeaderAxisCreation && 1 < resizeRowHeaderCommand.size()))) {
tableDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(resizeRowHeaderCommand));
}
}
@@ -1473,6 +1477,45 @@ 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.
+ */
+ protected void doFillColumnsSize() {
+
+ final TableConfiguration config = getTable().getTableConfiguration();
+ final BooleanValueStyle fillColumnsSize = (BooleanValueStyle) config.getNamedStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle(), NamedStyleConstants.FILL_COLUMNS_SIZE);
+ if (null != fillColumnsSize) {
+ if (fillColumnsSize.isBooleanValue()) {
+ final Composite parent = natTable.getParent();
+
+ if (null != parent && !parent.isDisposed()) {
+ final int parentSize = parent.getSize().x;
+
+ // Calculate the rows header width
+ int headerWidth = 0;
+ if (null != getRowHeaderLayerStack()) {
+ if (null != getRowHeaderLayerStack().getIndexRowHeaderLayer()) {
+ headerWidth = getRowHeaderLayerStack().getIndexRowHeaderLayer().getWidth();
+ }
+ 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();
+
+ // 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/manager/table/NattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
index d469d6ee4c3..9aa999b82e6 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
@@ -351,7 +351,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
};
}
-
+
private ListEventListener<Object> listEventListener;
/**
@@ -710,7 +710,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
final SortedList<Object> newHorizontalSortedList = this.rowSortedList;
final SortedList<Object> newVerticalSortedList = this.columnSortedList;
-
+
final FilterList<Object> newVerticalFilterLilst = this.horizontalFilterList;
final FilterList<Object> newHorizontalFilterList = this.verticalFilterList;
@@ -817,7 +817,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
if (this.decoractionServiceObserver != null) {
// Bug 490067: Check if the decoration service is available to avoid null pointer
final DecorationService decorationService = getDecorationService();
- if(null != decorationService) {
+ if (null != decorationService) {
decorationService.deleteListener(this.decoractionServiceObserver);
}
this.decoractionServiceObserver = null;
@@ -857,7 +857,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
table.eAdapters().remove(this.invertAxisListener);
}
}
-
+
if (this.cellsMap != null) {
this.cellsMap.clear();
}
@@ -1087,6 +1087,9 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
selectionLayer.doCommand(new ClearAllSelectionsCommand());
this.natTable.refresh();
+ // Refresh the nattable columns size in the case of named style
+ doFillColumnsSize();
+
// Keep the selection after the refresh of the table
if (null != selectedCells && !selectedCells.isEmpty()) {
Collection<Integer> selectedColumns = new ArrayList<Integer>();
@@ -2019,7 +2022,7 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
*/
@Override
public void setDataValue(final Object rowObject, final int columnIndex, final Object newValue) {
- //nothing to do
+ // nothing to do
}
/**
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 c8fb014aa96..e0339984245 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
@@ -107,4 +107,9 @@ public class NamedStyleConstants {
* This is for boolean value style {@link BooleanValueStyle}. This is used to expand all the rows in a tree table during the opening of the table.
*/
public static final String EXPAND_ALL = "expandAll"; //$NON-NLS-1$
+
+ /**
+ * This allows to manage the fill columns size to take all the container space.
+ */
+ public static final String FILL_COLUMNS_SIZE = "fillColumnsSize"; //$NON-NLS-1$
}
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 8ad00736b26..45cf7dd85a1 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
@@ -31,6 +31,7 @@ import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.papyrus.infra.emf.nattable.selection.EObjectSelectionExtractor;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager;
import org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.NattableFactory;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
@@ -42,10 +43,13 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfigurati
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderFactory;
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.NattablestylePackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.Style;
import org.eclipse.papyrus.infra.nattable.tree.CollapseAndExpandActionsEnum;
import org.eclipse.papyrus.infra.nattable.tree.ITreeItemAxisHelper;
import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
import org.eclipse.papyrus.infra.nattable.utils.NattableModelManagerFactory;
import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
import org.eclipse.papyrus.infra.properties.contexts.Property;
@@ -61,6 +65,8 @@ import org.eclipse.papyrus.uml.properties.modelelement.UMLNotationModelElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
@@ -210,7 +216,7 @@ public class NattablePropertyEditor extends AbstractPropertyEditor {
* @param sourceElement
* The source Element.
* @param feature
- * The feature.
+ * The parent structural feature.
* @param rows
* The rows of the table.
*/
@@ -222,7 +228,9 @@ public class NattablePropertyEditor extends AbstractPropertyEditor {
displayError("Cannot initialize the table"); //$NON-NLS-1$
return;
}
-
+
+ manageTableNamedStyle(table);
+
// Create the widget
nattableManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(table, new EObjectSelectionExtractor());
natTableWidget = nattableManager.createNattable(self, SWT.NONE, null);
@@ -231,15 +239,28 @@ public class NattablePropertyEditor extends AbstractPropertyEditor {
((TreeNattableModelManager) nattableManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null);
}
-
+
self.addDisposeListener(getDisposeListener());
natTableWidget.setBackground(self.getBackground());
// Configure the layout and the layout data
configureLayout();
+
+ ((NattableModelManager)nattableManager).refreshNatTable();
}
/**
+ * This allows to add some named style to the table.
+ *
+ * @param table The current table.
+ */
+ protected void manageTableNamedStyle(final Table table){
+ final Style fillColumnsSizeStyle = table.getTableConfiguration().createStyle(NattablestylePackage.eINSTANCE.getBooleanValueStyle());
+ ((BooleanValueStyle)fillColumnsSizeStyle).setName(NamedStyleConstants.FILL_COLUMNS_SIZE);
+ ((BooleanValueStyle)fillColumnsSizeStyle).setBooleanValue(true);
+ }
+
+ /**
* This allows to configure the tree table.
*
* @param nattableManager

Back to the top