Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-01-28 16:38:33 +0000
committerGerrit Code Review @ Eclipse.org2016-02-23 15:08:43 +0000
commit6cdca71d13ce6729f9db58432ac584006cb63850 (patch)
tree74efc11a9387b88852dbcabe8866680230346cfc
parent03a9f2860c1f3730528447f513b6216d41b6dca3 (diff)
downloadorg.eclipse.papyrus-6cdca71d13ce6729f9db58432ac584006cb63850.tar.gz
org.eclipse.papyrus-6cdca71d13ce6729f9db58432ac584006cb63850.tar.xz
org.eclipse.papyrus-6cdca71d13ce6729f9db58432ac584006cb63850.zip
Bug 486101 - [Table] CellPainter refactoring
https://bugs.eclipse.org/bugs/show_bug.cgi?id=486101 - Remove the getDepth method from PapyrusIndentedTreeImagePainter because of the opening NatTable API - Remove the PapyrusSortableHeaderTextPainter and manage the icon header by a simple Icon painter. - Manage differently the paint decoration for the problem cells painter with the opening NatTable API - The PapyrusBeveledBorderDecoration musn't be remove -> It doesn't works anymore for Tree Table Change-Id: Ic65afc9e761711fd11408ffc928f0b9c6ac522eb Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java8
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java346
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusIndentedTreeImagePainter.java393
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortIconPainter.java64
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortableHeaderTextPainter.java144
5 files changed, 394 insertions, 561 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java
index 2623a0702ab..c1c5edbc96a 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/PapyrusClickSortConfiguration.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 486101
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.configuration;
@@ -16,10 +17,11 @@ package org.eclipse.papyrus.infra.nattable.configuration;
import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator;
import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator;
import org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration;
+import org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter;
import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum;
import org.eclipse.papyrus.infra.nattable.painter.CustomImagePainter;
import org.eclipse.papyrus.infra.nattable.painter.CustomizedCellPainter;
-import org.eclipse.papyrus.infra.nattable.painter.PapyrusSortableHeaderTextPainter;
+import org.eclipse.papyrus.infra.nattable.painter.PapyrusSortIconPainter;
/**
* The abstract configuration used for the sort the sort
@@ -30,12 +32,10 @@ import org.eclipse.papyrus.infra.nattable.painter.PapyrusSortableHeaderTextPaint
public abstract class PapyrusClickSortConfiguration extends DefaultSortConfiguration {
/**
- *
* Constructor.
- *
*/
public PapyrusClickSortConfiguration() {
- super(new BeveledBorderDecorator(new CellPainterDecorator(new PapyrusSortableHeaderTextPainter(new CustomizedCellPainter(), CellEdgeEnum.RIGHT), CellEdgeEnum.LEFT, new CustomImagePainter())));
+ super(new BeveledBorderDecorator(new CellPainterDecorator(new SortableHeaderTextPainter(new CustomizedCellPainter(), CellEdgeEnum.RIGHT, new PapyrusSortIconPainter(true)), CellEdgeEnum.LEFT, new CustomImagePainter())));
}
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java
index 970a0883adc..26294e9d73f 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java
@@ -1,224 +1,122 @@
-/*****************************************************************************
- * Copyright (c) 2013 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.painter;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-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.IStyle;
-import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- *
- * This cell painter draws waves above the displayed text when the cell contains one or several problem
- *
- */
-public class CellPainterWithUnderlinedError extends TextPainter {
- /**
- * the offset used to do the underline with "waves"
- */
- final private int[] yErrorOffsets = { 0, 1, 2, 1 };
-
- /**
- *
- * Constructor.
- *
- * @param wrapText
- * @param paintBg
- */
- public CellPainterWithUnderlinedError(boolean wrapText, boolean paintBg) {
- super(wrapText, paintBg);
- }
-
- /**
- *
- * @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
- *
- * Method duplcated from super class, to allow to use a specific underline style for error
- */
- @Override
- public void paintCell(final ILayerCell cell, GC gc, final Rectangle rectangle, final IConfigRegistry configRegistry) {
- if (paintBg) {
- super.paintCell(cell, gc, rectangle, configRegistry);
- }
-
- if (paintFg) {
- Rectangle originalClipping = gc.getClipping();
- gc.setClipping(rectangle.intersection(originalClipping));
-
- IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
- setupGCFromConfig(gc, cellStyle);
-
- boolean underline = renderUnderlined(cellStyle);
- boolean strikethrough = renderStrikethrough(cellStyle);
- boolean hasError = hasError(cell);
-
- int fontHeight = gc.getFontMetrics().getHeight();
- String text = convertDataType(cell, configRegistry);
-
- // Draw Text
- text = getTextToDisplay(cell, gc, rectangle.width, text);
-
- int numberOfNewLines = getNumberOfNewLines(text);
-
- // if the content height is bigger than the available row height
- // 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 contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.width);
-
- gc.drawText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + spacing,
- SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
- if (hasError || underline || strikethrough) {
- // start x of line = start x of text
- int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + spacing;
- // y = start y of text
- int y = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + spacing;
-
- if (hasError) {
- // y = start y of text + font height
- // - half of the font descent so the underline is between the baseline and the bottom
- int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
-
- Color previousColor = gc.getForeground();
- gc.setForeground(GUIHelper.COLOR_RED);
- int startX = x;
- underlineY--;
- int index = 0;
- while (startX <= (x + gc.textExtent(text).x)) {
- gc.drawPoint(startX, underlineY + this.yErrorOffsets[(index % 4)]);
- index++;
- startX++;
- }
- gc.setForeground(previousColor);
-
- } else {
-
- // check and draw underline and strikethrough separately so it is possible to combine both
- if (underline) {
- // y = start y of text + font height
- // - half of the font descent so the underline is between the baseline and the bottom
- int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
- gc.drawLine(x, underlineY, x + gc.textExtent(text).x, underlineY);
- }
-
- if (strikethrough) {
- // y = start y of text + half of font height + ascent so lower case characters are
- // also strikethrough
- int strikeY = y + (fontHeight / 2) + (gc.getFontMetrics().getLeading() / 2);
- gc.drawLine(x, strikeY, x + gc.textExtent(text).x, strikeY);
- }
- }
- }
- } else {
- // draw every line by itself because of the alignment, otherwise the whole text
- // is always aligned right
- 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);
-
- gc.drawText(line, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + spacing, yStartPos + spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
- if (hasError || underline || strikethrough) {
- // start x of line = start x of text
- int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + spacing;
- // y = start y of text
- int y = yStartPos + spacing;
-
- if (hasError) {
- int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
- Color previousColor = gc.getForeground();
- gc.setForeground(GUIHelper.COLOR_RED);
- int startX = x;
- underlineY--;
- int index = 0;
- while (startX <= (x + gc.textExtent(line).x)) {
- gc.drawPoint(startX, underlineY + this.yErrorOffsets[(index % 4)]);
- index++;
- startX++;
- }
- gc.setForeground(previousColor);
-
- } else {
- // check and draw underline and strikethrough separately so it is possible to combine both
- if (underline) {
- // y = start y of text + font height
- // - half of the font descent so the underline is between the baseline and the bottom
- int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
- gc.drawLine(x, underlineY, x + gc.textExtent(line).x, underlineY);
- }
-
- if (strikethrough) {
- // y = start y of text + half of font height + ascent so lower case characters are
- // also strikethrough
- int strikeY = y + (fontHeight / 2) + (gc.getFontMetrics().getLeading() / 2);
- gc.drawLine(x, strikeY, x + gc.textExtent(line).x, strikeY);
- }
- }
- }
-
- // after every line calculate the y start pos new
- yStartPos += fontHeight;
- }
- }
-
- gc.setClipping(originalClipping);
- }
- }
-
- /**
- *
- * @param cell
- * a cell
- * @return
- * <code>true</code> if the cell contents a Problem
- */
- protected boolean hasError(final ILayerCell cell) {
- Object value = cell.getDataValue();
- boolean hasError = false;
- if (value instanceof Problem) {
- hasError = true;
- } else if (value instanceof Collection<?>) {
- final Iterator<?> iter = ((Collection<?>) value).iterator();
- while (!hasError && iter.hasNext()) {
- hasError = iter.next() instanceof Problem;
- }
- }
- return hasError;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 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
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 486101
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.painter;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
+import org.eclipse.nebula.widgets.nattable.style.IStyle;
+import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * This cell painter draws waves above the displayed text when the cell contains one or several problem
+ */
+public class CellPainterWithUnderlinedError extends TextPainter {
+ /**
+ * the offset used to do the underline with "waves"
+ */
+ final private int[] yErrorOffsets = { 0, 1, 2, 1 };
+
+ /**
+ * Boolean to determinate if the cell has an error.
+ */
+ boolean hasError = false;
+
+ /**
+ * Constructor.
+ *
+ * @param wrapText
+ * split text over multiple lines
+ * @param paintBg
+ * skips painting the background if is FALSE
+ */
+ public CellPainterWithUnderlinedError(final boolean wrapText, final boolean paintBg) {
+ super(wrapText, paintBg);
+ }
+
+ /**
+ * Just calculate if the cell is in error before manage the paint cell. This allows to manage a different pain decoration if needed.
+ * {@inheritDoc}
+ *
+ * @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)
+ */
+ @Override
+ public void paintCell(final ILayerCell cell, GC gc, final Rectangle rectangle, final IConfigRegistry configRegistry) {
+ if (paintBg) {
+ hasError = hasError(cell);
+ }
+ super.paintCell(cell, gc, rectangle, configRegistry);
+ }
+
+ /**
+ * This allows to manage a different pain decoration (underline red) if the cell has an error.
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter#paintDecoration(org.eclipse.nebula.widgets.nattable.style.IStyle, org.eclipse.swt.graphics.GC, int, int, int, int)
+ */
+ @Override
+ protected void paintDecoration(final IStyle cellStyle, final GC gc, final int x, final int y, final int length, final int fontHeight) {
+ if (hasError) {
+ // y = start y of text + font height
+ // - half of the font descent so the underline is between the baseline and the bottom
+ int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
+
+ Color previousColor = gc.getForeground();
+ gc.setForeground(GUIHelper.COLOR_RED);
+ int startX = x;
+ underlineY--;
+ int index = 0;
+ while (startX <= (x + length)) {
+ gc.drawPoint(startX, underlineY + this.yErrorOffsets[(index % 4)]);
+ index++;
+ startX++;
+ }
+ gc.setForeground(previousColor);
+
+ } else {
+ super.paintDecoration(cellStyle, gc, x, y, length, fontHeight);
+ }
+ }
+
+ /**
+ * This allows to determinate if the cell has an error.
+ *
+ * @param cell
+ * a cell.
+ * @return
+ * <code>true</code> if the cell contents a Problem
+ */
+ protected boolean hasError(final ILayerCell cell) {
+ Object value = cell.getDataValue();
+ boolean hasError = false;
+ if (value instanceof Problem) {
+ hasError = true;
+ } else if (value instanceof Collection<?>) {
+ final Iterator<?> iter = ((Collection<?>) value).iterator();
+ while (!hasError && iter.hasNext()) {
+ hasError = iter.next() instanceof Problem;
+ }
+ }
+ return hasError;
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusIndentedTreeImagePainter.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusIndentedTreeImagePainter.java
index 7e99a3bbee0..068cb925b3e 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusIndentedTreeImagePainter.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusIndentedTreeImagePainter.java
@@ -1,189 +1,204 @@
-/*****************************************************************************
- * Copyright (c) 2014 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.nattable.painter;
-
-import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
-import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
-import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
-import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
-import org.eclipse.nebula.widgets.nattable.tree.config.DefaultTreeLayerConfiguration;
-import org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter;
-import org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter;
-import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
-import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * This intended tree painter allows us to ignore indentation when the table displays the hierarchy as multi column
- *
- * @author VL222926
- *
- */
-public class PapyrusIndentedTreeImagePainter extends IndentedTreeImagePainter {
-
- /**
- * Constructor.
- *
- */
- public PapyrusIndentedTreeImagePainter() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param treeIndent
- * @param cellEdge
- * @param treeImagePainter
- */
- public PapyrusIndentedTreeImagePainter(int treeIndent, CellEdgeEnum cellEdge, TreeImagePainter treeImagePainter) {
- super(treeIndent, cellEdge, treeImagePainter);
- }
-
- /**
- * Constructor.
- *
- * @param treeIndent
- * @param interiorPainter
- * @param paintBg
- * @param interiorPainterToSpanFullWidth
- */
- public PapyrusIndentedTreeImagePainter(int treeIndent, ICellPainter interiorPainter, boolean paintBg, boolean interiorPainterToSpanFullWidth) {
- super(treeIndent, interiorPainter, paintBg, interiorPainterToSpanFullWidth);
- }
-
- /**
- * Constructor.
- *
- * @param treeIndent
- * @param interiorPainter
- * @param cellEdge
- * @param paintBg
- * @param spacing
- * @param paintDecorationDependent
- */
- public PapyrusIndentedTreeImagePainter(int treeIndent, ICellPainter interiorPainter, CellEdgeEnum cellEdge, boolean paintBg, int spacing, boolean paintDecorationDependent) {
- super(treeIndent, interiorPainter, cellEdge, paintBg, spacing, paintDecorationDependent);
- }
-
- /**
- * Constructor.
- *
- * @param treeIndent
- * @param interiorPainter
- * @param cellEdge
- * @param decoratorPainter
- * @param paintBg
- * @param spacing
- * @param paintDecorationDependent
- */
- public PapyrusIndentedTreeImagePainter(int treeIndent, ICellPainter interiorPainter, CellEdgeEnum cellEdge, ICellPainter decoratorPainter, boolean paintBg, int spacing, boolean paintDecorationDependent) {
- super(treeIndent, interiorPainter, cellEdge, decoratorPainter, paintBg, spacing, paintDecorationDependent);
- }
-
- /**
- * Constructor.
- *
- * @param treeIndent
- * @param treeImagePainter
- */
- public PapyrusIndentedTreeImagePainter(int treeIndent, TreeImagePainter treeImagePainter) {
- super(treeIndent, treeImagePainter);
- }
-
- /**
- * Constructor.
- *
- * @param treeIndent
- */
- public PapyrusIndentedTreeImagePainter(int treeIndent) {
- super(treeIndent);
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter#getWrappedPainterBounds(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 bounds
- * @param configRegistry
- * @return
- */
- @Override
- public Rectangle getWrappedPainterBounds(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
- INattableModelManager tableManager = getTableManager(configRegistry);
- int depth = getDepth(cell);
- if (TableHelper.isMultiColumnTreeTable(tableManager)) {
- depth = 1;
- }
- int indent = getIndent(depth);
- return new Rectangle(bounds.x + indent, bounds.y, bounds.width - indent, bounds.height);
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter#getPreferredWidth(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.swt.graphics.GC, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
- *
- * @param cell
- * @param gc
- * @param configRegistry
- * @return
- */
- @Override
- public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
- INattableModelManager tableManager = getTableManager(configRegistry);
- int depth = getDepth(cell);
- if (TableHelper.isMultiColumnTreeTable(tableManager)) {
- depth = 1;
- }
- int indent = getIndent(depth);
- return indent + super.getPreferredWidth(cell, gc, configRegistry);
- }
-
-
- /**
- * @param cell
- * The cell for which the depth/level in the tree structure is requested.
- * @return The depth/level in the tree structure the given cell is located.
- */
- // TODO : ask to nattable to open there api to use this method from the super class
- protected int getDepth(ILayerCell cell) {
- int depth = 0;
-
- for (String configLabel : cell.getConfigLabels().getLabels()) {
- if (configLabel.startsWith(DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE)) {
- String[] tokens = configLabel.split("_"); //$NON-NLS-1$
- depth = Integer.valueOf(tokens[tokens.length - 1]).intValue();
- }
- }
-
- return depth;
- }
-
- /**
- *
- * @param configRegistry
- * the config registry
- * @return
- * the INattable manager from the config registry
- */
- private INattableModelManager getTableManager(final IConfigRegistry configRegistry) {
- return configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 486101
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.painter;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
+import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter;
+import org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter;
+import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.infra.nattable.utils.TableHelper;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * This intended tree painter allows us to ignore indentation when the table displays the hierarchy as multi column
+ */
+public class PapyrusIndentedTreeImagePainter extends IndentedTreeImagePainter {
+
+ /**
+ * Constructor.
+ */
+ public PapyrusIndentedTreeImagePainter() {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param treeIndent
+ * @param cellEdge
+ * @param treeImagePainter
+ */
+ public PapyrusIndentedTreeImagePainter(int treeIndent, CellEdgeEnum cellEdge, TreeImagePainter treeImagePainter) {
+ super(treeIndent, cellEdge, treeImagePainter);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param treeIndent
+ * The number of pixels to indent per depth.
+ * @param interiorPainter
+ * the base {@link ICellPainter} to use
+ * @param paintBg
+ * flag to configure whether the {@link TreeImagePainter} should
+ * paint the background or not
+ * @param interiorPainterToSpanFullWidth
+ * flag to configure how the bounds of the base painter should be
+ * calculated
+ */
+ public PapyrusIndentedTreeImagePainter(final int treeIndent, final ICellPainter interiorPainter, final boolean paintBg, final boolean interiorPainterToSpanFullWidth) {
+ super(treeIndent, interiorPainter, paintBg, interiorPainterToSpanFullWidth);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param treeIndent
+ * The number of pixels to indent per depth.
+ * @param interiorPainter
+ * the base {@link ICellPainter} to use
+ * @param cellEdge
+ * the edge of the cell on which the tree state indicator
+ * decoration should be applied
+ * @param paintBg
+ * flag to configure whether the {@link TreeImagePainter} should
+ * paint the background or not
+ * @param spacing
+ * the number of pixels that should be used as spacing between
+ * cell edge and decoration
+ * @param paintDecorationDependent
+ * flag to configure if the base {@link ICellPainter} should
+ * render decoration dependent or not. If it is set to
+ * <code>false</code>, the base painter will always paint at the
+ * same coordinates, using the whole cell bounds,
+ * <code>true</code> will cause the bounds of the cell to shrink
+ * for the base painter.
+ */
+ public PapyrusIndentedTreeImagePainter(final int treeIndent, final ICellPainter interiorPainter, final CellEdgeEnum cellEdge, final boolean paintBg, final int spacing, final boolean paintDecorationDependent) {
+ super(treeIndent, interiorPainter, cellEdge, paintBg, spacing, paintDecorationDependent);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param treeIndent
+ * The number of pixels to indent per depth.
+ * @param interiorPainter
+ * the base {@link ICellPainter} to use
+ * @param cellEdge
+ * the edge of the cell on which the tree state indicator
+ * decoration should be applied
+ * @param decoratorPainter
+ * the {@link ICellPainter} that should be used to paint the tree
+ * state related decoration
+ * @param paintBg
+ * flag to configure whether the {@link CellPainterDecorator}
+ * should paint the background or not
+ * @param spacing
+ * the number of pixels that should be used as spacing between
+ * cell edge and decoration
+ * @param paintDecorationDependent
+ * flag to configure if the base {@link ICellPainter} should
+ * render decoration dependent or not. If it is set to
+ * <code>false</code>, the base painter will always paint at the
+ * same coordinates, using the whole cell bounds,
+ * <code>true</code> will cause the bounds of the cell to shrink
+ * for the base painter.
+ */
+ public PapyrusIndentedTreeImagePainter(final int treeIndent, final ICellPainter interiorPainter, final CellEdgeEnum cellEdge, final ICellPainter decoratorPainter, final boolean paintBg, final int spacing, final boolean paintDecorationDependent) {
+ super(treeIndent, interiorPainter, cellEdge, decoratorPainter, paintBg, spacing, paintDecorationDependent);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param treeIndent
+ * The number of pixels to indent per depth.
+ * @param treeImagePainter
+ * The ICellPainter that should be used to paint the images in
+ * the tree. It needs to be of type of TreeImagePainter that
+ * paints expand/collapse/leaf icons regarding the node state,
+ * because the ui bindings for expand/collapse are registered
+ * against that type.
+ */
+ public PapyrusIndentedTreeImagePainter(final int treeIndent, final TreeImagePainter treeImagePainter) {
+ super(treeIndent, treeImagePainter);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param treeIndent
+ * The number of pixels to indent per depth.
+ */
+ public PapyrusIndentedTreeImagePainter(final int treeIndent) {
+ super(treeIndent);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter#getWrappedPainterBounds(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)
+ */
+ @Override
+ public Rectangle getWrappedPainterBounds(final ILayerCell cell, final GC gc, final Rectangle bounds, final IConfigRegistry configRegistry) {
+ INattableModelManager tableManager = getTableManager(configRegistry);
+ int depth = getDepth(cell);
+ if (TableHelper.isMultiColumnTreeTable(tableManager)) {
+ depth = 1;
+ }
+ int indent = getIndent(depth);
+ return new Rectangle(bounds.x + indent, bounds.y, bounds.width - indent, bounds.height);
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter#getPreferredWidth(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.swt.graphics.GC, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ *
+ * @param cell
+ * @param gc
+ * @param configRegistry
+ * @return
+ */
+ @Override
+ public int getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) {
+ INattableModelManager tableManager = getTableManager(configRegistry);
+ int depth = getDepth(cell);
+ if (TableHelper.isMultiColumnTreeTable(tableManager)) {
+ depth = 1;
+ }
+ int indent = getIndent(depth);
+ return indent + super.getPreferredWidth(cell, gc, configRegistry);
+ }
+
+ /**
+ *
+ * @param configRegistry
+ * the config registry
+ * @return
+ * the INattable manager from the config registry
+ */
+ private INattableModelManager getTableManager(final IConfigRegistry configRegistry) {
+ return configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortIconPainter.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortIconPainter.java
new file mode 100644
index 00000000000..98ccf792487
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortIconPainter.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.painter;
+
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.sort.painter.SortIconPainter;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AbstractHeaderAxisConfiguration;
+import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Inherited From SortIconPainter to manage the icon painter only for the header label and not for the index header.
+ */
+public class PapyrusSortIconPainter extends SortIconPainter {
+
+ /**
+ * Constructor.
+ *
+ * @param paintBg
+ * <code>true</code> if it should render the background itself,
+ * <code>false</code> if the background rendering should be
+ * skipped in here.
+ */
+ public PapyrusSortIconPainter(final boolean paintBg) {
+ super(paintBg);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.nebula.widgets.nattable.sort.painter.SortIconPainter#getImage(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
+ */
+ @Override
+ protected Image getImage(final ILayerCell cell, final IConfigRegistry configRegistry) {
+ boolean isDisplayIndex = false;
+
+ int position = cell.getRowPosition();
+ if (position == 0) {
+ INattableModelManager manager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ AbstractHeaderAxisConfiguration config = HeaderAxisConfigurationManagementUtils.getColumnAbstractHeaderAxisConfigurationUsedInTable(manager.getTable());
+ if (config != null && config.isDisplayIndex()) {
+ isDisplayIndex = true;
+ }
+ }
+
+ return isDisplayIndex ? null : super.getImage(cell, configRegistry);
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortableHeaderTextPainter.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortableHeaderTextPainter.java
deleted file mode 100644
index c7f4acfb7ce..00000000000
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/PapyrusSortableHeaderTextPainter.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.painter;
-
-import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
-import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
-import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
-import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
-import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator;
-import org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter;
-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.nebula.widgets.nattable.ui.util.CellEdgeEnum;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AbstractHeaderAxisConfiguration;
-import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
-import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-
-
-public class PapyrusSortableHeaderTextPainter extends SortableHeaderTextPainter {
-
- /**
- * Creates the default {@link SortableHeaderTextPainter} that uses a {@link TextPainter} as base {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the right
- * edge of the cell.
- */
- public PapyrusSortableHeaderTextPainter() {
- this(new TextPainter());
- }
-
- /**
- * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} as base {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the right
- * edge of the cell.
- *
- * @param interiorPainter
- * the base {@link ICellPainter} to use
- */
- public PapyrusSortableHeaderTextPainter(ICellPainter interiorPainter) {
- this(interiorPainter, CellEdgeEnum.RIGHT);
- }
-
- /**
- * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} as base {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the specified
- * edge of the cell.
- *
- * @param interiorPainter
- * the base {@link ICellPainter} to use
- * @param cellEdge
- * the edge of the cell on which the sort indicator decoration should be applied
- */
- public PapyrusSortableHeaderTextPainter(ICellPainter interiorPainter, CellEdgeEnum cellEdge) {
- this(interiorPainter, cellEdge, new SortIconPainter(true));
- }
-
- /**
- * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} as base {@link ICellPainter} and decorate it with the
- * given {@link ICellPainter} to use for sort
- * related decoration on the specified edge of the cell.
- *
- * @param interiorPainter
- * the base {@link ICellPainter} to use
- * @param cellEdge
- * the edge of the cell on which the sort indicator decoration should be applied
- * @param decoratorPainter
- * the {@link ICellPainter} that should be used to paint the sort related
- * decoration (by default the {@link SortIconPainter} will be used)
- */
- public PapyrusSortableHeaderTextPainter(ICellPainter interiorPainter, CellEdgeEnum cellEdge, ICellPainter decoratorPainter) {
- setWrappedPainter(new CellPainterDecorator(interiorPainter, cellEdge, decoratorPainter));
- }
-
- /**
- * Paints the triangular sort icon images.
- * Adapted code from Nattable
- */
- protected static class SortIconPainter extends org.eclipse.nebula.widgets.nattable.sort.painter.SortIconPainter {
-
- public SortIconPainter(boolean paintBg) {
- super(paintBg);
- }
-
-
- @Override
- public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
- int position = cell.getRowPosition();
- if (position == 0) {
- INattableModelManager manager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
- AbstractHeaderAxisConfiguration config = HeaderAxisConfigurationManagementUtils.getColumnAbstractHeaderAxisConfigurationUsedInTable(manager.getTable());
- if (config != null && config.isDisplayIndex()) {
- return;
- }
- }
-
- Image image = getImage(cell, configRegistry);
- if (image != null) {
- Rectangle imageBounds = image.getBounds();
- imageBounds = new Rectangle(imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height);
-
- IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
- int y = bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height);
-
- gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), y);
-
- // a try to add the order of the column into the sort at the top of the arrow
- // int x = bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width);
- //
- // System.out.println("before =" + y);
- // int yy = (y - imageBounds.height) - 2;//- 7;
- // float halfHeight = ((float)getPreferredHeight(cell, gc, configRegistry)) / ((float)2);
- // yy = (int)(y - (gc.getFont().getFontData()[0].height + 2));
- // System.out.println("after =" + yy);
- //
- // gc.drawText(Integer.toString(getSortSequence(cell)), x, yy); //$NON-NLS-1$
- }
- }
-
- @Override
- public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
- int width = super.getPreferredHeight(cell, gc, configRegistry);
- width += gc.getFont().getFontData()[0].height + 2;
- return width;
- }
-
- @Override
- public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
- return super.getPreferredWidth(cell, gc, configRegistry);
- }
-
- }
-
-}

Back to the top