diff options
| author | Dirk Fauth | 2023-01-09 07:38:39 +0000 |
|---|---|---|
| committer | Dirk Fauth | 2023-01-09 07:38:39 +0000 |
| commit | ca3b345bb62c68ac60dced75378f6411013d4ad5 (patch) | |
| tree | 3f7456861ba2f8009023cb2dfc4696edb8458209 | |
| parent | b0fb9a9e99b946c675c536132034aedb6d1a06d3 (diff) | |
| download | org.eclipse.nebula.widgets.nattable-ca3b345bb62c68ac60dced75378f6411013d4ad5.tar.gz org.eclipse.nebula.widgets.nattable-ca3b345bb62c68ac60dced75378f6411013d4ad5.tar.xz org.eclipse.nebula.widgets.nattable-ca3b345bb62c68ac60dced75378f6411013d4ad5.zip | |
Bug 581300 - [RichTextCellPainter] allow configuration of data and
markup converter
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
Change-Id: I5db49a271a86ab48e14dde7224e596b98091e705
3 files changed, 73 insertions, 15 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_400_Configuration/_424_NebulaRichTextIntegrationExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_400_Configuration/_424_NebulaRichTextIntegrationExample.java index be1c8e40..ab9f57fc 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_400_Configuration/_424_NebulaRichTextIntegrationExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_400_Configuration/_424_NebulaRichTextIntegrationExample.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015, 2020 CEA LIST. + * Copyright (c) 2015, 2023 CEA LIST. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -29,7 +29,6 @@ import org.eclipse.nebula.widgets.nattable.data.IDataProvider; import org.eclipse.nebula.widgets.nattable.data.ListDataProvider; import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor; import org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter; -import org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter; import org.eclipse.nebula.widgets.nattable.dataset.person.Person; import org.eclipse.nebula.widgets.nattable.dataset.person.PersonService; import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; @@ -39,6 +38,7 @@ import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleR import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.MarkupDisplayConverter; import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellEditor; import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellPainter; +import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextConfigAttributes; import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider; import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer; import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer; @@ -116,19 +116,12 @@ public class _424_NebulaRichTextIntegrationExample extends AbstractNatExample { "<span style=\"background-color:rgb(255, 0, 0)\"><strong><s><u>", "</u></s></strong></span>"); - // register markup display converter for normal displaymode + // register markup display converter configRegistry.registerConfigAttribute( - CellConfigAttributes.DISPLAY_CONVERTER, + RichTextConfigAttributes.MARKUP_DISPLAY_CONVERTER, markupConverter, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1); - // register default display converter for editing, so there is - // no markup in the editor - configRegistry.registerConfigAttribute( - CellConfigAttributes.DISPLAY_CONVERTER, - new DefaultDisplayConverter(), - DisplayMode.EDIT, - ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 1); configRegistry.registerConfigAttribute( CellConfigAttributes.DISPLAY_CONVERTER, diff --git a/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextCellPainter.java b/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextCellPainter.java index ae9f82d0..cc68c4c2 100644 --- a/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextCellPainter.java +++ b/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextCellPainter.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015, 2020 CEA LIST. + * Copyright (c) 2015, 2023 CEA LIST. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,7 @@ package org.eclipse.nebula.widgets.nattable.extension.nebula.richtext; import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; +import org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter; import org.eclipse.nebula.widgets.nattable.layer.cell.CellDisplayConversionUtils; import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; import org.eclipse.nebula.widgets.nattable.painter.cell.AbstractCellPainter; @@ -109,7 +110,7 @@ public class RichTextCellPainter extends AbstractCellPainter { IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); - String htmlText = CellDisplayConversionUtils.convertDataType(cell, configRegistry); + String htmlText = getHtmlText(cell, configRegistry); Rectangle painterBounds = new Rectangle(bounds.x, bounds.y - this.richTextPainter.getParagraphSpace(), bounds.width, bounds.height); this.richTextPainter.paintHTML(htmlText, gc, painterBounds); @@ -135,7 +136,7 @@ public class RichTextCellPainter extends AbstractCellPainter { @Override public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) { setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry)); - String htmlText = CellDisplayConversionUtils.convertDataType(cell, configRegistry); + String htmlText = getHtmlText(cell, configRegistry); // using a zero size rectangle for calculation results in a content // related preferred size @@ -146,7 +147,7 @@ public class RichTextCellPainter extends AbstractCellPainter { @Override public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) { setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry)); - String htmlText = CellDisplayConversionUtils.convertDataType(cell, configRegistry); + String htmlText = getHtmlText(cell, configRegistry); // using a zero size rectangle for calculation results in a content // related preferred size @@ -255,4 +256,30 @@ public class RichTextCellPainter extends AbstractCellPainter { this.calculateByTextHeight = calculateByTextHeight; } + /** + * Returns the HTML text for the data that should be shown in the given + * {@link ILayerCell}. + * + * @param cell + * The cell for which the data should be shown. + * @param configRegistry + * The {@link IConfigRegistry} to retrieve the configurations + * like e.g. the {@link IDisplayConverter}. + * @return The data to be shown in the cell as HTML text. + * @since 2.1 + */ + protected String getHtmlText(ILayerCell cell, IConfigRegistry configRegistry) { + Object displayValue = CellDisplayConversionUtils.convertDataType(cell, configRegistry); + + IDisplayConverter markupDisplayConverter = configRegistry.getConfigAttribute( + RichTextConfigAttributes.MARKUP_DISPLAY_CONVERTER, + cell.getDisplayMode(), + cell.getConfigLabels()); + + if (markupDisplayConverter != null) { + displayValue = markupDisplayConverter.canonicalToDisplayValue(cell, configRegistry, displayValue); + } + + return String.valueOf(displayValue); + } } diff --git a/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextConfigAttributes.java b/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextConfigAttributes.java new file mode 100644 index 00000000..cf2e3e6d --- /dev/null +++ b/org.eclipse.nebula.widgets.nattable.extension.nebula/src/org/eclipse/nebula/widgets/nattable/extension/nebula/richtext/RichTextConfigAttributes.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2023 Original authors and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Original authors and others - initial API and implementation + ******************************************************************************/ +package org.eclipse.nebula.widgets.nattable.extension.nebula.richtext; + +import org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter; +import org.eclipse.nebula.widgets.nattable.style.ConfigAttribute; + +/** + * {@link ConfigAttribute}s specifically for configuring the + * {@link RichTextCellPainter}. + * + * @since 2.1 + */ +public final class RichTextConfigAttributes { + + private RichTextConfigAttributes() { + // private default constructor for constants class + } + + /** + * Attribute for configuring the markup IDisplayConverter that should be + * used to convert the data in a cell for HTML rendering. + * + * @since 2.1 + */ + public static final ConfigAttribute<IDisplayConverter> MARKUP_DISPLAY_CONVERTER = new ConfigAttribute<>(); + +} |
