Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanh Liem PHAN2017-04-27 09:58:23 +0000
committervincent lorenzo2017-05-16 09:02:08 +0000
commit762b2bcf00d750487f88221fa6cdd508e9544d5f (patch)
tree9e320f798d0456da52eca20fe6220b4dc57b31ae
parentdda713e66ea56e0bd94a60cefdae72b8e287a18b (diff)
downloadorg.eclipse.papyrus-762b2bcf00d750487f88221fa6cdd508e9544d5f.tar.gz
org.eclipse.papyrus-762b2bcf00d750487f88221fa6cdd508e9544d5f.tar.xz
org.eclipse.papyrus-762b2bcf00d750487f88221fa6cdd508e9544d5f.zip
Bug 515735: [Table] Bad display in row header in some case
https://bugs.eclipse.org/bugs/show_bug.cgi?id=515735 - Remove the redundant draw text command Change-Id: I196fcf616e90648276bd17a3ad98ea89fdce92ac Signed-off-by: Thanh Liem PHAN <thanhliem.phan@all4tec.net>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CustomizedCellPainter.java248
1 files changed, 121 insertions, 127 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CustomizedCellPainter.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CustomizedCellPainter.java
index a78c774e66a..c3f3536360f 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CustomizedCellPainter.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CustomizedCellPainter.java
@@ -1,127 +1,121 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Override of the paintCell() method
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.painter;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
-import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
-import org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand;
-import org.eclipse.nebula.widgets.nattable.style.CellStyleUtil;
-import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
-import org.eclipse.nebula.widgets.nattable.style.IStyle;
-import org.eclipse.papyrus.infra.nattable.utils.Constants;
-import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper;
-import org.eclipse.papyrus.infra.nattable.utils.LabelProviderCellContextElementWrapper;
-import org.eclipse.papyrus.infra.nattable.utils.LabelProviderContextElementWrapper;
-import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
-import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * Custom CellPainter to define the LabelProvider to use
- *
- * @author Vincent Lorenzo
- *
- */
-// TODO : we should use the TextPainter itself, now with the GenericDisplayConverter, it should works fine
-public class CustomizedCellPainter extends CellPainterWithUnderlinedError {
-
- private LabelProviderCellContextElementWrapper contextElement = new LabelProviderCellContextElementWrapper();
- /**
- *
- * Constructor. We're overriding it to always set word-wrapping for our cells.
- *
- */
- public CustomizedCellPainter() {
- super(false, true);// with (true,true), automatic newLine when the text is too long to be displayed.
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter#convertDataType(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
- *
- * @param cell
- * @param configRegistry
- * @return
- */
- @Override
- protected String convertDataType(final ILayerCell cell, final IConfigRegistry configRegistry) {
- final LabelProviderService serv = configRegistry.getConfigAttribute(NattableConfigAttributes.LABEL_PROVIDER_SERVICE_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.LABEL_PROVIDER_SERVICE_ID);
- contextElement.setConfigRegistry(configRegistry);
- contextElement.setObject(cell.getDataValue());
- contextElement.setCell(cell);
- final ILabelProvider provider = serv.getLabelProvider(Constants.TABLE_LABEL_PROVIDER_CONTEXT, contextElement);
- String str = provider.getText(contextElement);
- if (str == null) {
- str = ""; //$NON-NLS-1$
- }
- return str;
- }
-
- /**
- * Overridden to show, additionally to the contents of a cell, a vertical arrow pointing down in case there are masked lines
- *
- * @see org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter#paintCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle,
- * org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
- *
- * @param cell
- * @param gc
- * @param rectangle
- * @param configRegistry
- */
- @Override
- public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
- super.paintCell(cell, gc, rectangle, configRegistry);
- IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
- int fontHeight = gc.getFontMetrics().getHeight();
- String text = convertDataType(cell, configRegistry);
- text = getTextToDisplay(cell, gc, rectangle.width, text);
-
- int numberOfNewLines = getNumberOfNewLines(text);
- // we're extending the row height (only if word wrapping is enabled)
- int contentHeight = (fontHeight * numberOfNewLines) + (spacing * 2);
- int contentToCellDiff = (cell.getBounds().height - rectangle.height);
-
- if (performRowResize(contentHeight, rectangle)) {
- ILayer layer = cell.getLayer();
- layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff));
- }
- if (numberOfNewLines > 1) {
-
- int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight);
- String[] lines = text.split("\n"); //$NON-NLS-1$
- for (String line : lines) {
- int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width);
-
- Image im = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.infra.nattable", "/icons/arrow_down_end.png"); //$NON-NLS-1$ //$NON-NLS-2$
- gc.drawText(line, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + spacing, yStartPos + spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
-
- // We test if, given the current cell size and text position, we should display the down pointing arrow.
- if (contentHeight > rectangle.height && yStartPos + fontHeight > rectangle.height + rectangle.y) {
- int yDownRowIcon = rectangle.y + rectangle.height - im.getBounds().height;
- int xDownRowIcon = rectangle.x + rectangle.width - im.getBounds().width;
- gc.drawImage(im, xDownRowIcon, yDownRowIcon);
- }
-
- // after every line calculate the y start pos new
- yStartPos += fontHeight;
- }
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2017 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Override of the paintCell() method
+ * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515735
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.painter;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleUtil;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.nebula.widgets.nattable.style.IStyle;
+import org.eclipse.papyrus.infra.nattable.utils.Constants;
+import org.eclipse.papyrus.infra.nattable.utils.LabelProviderCellContextElementWrapper;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * Custom CellPainter to define the LabelProvider to use
+ *
+ * @author Vincent Lorenzo
+ *
+ */
+// TODO : we should use the TextPainter itself, now with the GenericDisplayConverter, it should works fine
+public class CustomizedCellPainter extends CellPainterWithUnderlinedError {
+
+ private LabelProviderCellContextElementWrapper contextElement = new LabelProviderCellContextElementWrapper();
+ /**
+ *
+ * Constructor. We're overriding it to always set word-wrapping for our cells.
+ *
+ */
+ public CustomizedCellPainter() {
+ super(false, true);// with (true,true), automatic newLine when the text is too long to be displayed.
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter#convertDataType(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param cell
+ * @param configRegistry
+ * @return
+ */
+ @Override
+ protected String convertDataType(final ILayerCell cell, final IConfigRegistry configRegistry) {
+ final LabelProviderService serv = configRegistry.getConfigAttribute(NattableConfigAttributes.LABEL_PROVIDER_SERVICE_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.LABEL_PROVIDER_SERVICE_ID);
+ contextElement.setConfigRegistry(configRegistry);
+ contextElement.setObject(cell.getDataValue());
+ contextElement.setCell(cell);
+ final ILabelProvider provider = serv.getLabelProvider(Constants.TABLE_LABEL_PROVIDER_CONTEXT, contextElement);
+ String str = provider.getText(contextElement);
+ if (str == null) {
+ str = ""; //$NON-NLS-1$
+ }
+ return str;
+ }
+
+ /**
+ * Overridden to show, additionally to the contents of a cell, a vertical arrow pointing down in case there are masked lines.
+ *
+ * @see org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter#paintCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle,
+ * org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param cell
+ * @param gc
+ * @param rectangle
+ * @param configRegistry
+ */
+ @Override
+ public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
+ super.paintCell(cell, gc, rectangle, configRegistry);
+ IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
+ int fontHeight = gc.getFontMetrics().getHeight();
+ String text = convertDataType(cell, configRegistry);
+ text = getTextToDisplay(cell, gc, rectangle.width, text);
+
+ int numberOfNewLines = getNumberOfNewLines(text);
+ // we're extending the row height (only if word wrapping is enabled)
+ int contentHeight = (fontHeight * numberOfNewLines) + (spacing * 2);
+ int contentToCellDiff = (cell.getBounds().height - rectangle.height);
+
+ if (performRowResize(contentHeight, rectangle)) {
+ ILayer layer = cell.getLayer();
+ layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff));
+ }
+ if (numberOfNewLines > 1) {
+
+ int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight);
+ String[] lines = text.split("\n"); //$NON-NLS-1$
+ for (int lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
+ Image im = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.infra.nattable", "/icons/arrow_down_end.png"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // If the current text position passes the cell bounds, we should display the down pointing arrow
+ if (contentHeight > rectangle.height && yStartPos + fontHeight > rectangle.height + rectangle.y) {
+ int yDownRowIcon = rectangle.y + rectangle.height - im.getBounds().height;
+ int xDownRowIcon = rectangle.x + rectangle.width - im.getBounds().width;
+ gc.drawImage(im, xDownRowIcon, yDownRowIcon);
+ }
+
+ // After each line, increase the y start position of the text
+ yStartPos += fontHeight;
+ }
+ }
+ }
+}

Back to the top