Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanh Liem PHAN2017-11-29 16:51:01 +0000
committervincent lorenzo2017-12-13 11:08:22 +0000
commitff69ce6e3bb99fc8a277cae689117ee23179dd77 (patch)
treeadfb4ee229fcae56b806fa09e6de1ebbb7bcda8b
parenta08aefe458f053a7783d4c57ac44e4673ceb35ce (diff)
downloadorg.eclipse.papyrus-ff69ce6e3bb99fc8a277cae689117ee23179dd77.tar.gz
org.eclipse.papyrus-ff69ce6e3bb99fc8a277cae689117ee23179dd77.tar.xz
org.eclipse.papyrus-ff69ce6e3bb99fc8a277cae689117ee23179dd77.zip
Bug 527733: [Rich Text] autoResizeCellHeight and wrapText did not work
with Rich Text editor https://bugs.eclipse.org/bugs/show_bug.cgi?id=527733 - Create a custom RichTextCellPainter for Papyrus Change-Id: I0a7e9bfd8f8356447d52b251379b31cd205e5dbf Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/config/RichTextCellEditorConfiguration.java25
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/cellpainter/PapyrusRichTextCellPainter.java77
2 files changed, 99 insertions, 3 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/config/RichTextCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/config/RichTextCellEditorConfiguration.java
index c632f6b2fd1..4103bb8001c 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/config/RichTextCellEditorConfiguration.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/config/RichTextCellEditorConfiguration.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2017 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
@@ -9,6 +9,7 @@
* Contributors:
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 527733
*****************************************************************************/
package org.eclipse.papyrus.uml.nattable.richtext.celleditor.config;
@@ -19,18 +20,22 @@ import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
-import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.papyrus.infra.emf.nattable.celleditor.config.SingleStringCellEditorConfiguration;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
import org.eclipse.papyrus.infra.ui.Activator;
import org.eclipse.papyrus.infra.ui.preferences.RichtextPreferencePage;
import org.eclipse.papyrus.uml.nattable.richtext.celleditor.RichTextCellEditorWithUMLReferences;
import org.eclipse.papyrus.uml.nattable.richtext.celleditor.config.messages.Messages;
+import org.eclipse.papyrus.uml.nattable.richtext.cellpainter.PapyrusRichTextCellPainter;
import org.eclipse.uml2.uml.UMLPackage;
/**
@@ -113,7 +118,21 @@ public class RichTextCellEditorConfiguration extends SingleStringCellEditorConfi
protected ICellPainter getCellPainter(final IConfigRegistry configRegistry, final Object axis, final String configLabel) {
final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
if (store.getBoolean(RichtextPreferencePage.USE_HTML_RENDERER)) {
- return new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2, 5, 2, 5));
+ final INattableModelManager nattableManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ // If nattable model could be retrieved
+ if (null != nattableManager && null != nattableManager.getTable()) {
+ final Table table = nattableManager.getTable();
+
+ // Get wraptext and auto resize cell height boolean value from the table
+ final boolean wrapTextFlag = StyleUtils.getBooleanNamedStyleValue(table, NamedStyleConstants.WRAP_TEXT);
+ final boolean autoResizeCellHeightFlag = StyleUtils.getBooleanNamedStyleValue(table, NamedStyleConstants.AUTO_RESIZE_CELL_HEIGHT);
+
+ // Then create the richtext cell painter with these values as parameters
+ return new BackgroundPainter(new PaddingDecorator(new PapyrusRichTextCellPainter(wrapTextFlag, false, autoResizeCellHeightFlag), 2, 5, 2, 5));
+ } else {
+ // Otherwise, create the richtext cell painter without parameters
+ return new BackgroundPainter(new PaddingDecorator(new PapyrusRichTextCellPainter(), 2, 5, 2, 5));
+ }
}
return super.getCellPainter(configRegistry, axis, configLabel);
}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/cellpainter/PapyrusRichTextCellPainter.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/cellpainter/PapyrusRichTextCellPainter.java
new file mode 100644
index 00000000000..15f6909acf8
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/cellpainter/PapyrusRichTextCellPainter.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2017 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:
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 527733
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.richtext.cellpainter;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellPainter;
+import org.eclipse.nebula.widgets.nattable.layer.cell.CellDisplayConversionUtils;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleUtil;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.NamedStyleConstants;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * A custom {@link RichTextCellPainter} used in Papyrus.
+ */
+public class PapyrusRichTextCellPainter extends RichTextCellPainter {
+
+ /**
+ * Create a new {@link PapyrusRichTextCellPainter} with text wrapping enabled and auto-resizing disabled.
+ */
+ public PapyrusRichTextCellPainter() {
+ super(true, false, false);
+ }
+
+ /**
+ * Create a new {@link PapyrusRichTextCellPainter}.
+ *
+ * @param wrapText
+ * <code>true</code> to enable text wrapping
+ * @param calculateByTextLength
+ * <code>true</code> to configure the text painter to calculate the cell border by containing text length
+ * @param calculateByTextHeight
+ * <code>true</code> to configure the text painter to calculate the cell border by containing text height
+ */
+ public PapyrusRichTextCellPainter(final boolean wrapText, final boolean calculateByTextLength, final boolean calculateByTextHeight) {
+ super(wrapText, calculateByTextLength, calculateByTextHeight);
+ }
+
+ /**
+ * <pre>
+ * {@inheritDoc}
+ *
+ * Overridden to pre-calculate with the wrap text parameter from the nattable model retrieved from the input config registry.
+ * </pre>
+ */
+ @Override
+ public int getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) {
+ setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry));
+ String htmlText = CellDisplayConversionUtils.convertDataType(cell, configRegistry);
+
+ final INattableModelManager nattableManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+
+ boolean calculateWithWrapping = true;
+
+ if (null != nattableManager && null != nattableManager.getTable()) {
+ calculateWithWrapping = StyleUtils.getBooleanNamedStyleValue(nattableManager.getTable(), NamedStyleConstants.WRAP_TEXT);
+ }
+
+ this.richTextPainter.preCalculate(htmlText, gc, new Rectangle(0, 0, cell.getBounds().width, 0), calculateWithWrapping);
+ return this.richTextPainter.getPreferredSize().y - 2 * this.richTextPainter.getParagraphSpace();
+ }
+}

Back to the top