Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-05-21 15:20:52 +0000
committervlorenzo2013-05-21 15:20:52 +0000
commit60430c6a4fd0191ec1b8673c7a1a95896634a0be (patch)
tree0c9bb0191971caa4067a95765175b0a59451b457 /sandbox
parent1b4e5ff9dd1a9d6e868844d158ef33245e681e63 (diff)
downloadorg.eclipse.papyrus-60430c6a4fd0191ec1b8673c7a1a95896634a0be.tar.gz
org.eclipse.papyrus-60430c6a4fd0191ec1b8673c7a1a95896634a0be.tar.xz
org.eclipse.papyrus-60430c6a4fd0191ec1b8673c7a1a95896634a0be.zip
408585: [Table 2] Multiline visualization and Edition
https://bugs.eclipse.org/bugs/show_bug.cgi?id=408585
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/TableV3/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java5
-rw-r--r--sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java71
2 files changed, 75 insertions, 1 deletions
diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java b/sandbox/TableV3/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java
index 0474ec26f33..92742a7261a 100644
--- a/sandbox/TableV3/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java
+++ b/sandbox/TableV3/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/celleditor/config/EStructuralFeatureEditorConfig.java
@@ -32,6 +32,7 @@ import org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
+import org.eclipse.nebula.widgets.nattable.edit.editor.MultiLineTextCellEditor;
import org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor;
import org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
@@ -97,6 +98,8 @@ public class EStructuralFeatureEditorConfig extends AbstractCellEditorConfigurat
ICellEditor editor = null;
switch(editorKind) {
case SINGLE_STRING:
+ editor = new MultiLineTextCellEditor(true);
+ break;
case SINGLE_INTEGER:
editor = new TextCellEditor();
break;
@@ -208,7 +211,7 @@ public class EStructuralFeatureEditorConfig extends AbstractCellEditorConfigurat
cellPainter = new ComboBoxPainter();
break;
default:
- cellPainter = new TextPainter();
+ cellPainter = new TextPainter();//FIXME : seems overriden by the CustomizedCellPainter... -> the result is correct, but our code is maybe incorrect
break;
}
return cellPainter;
diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java
index 53b09552b9f..fd780498ad9 100644
--- a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java
+++ b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java
@@ -9,20 +9,29 @@
*
* 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.configuration;
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.painter.cell.TextPainter;
+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.ILabelProviderContextElement;
import org.eclipse.papyrus.infra.nattable.utils.LabelProviderCellContextElement;
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
@@ -35,6 +44,15 @@ public class CustomizedCellPainter extends TextPainter {
/**
*
+ * 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)
*
@@ -54,4 +72,57 @@ public class CustomizedCellPainter extends TextPainter {
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;
+ }
+ }
+
+
+ }
+
}

Back to the top