Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2013-11-06 10:41:00 +0000
committerCamille Letavernier2013-11-06 10:41:00 +0000
commitb8fad463d3ccf316edb39e9b5fc2d50e987996fe (patch)
tree9141794961165ae73045bf2315e1fd94ea614d66
parentc12316f0108066bb8bb98afe3c2e25320e356591 (diff)
parent6f1e30dd401e83376be5c053045df6df3a13c3a0 (diff)
downloadorg.eclipse.papyrus-b8fad463d3ccf316edb39e9b5fc2d50e987996fe.tar.gz
org.eclipse.papyrus-b8fad463d3ccf316edb39e9b5fc2d50e987996fe.tar.xz
org.eclipse.papyrus-b8fad463d3ccf316edb39e9b5fc2d50e987996fe.zip
Merge branch 'master' of ssh://cletavernie@git.eclipse.org/gitroot/papyrus/org.eclipse.papyrus.git
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java3
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java2
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties1
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java223
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CustomizedCellPainter.java44
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PapyrusNatTableToolTipProvider.java179
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/ProblemLabelProvider.java44
7 files changed, 450 insertions, 46 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
index aa5b9492788..811fb97a7e0 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
@@ -70,6 +70,7 @@ import org.eclipse.papyrus.infra.nattable.listener.NatTableDropListener;
import org.eclipse.papyrus.infra.nattable.manager.cell.CellManagerFactory;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
+import org.eclipse.papyrus.infra.nattable.provider.PapyrusNatTableToolTipProvider;
import org.eclipse.papyrus.infra.nattable.provider.TableSelectionProvider;
import org.eclipse.papyrus.infra.nattable.sort.ColumnSortModel;
import org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel;
@@ -210,7 +211,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
site.registerContextMenu(menuMgr, this.selectionProvider);
site.setSelectionProvider(this.selectionProvider);
}
-
+ new PapyrusNatTableToolTipProvider(this.natTable, GridRegion.BODY, GridRegion.COLUMN_HEADER, GridRegion.ROW_HEADER);
return this.natTable;
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java
index 46ec98077c1..d532d8149ad 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java
@@ -123,6 +123,8 @@ public class Messages extends NLS {
public static String PrintTableHandler_TablePrint;
+ public static String ProblemLabelProvider_StringsValuesCanBeResolved;
+
public static String TableLabelProvider_ErrorGettingIconForTable;
public static String TableTesterRegistry_SeveralTesterAreRegisteredWithTheSameId;
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties
index b3659ba6063..44cadf7b763 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties
@@ -50,6 +50,7 @@ NattableModelManager_TheCheckBoxHasNotBeenCheckedToAvoidAutomaticColumnAddition=
NattableModelManager_TheCheckBoxHasNotBeenCheckedToAvoidAutomaticRowAddition=The checkbox '%s' has not been checked, so the next column addition could be followed by a rows addition, ignoring your current selection of rows. Do you want to continue?
PrintTableHandler_PrintCantBeDone=Print can't be done
PrintTableHandler_TablePrint=Table Print
+ProblemLabelProvider_StringsValuesCanBeResolved={0} string(s) values can't be resolved:
TableLabelProvider_ErrorGettingIconForTable=Error getting icon image for tables:
TableTesterRegistry_SeveralTesterAreRegisteredWithTheSameId=Several classes are registered for the id {0}
TableTesterRegistry_TheClassCantBeLoaded=Class registrered with id {0} can't be loaded
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
new file mode 100644
index 00000000000..e4ea25abed0
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/painter/CellPainterWithUnderlinedError.java
@@ -0,0 +1,223 @@
+/*****************************************************************************
+ * 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;
+ }
+}
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 1c161e61e66..04b794def12 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
@@ -14,30 +14,23 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.painter;
-import java.util.Collection;
-import java.util.Iterator;
-
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.model.nattable.nattableproblem.Problem;
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.NattableConfigAttributes;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Display;
/**
* Custom CellPainter to define the LabelProvider to use
@@ -46,12 +39,7 @@ import org.eclipse.swt.widgets.Display;
*
*/
//TODO : we should use the TextPainter itself, now with the GenericDisplayConverter, it should works fine
-public class CustomizedCellPainter extends TextPainter {
-
- /**
- * the color used for error;
- */
- private final Color errorColor = new Color(Display.getDefault(), 255, 0, 0);
+public class CustomizedCellPainter extends CellPainterWithUnderlinedError {
/**
*
@@ -133,34 +121,4 @@ public class CustomizedCellPainter extends TextPainter {
}
}
}
-
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter#getBackgroundColour(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell,
- * org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)
- *
- * @param cell
- * @param configRegistry
- * @return
- */
- @Override
- protected Color getBackgroundColour(final ILayerCell cell, final IConfigRegistry configRegistry) {
- 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;
- }
- }
-
- if(hasError) {
- return this.errorColor;
- }
- return super.getBackgroundColour(cell, configRegistry);
- }
-
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PapyrusNatTableToolTipProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PapyrusNatTableToolTipProvider.java
new file mode 100644
index 00000000000..0c4b262639b
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PapyrusNatTableToolTipProvider.java
@@ -0,0 +1,179 @@
+/*****************************************************************************
+ * 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.provider;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
+import org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.internal.SharedImages;
+
+/**
+ *
+ * @author VL222926
+ * This class provides the tooltip to display in the table
+ */
+@SuppressWarnings("restriction")//$NON-NLS-1$
+//suppress warning for SharedImages
+public class PapyrusNatTableToolTipProvider extends NatTableContentTooltip {
+
+ /**
+ * the shared images registry
+ */
+ private final ISharedImages sharedImage = new SharedImages();
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param natTable
+ * the nattable
+ * @param tooltipRegions
+ * the region on which this tooltip provider will be applied
+ */
+ public PapyrusNatTableToolTipProvider(final NatTable natTable, final String... tooltipRegions) {
+ super(natTable, tooltipRegions);
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.window.DefaultToolTip#getImage(org.eclipse.swt.widgets.Event)
+ *
+ * @param event
+ * @return
+ */
+ @Override
+ protected Image getImage(Event event) {
+ if(isCellWithError(event)) {
+ return this.sharedImage.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
+ }
+ return super.getImage(event);
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip#getText(org.eclipse.swt.widgets.Event)
+ *
+ * @param event
+ * @return
+ */
+ @Override
+ protected String getText(final Event event) {
+ if(isCellWithError(event)) {
+ final ILayerCell cell = getCell(event);
+ return getProblemTooltip(cell.getDataValue());
+ } else {
+ return super.getText(event);
+ }
+ }
+
+ /**
+ *
+ * @param value
+ * @return
+ */
+ protected String getProblemTooltip(final Object value) {
+ ProblemLabelProvider provider = new ProblemLabelProvider();
+ if(value instanceof Problem) {
+ return provider.getTooltipText((EObject)value);
+ } else if(value instanceof Collection<?>) {
+ final StringBuilder builder = new StringBuilder();
+ final Iterator<?> iter = ((Collection<?>)value).iterator();
+ while(iter.hasNext()) {
+ final Object current = iter.next();
+ if(current instanceof Problem){
+ builder.append(provider.getTooltipText((EObject)current));
+ }
+ if(iter.hasNext()){
+ builder.append("\n"); //$NON-NLS-1$
+ }
+ }
+ return builder.toString();
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param event
+ * an event
+ * @return
+ * the cell for this event
+ */
+ protected ILayerCell getCell(final Event event) {
+ int col = this.natTable.getColumnPositionByX(event.x);
+ int row = this.natTable.getRowPositionByY(event.y);
+ return this.natTable.getCellByPosition(col, row);
+ }
+
+ /**
+ *
+ * @param event
+ * an event
+ * @return
+ * <code>true</code> if the cell have a problem
+ */
+ protected boolean isCellWithError(final Event event) {
+ final ILayerCell cell = getCell(event);
+ boolean hasError = false;
+ if(cell != null) {
+ final Object value = cell.getDataValue();
+ 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;
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip#shouldCreateToolTip(org.eclipse.swt.widgets.Event)
+ *
+ * @param event
+ * @return
+ */
+ @Override
+ protected boolean shouldCreateToolTip(final Event event) {
+ if(isCellWithError(event)) {
+ return true;
+ }
+ if(!isDisplayingFullCellText(event)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param event
+ * an event
+ * @return
+ * <code>true</code> if the cell size allow to display the full text
+ */
+ protected boolean isDisplayingFullCellText(final Event event) {
+ return true;//TODO : display a tooltip when the full text is not displayed in the cell
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/ProblemLabelProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/ProblemLabelProvider.java
index 3efcfcf0545..ce13f281b9d 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/ProblemLabelProvider.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/ProblemLabelProvider.java
@@ -13,9 +13,15 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.provider;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
+import org.eclipse.papyrus.infra.nattable.messages.Messages;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.StringResolutionProblem;
import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
/**
@@ -48,9 +54,43 @@ public class ProblemLabelProvider extends EMFLabelProvider implements IFilteredL
@Override
protected String getText(final EObject element) {
final Problem pb = (Problem)element;
- final String text = "#Problem: " + pb.getName() + "Description: " + pb.getDescription(); //$NON-NLS-1$ //$NON-NLS-2$
- return text;
+ if(pb instanceof StringResolutionProblem) {
+ return ((StringResolutionProblem)pb).getValueAsString();
+ }
+ return pb.getDescription();
}
+ /**
+ *
+ * @param element
+ * a problem
+ * @return
+ * the text to display for a problem in a tooltip
+ */
+ //TODO : should be obtained using a service or a specific wrapper to get tooltip
+ public String getTooltipText(final EObject element) {
+ if(element instanceof Problem) {
+ final Problem problem = (Problem)element;
+ final StringBuilder builder = new StringBuilder();
+ if(problem instanceof StringResolutionProblem) {
+ final List<String> unresolvedStrings = ((StringResolutionProblem)problem).getUnresolvedString();
+ builder.append(NLS.bind(Messages.ProblemLabelProvider_StringsValuesCanBeResolved,unresolvedStrings.size()));
+ if(unresolvedStrings.size() == 1) {
+ builder.append(" "); //$NON-NLS-1$
+ builder.append(unresolvedStrings.get(0));
+ } else {
+ final Iterator<String> iterOnString = ((StringResolutionProblem)problem).getUnresolvedString().iterator();
+ while(iterOnString.hasNext()) {
+ builder.append("\n\t- "); //$NON-NLS-1$
+ builder.append(iterOnString.next());
+ }
+ }
+ } else {
+ builder.append(((Problem)problem).getDescription());
+ }
+ return builder.toString();
+ }
+ return null;
+ }
}

Back to the top