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.ChopboxAnchor;
21 import org.eclipse.draw2d.ConnectionAnchor;
22 import org.eclipse.gef.ConnectionEditPart;
23 import org.eclipse.gef.NodeEditPart;
24 import org.eclipse.gef.Request;
25 import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
26
27 import pl.edu.agh.cast.figure.AbstractLegendFigure;
28 import pl.edu.agh.cast.model.visual.Legend;
29
30
31
32
33
34
35 public abstract class AbstractLegendEditPart extends AbstractGraphicalEditPart implements NodeEditPart {
36
37
38
39
40 protected Legend legend;
41
42
43
44
45 protected AbstractLegendFigure legendFigure;
46
47 private ConnectionAnchor connectionAnchor;
48
49
50
51
52
53
54
55 public AbstractLegendEditPart(Legend legend) {
56 this.legend = legend;
57 setModel(legend);
58 }
59
60
61
62
63
64
65 public Legend getModel() {
66 return legend;
67 }
68
69
70
71
72
73
74 @Override
75 protected void refreshVisuals() {
76
77
78
79 if (legend.getLocation().x > 0) {
80 legendFigure.setLocation(legend.getLocation());
81 }
82 refreshItems();
83 }
84
85
86
87
88 public void refreshItems() {
89 legendFigure.refresh();
90 }
91
92
93
94
95
96
97 public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
98 return getConnectionAnchor();
99 }
100
101
102
103
104
105
106 public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
107 return getConnectionAnchor();
108 }
109
110
111
112
113
114
115 public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
116 return getConnectionAnchor();
117 }
118
119
120
121
122
123
124 public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
125 return getConnectionAnchor();
126 }
127
128 private ConnectionAnchor getConnectionAnchor() {
129 if (connectionAnchor == null) {
130 connectionAnchor = new ChopboxAnchor(legendFigure);
131 }
132 return connectionAnchor;
133
134 }
135
136 }