Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2020-03-24 14:14:16 +0000
committerVincent Lorenzo2020-05-15 12:54:50 +0000
commit1a3305aa62de658f5a3dee738e7d92e666cf1237 (patch)
tree29a25f0bec4d25d65cf7f69fe68d3b19117e46ff
parent541ef46d6ac8285c707fcf22c5f08480d72e65c6 (diff)
downloadorg.eclipse.papyrus-master.tar.gz
org.eclipse.papyrus-master.tar.xz
org.eclipse.papyrus-master.zip
Bug 561411: [Table] The background color of cells in the body don't well alternateHEADmaster
Change-Id: I81cb419921632c83658865cab794054298b4432a Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusAlternateRowConfigLabelAccumulatorForRegion.java133
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusGridLayerConfiguration.java41
2 files changed, 170 insertions, 4 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusAlternateRowConfigLabelAccumulatorForRegion.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusAlternateRowConfigLabelAccumulatorForRegion.java
new file mode 100755
index 00000000000..7a93110771c
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusAlternateRowConfigLabelAccumulatorForRegion.java
@@ -0,0 +1,133 @@
+/*****************************************************************************
+ * Copyright (c) 2020 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.configuration;
+
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator;
+import org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.papyrus.infra.nattable.layerstack.BodyLayerStack;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+
+/**
+ * Custom configuration to get the expected row background color, according to the ShowHideLayer
+ * This class is in visibility package, because the API (method setConfigRegistry) is not satisifaying.
+ *
+ * @since 6.7
+ */
+final class PapyrusAlternateRowConfigLabelAccumulatorForRegion extends AlternatingRowConfigLabelAccumulator {
+ /**
+ * TODO : ask to NatTable to open its API
+ * the configured layer
+ */
+ private final ILayer layer;
+
+ /**
+ * The config registry for the current table
+ */
+ private IConfigRegistry configRegistry;
+
+ /**
+ * Constructor.
+ *
+ * @param layer
+ * the configured label
+ */
+ public PapyrusAlternateRowConfigLabelAccumulatorForRegion(final ILayer layer) {
+ super(layer);
+ this.layer = layer;
+ }
+
+ /**
+ *
+ * This method allows to set the {@link IConfigRegistry} to use to get the current edited NatTable widget
+ *
+ * @param configRegistry
+ * the config registry
+ */
+ void setConfigRegistry(final IConfigRegistry configRegistry) {
+ this.configRegistry = configRegistry;
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator#accumulateConfigLabels(org.eclipse.nebula.widgets.nattable.layer.LabelStack, int, int)
+ *
+ * @param configLabels
+ * @param columnPosition
+ * @param rowPosition
+ */
+ @Override
+ public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
+ final BodyLayerStack layerStack = getBodyLayerStack();
+ final NatTable natTable = getNatTable();
+ if (layerStack != null && natTable != null) {
+ final RowHideShowLayer rowHideShowLayer = layerStack.getRowHideShowLayer();
+ // refind the initial row index
+ int rowIndex = this.layer.getRowIndexByPosition(rowPosition);
+ int realRowPosition = rowHideShowLayer.underlyingToLocalRowPosition(natTable, rowIndex);
+
+ configLabels.addLabel((realRowPosition % 2 == 0 ? EVEN_ROW_CONFIG_TYPE : ODD_ROW_CONFIG_TYPE));
+
+ }
+ super.accumulateConfigLabels(configLabels, columnPosition, rowPosition);
+ }
+
+ /**
+ *
+ * @return
+ * the natTable widget, or <code>null</code> (if not found or disposed)
+ */
+ private NatTable getNatTable() {
+ final INattableModelManager manager = getNattableModelManager();
+ if (manager == null) {
+ return null;
+ }
+ final NatTable natTable = manager.getAdapter(NatTable.class);
+ if (natTable.isDisposed()) {
+ return null;
+ }
+ return natTable;
+ }
+
+ /**
+ *
+ * @return
+ * the {@link INattableModelManager} for which we are configuring the row color, or <code>null</code>
+ */
+ private INattableModelManager getNattableModelManager() {
+ if (this.configRegistry == null) {
+ return null;
+ }
+ return this.configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ }
+
+ /**
+ *
+ * @return
+ * the {@link BodyLayerStack} used by the table, or <code>null</code>
+ */
+ private BodyLayerStack getBodyLayerStack() {
+ final INattableModelManager manager = getNattableModelManager();
+ if (manager == null) {
+ return null;
+ }
+ return manager.getBodyLayerStack();
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusGridLayerConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusGridLayerConfiguration.java
index 7218b4d82db..bc8f875d73e 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusGridLayerConfiguration.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusGridLayerConfiguration.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2017 CEA LIST.
+ * Copyright (c) 2013, 2017, 2020 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,10 +11,14 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 417095, 515737
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 561411
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.configuration;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultGridLayerConfiguration;
+import org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultRowStyleConfiguration;
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
import org.eclipse.papyrus.infra.nattable.applynamedstyle.PapyrusApplyNamedStyleBindings;
import org.eclipse.papyrus.infra.nattable.export.PapyrusExportBindings;
@@ -23,13 +27,15 @@ import org.eclipse.papyrus.infra.nattable.internal.export.image.PapyrusImageExpo
/**
* We change the edit configuration
- *
- * @author Vincent Lorenzo
- *
*/
public class PapyrusGridLayerConfiguration extends DefaultGridLayerConfiguration {
/**
+ * The configuration to use to get a color for odd row and a color for even row
+ */
+ private PapyrusAlternateRowConfigLabelAccumulatorForRegion alternateRowConfiguration;
+
+ /**
*
* Constructor.
*
@@ -83,6 +89,7 @@ public class PapyrusGridLayerConfiguration extends DefaultGridLayerConfiguration
/**
* Add the image export binding.
+ *
* @since 3.0
*/
protected void addImageExportUIBindings() {
@@ -97,4 +104,30 @@ public class PapyrusGridLayerConfiguration extends DefaultGridLayerConfiguration
protected void addApplyNamedStyleBindings() {
addConfiguration(new PapyrusApplyNamedStyleBindings());
}
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.config.AggregateConfiguration#configureRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param configRegistry
+ */
+ @Override
+ public void configureRegistry(final IConfigRegistry configRegistry) {
+ if (this.alternateRowConfiguration != null) {
+ this.alternateRowConfiguration.setConfigRegistry(configRegistry);
+ }
+ super.configureRegistry(configRegistry);
+ }
+
+ /**
+ * @see org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultGridLayerConfiguration#addAlternateRowColoringConfig(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)
+ *
+ * @param gridLayer
+ */
+ @Override
+ protected void addAlternateRowColoringConfig(final CompositeLayer layer) {
+ addConfiguration(new DefaultRowStyleConfiguration());
+ this.alternateRowConfiguration = new PapyrusAlternateRowConfigLabelAccumulatorForRegion(layer
+ .getChildLayerByRegionName(GridRegion.BODY));
+ layer.setConfigLabelAccumulatorForRegion(GridRegion.BODY, this.alternateRowConfiguration);
+ }
}

Back to the top