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 package info.magnolia.templating.editor.client;
35
36
37 import info.magnolia.templating.editor.client.dom.CMSBoundary;
38
39 import com.google.gwt.dom.client.Element;
40 import com.google.gwt.dom.client.Node;
41 import com.google.gwt.dom.client.Style;
42 import com.google.gwt.dom.client.Style.Float;
43
44 import com.google.gwt.event.dom.client.MouseDownEvent;
45 import com.google.gwt.event.dom.client.MouseDownHandler;
46 import com.google.gwt.event.dom.client.MouseOutEvent;
47 import com.google.gwt.event.dom.client.MouseOutHandler;
48 import com.google.gwt.event.dom.client.MouseOverEvent;
49 import com.google.gwt.event.dom.client.MouseOverHandler;
50 import com.google.gwt.event.dom.client.MouseUpEvent;
51 import com.google.gwt.event.dom.client.MouseUpHandler;
52 import com.google.gwt.user.client.ui.Button;
53 import com.google.gwt.user.client.ui.FlowPanel;
54 import com.google.gwt.user.client.ui.InlineLabel;
55 import com.google.gwt.user.client.ui.Label;
56
57
58
59
60 public abstract class AbstractBarWidget extends FlowPanel {
61
62 private CMSBoundary boundary;
63 protected boolean hasControls = false;
64 private String label = "";
65
66 public AbstractBarWidget(CMSBoundary boundary) {
67
68 this.setBoundary(boundary);
69 if (boundary != null) {
70 this.label = boundary.getComment().getAttribute("label");
71 if (label == null || label.isEmpty()) {
72 if (boundary.getParentArea() != null) {
73 this.label = boundary.getParentArea().getComment().getAttribute("label");
74 }
75 }
76 }
77
78 if (this.label != null && !this.label.isEmpty()) {
79 Label areaName = new InlineLabel(this.label);
80
81 areaName.setTitle(this.label);
82
83
84 areaName.setStylePrimaryName("mgnlAreaLabel");
85 add(areaName);
86 }
87 addDomHandler(new MouseOverHandler() {
88 @Override
89 public void onMouseOver(MouseOverEvent event) {
90 select();
91 }
92 }, MouseOverEvent.getType());
93
94 addDomHandler(new MouseOutHandler() {
95 @Override
96 public void onMouseOut(MouseOutEvent event) {
97 deSelect();
98 }
99 }, MouseOutEvent.getType());
100 }
101
102
103
104
105 protected void select() {
106
107 this.addStyleName("selected");
108
109
110
111
112 }
113
114 protected void deSelect() {
115
116 this.removeStyleName("selected");
117
118 }
119
120 protected void setId(String id){
121 getElement().setId(id);
122 }
123
124 protected void addButton(final Button button, final Float cssFloat) {
125 button.setStylePrimaryName("mgnlControlButton");
126 button.getElement().getStyle().setFloat(cssFloat);
127
128 button.addMouseDownHandler(new MouseDownHandler() {
129
130 @Override
131 public void onMouseDown(MouseDownEvent event) {
132
133 button.setStyleName("mgnlControlButton_PUSHED", true);
134 }
135 });
136 button.addMouseUpHandler(new MouseUpHandler() {
137
138 @Override
139 public void onMouseUp(MouseUpEvent event) {
140
141 button.setStyleName("mgnlControlButton_PUSHED", false);
142 }
143 });
144 add(button);
145 hasControls = true;
146 }
147
148 protected void setClassName(String className) {
149 getElement().setClassName(className);
150 }
151
152
153
154
155 protected Style getStyle() {
156 return getElement().getStyle();
157 }
158
159 public void attach(Element element) {
160 final Node parentNode = element.getParentNode();
161 parentNode.insertAfter(getElement(), element);
162 onAttach();
163 }
164 public void attach(Node node) {
165 final Node parentNode = node.getParentNode();
166 parentNode.insertAfter(getElement(), node);
167 onAttach();
168 }
169 public void setBoundary(CMSBoundary boundary) {
170 this.boundary = boundary;
171 }
172
173 public CMSBoundary getBoundary() {
174 return boundary;
175 }
176 }