1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
*
*****************************************************************************/
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.CheckBoxPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter;
import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
/**
* This checkbox painter allows to display text into the cell
*
* @author VL222926
*
*/
public class CustomCheckBoxPainter extends CheckBoxPainter {
/**
* the text painter used to paint N/A
*/
private TextPainter textPainter = new CustomizedCellPainter();
/**
*
* @see org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter#getCellPainterAt(int, int,
* 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 x
* @param y
* @param cell
* @param gc
* @param bounds
* @param configRegistry
* @return
*/
@Override
public ICellPainter getCellPainterAt(int x, int y, ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
try {
isChecked(cell, configRegistry);
} catch (Exception e) {
return this;
}
return super.getCellPainterAt(x, y, cell, gc, bounds, configRegistry);
}
/**
*
* @see org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter#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 bounds
* @param configRegistry
*/
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
try {
isChecked(cell, configRegistry);
} catch (Exception e) {
this.textPainter.paintCell(cell, gc, bounds, configRegistry);
return;
}
super.paintCell(cell, gc, bounds, configRegistry);
}
/**
*
* @see org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter#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) {
try {
isChecked(cell, configRegistry);
} catch (Exception e) {
return textPainter.getPreferredWidth(cell, gc, configRegistry);
}
return super.getPreferredWidth(cell, gc, configRegistry);
}
/**
*
* @see org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter#getPreferredHeight(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 getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
try {
isChecked(cell, configRegistry);
} catch (Exception e) {
return textPainter.getPreferredHeight(cell, gc, configRegistry);
}
return super.getPreferredHeight(cell, gc, configRegistry);
}
}
|