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.MgnlElement;
38 import info.magnolia.templating.editor.client.jsni.LegacyJavascript;
39
40 import com.google.gwt.dom.client.Element;
41 import com.google.gwt.dom.client.Node;
42 import com.google.gwt.dom.client.Style;
43 import com.google.gwt.dom.client.Style.Float;
44
45
46 import com.google.gwt.user.client.ui.FlowPanel;
47 import com.google.gwt.user.client.ui.Label;
48 import com.google.gwt.user.client.ui.Widget;
49
50
51
52
53 public abstract class AbstractBarWidget extends FlowPanel {
54
55 protected boolean hasControls = false;
56 private String label = "";
57 private FlowPanel buttonWrapper;
58 private MgnlElement mgnlElement;
59
60 public AbstractBarWidget(MgnlElement mgnlElement) {
61
62 this.setMgnlElement(mgnlElement);
63 if (mgnlElement != null) {
64 this.label = mgnlElement.getComment().getAttribute("label");
65 if (label != null && !label.isEmpty()) {
66 Label areaName = new Label(this.label);
67
68 areaName.setTitle(this.label);
69 areaName.setStylePrimaryName("mgnlEditorBarLabel");
70
71
72 add(areaName);
73 }
74 }
75 buttonWrapper = new FlowPanel();
76 buttonWrapper.setStylePrimaryName("mgnlEditorBarButtons");
77
78 add(buttonWrapper);
79
80
81 setClassName("mgnlEditorBar");
82
83 }
84
85 protected void setId(String id){
86 getElement().setId(id);
87 }
88
89
90
91
92 protected void addButton(final Widget button, final Float cssFloat) {
93 button.setStylePrimaryName("mgnlEditorButton");
94 button.getElement().getStyle().setFloat(cssFloat);
95
96 buttonWrapper.add(button);
97 hasControls = true;
98 }
99
100
101
102
103 protected void addButton(final Widget button, final Float cssFloat, final String primaryStyleName) {
104 if(LegacyJavascript.isEmpty(primaryStyleName)) {
105 addButton(button, cssFloat);
106 return;
107 }
108 button.setStylePrimaryName(primaryStyleName);
109 button.getElement().getStyle().setFloat(cssFloat);
110
111 buttonWrapper.add(button);
112 hasControls = true;
113 }
114
115 protected void setClassName(String className) {
116 getElement().setClassName(className);
117 }
118
119
120
121
122 protected Style getStyle() {
123 return getElement().getStyle();
124 }
125
126
127
128
129 public void attach(Element element) {
130 final Node parentNode = element.getParentNode();
131 parentNode.insertAfter(getElement(), element);
132 onAttach();
133 }
134
135 public void toggleVisible() {
136 setVisible(!isVisible());
137 }
138
139 @Override
140 protected void onAttach() {
141 PageEditor.model.addElements(this.getMgnlElement(), getElement());
142 super.onAttach();
143 }
144
145 public void setMgnlElement(MgnlElement mgnlElement) {
146 this.mgnlElement = mgnlElement;
147 }
148
149 public MgnlElement getMgnlElement() {
150 return mgnlElement;
151 }
152
153 }