1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.editpart;
19
20 import org.eclipse.draw2d.geometry.Rectangle;
21 import org.eclipse.gef.tools.CellEditorLocator;
22 import org.eclipse.jface.viewers.CellEditor;
23 import org.eclipse.swt.widgets.Text;
24
25 import pl.edu.agh.cast.backward.figure.NodeFigure;
26
27
28
29
30
31
32 public class LabelCellEditorLocator implements CellEditorLocator {
33
34 private NodeFigure nodeFigure;
35
36 public NodeFigure getNodeFigure() {
37 return nodeFigure;
38 }
39
40
41
42
43
44
45 public LabelCellEditorLocator(NodeFigure nodeFigure) {
46 setLabel(nodeFigure);
47 }
48
49
50
51
52
53 public void relocate(CellEditor celleditor) {
54 Text text = (Text)celleditor.getControl();
55
56 Rectangle rect = new Rectangle(nodeFigure.getLabelFigure().getClientArea());
57 nodeFigure.translateToAbsolute(rect);
58 org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
59 rect.translate(trim.x, trim.y);
60 rect.width += trim.width;
61 rect.height += trim.height;
62
63 rect.width = Math.max(rect.width, 100);
64 text.setBounds(rect.x, rect.y, rect.width, rect.height);
65 }
66
67
68
69
70 protected NodeFigure getLabel() {
71 return nodeFigure;
72 }
73
74
75
76
77
78
79
80 protected void setLabel(NodeFigure stickyNote) {
81 this.nodeFigure = stickyNote;
82 }
83
84 }