Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/pasteInNewTable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java')
-rw-r--r--sandbox/pasteInNewTable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java163
1 files changed, 0 insertions, 163 deletions
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java
deleted file mode 100644
index 64ab0305f7c..00000000000
--- a/sandbox/pasteInNewTable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/configuration/CustomizedCellPainter.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*****************************************************************************
- * 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.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.manager.table.NattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.ICell;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Status;
-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.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Custom CellPainter to define the LabelProvider to use
- *
- * @author Vincent Lorenzo
- *
- */
-//FIXME : we should use the TextPainter itself, now with the GenericDisplayConverter, it should works fine
-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)
- *
- * @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);
- final ILabelProviderContextElementWrapper contextElement = new LabelProviderCellContextElementWrapper(cell, configRegistry);
- 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;
- }
- }
- }
-
- //FIXME : essayer d'être plus subtile pour ce genre de chose!
- @Override
- protected Color getBackgroundColour(ILayerCell cell, IConfigRegistry configRegistry) {
- if(cell.getConfigLabels().hasLabel("BODY")) {//FIXME : doesn't work for boolean checkbox!
- int rowPosition = cell.getRowIndex();
- int columnPostion = cell.getColumnIndex();
- NattableModelManager manager = (NattableModelManager)configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
- Object rowElement = manager.getRowElement(rowPosition);
- Object columnElement = manager.getColumnElement(columnPostion);
- ICell tableCell = null;
-
- for(final ICell current : manager.getTable().getCells()) {
- if(manager.getTable().isInvertAxis()) {
- if(current.getRowElement() == columnElement && current.getColumnElement() == rowElement) {
- tableCell = current;
- }
- } else {
- if(current.getRowElement() == rowElement && current.getColumnElement() == columnElement) {
- tableCell = current;
- }
- }
- if(tableCell == null) {
- break;
- }
- if(tableCell.getProblems().size()!=0) {
- return new Color(Display.getDefault(), new RGB(255, 0, 0));
- }
- }
- }
- return super.getBackgroundColour(cell, configRegistry);
- }
-}

Back to the top