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.ui.vaadin.gwt.client.editor.widget.controlbar;
35
36 import com.google.gwt.dom.client.Style;
37 import com.google.gwt.dom.client.Style.Float;
38 import com.google.gwt.event.shared.EventBus;
39 import com.google.gwt.user.client.ui.FlowPanel;
40 import com.google.gwt.user.client.ui.Label;
41 import com.google.gwt.user.client.ui.Widget;
42
43 import info.magnolia.ui.vaadin.gwt.client.editor.dom.CmsNode;
44 import info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlElement;
45 import info.magnolia.ui.vaadin.gwt.client.editor.jsni.JavascriptUtils;
46
47
48
49
50
51 public abstract class AbstractBar extends FlowPanel {
52
53 protected final static String ICON_CLASSNAME = "editorIcon";
54 protected final static String EDIT_CLASSNAME = "icon-edit";
55 protected final static String REMOVE_CLASSNAME = "icon-trash";
56 protected final static String ADD_CLASSNAME = "icon-add";
57
58 private String workspace;
59
60 private String path;
61
62 private String label = "";
63
64 private final FlowPanel buttonWrapper;
65
66 private CmsNode cmsNode;
67
68 private FlowPanel primaryButtons;
69
70 private FlowPanel secondaryButtons;
71
72 private final EventBus eventBus;
73
74 private final static String FOCUS_CLASSNAME = "focus";
75
76 private final static String CHILD_FOCUS_CLASSNAME = "childFocus";
77
78 public AbstractBar(EventBus eventBus, MgnlElement mgnlElement) {
79 this.eventBus = eventBus;
80
81 this.setCmsNode(mgnlElement);
82
83 buttonWrapper = new FlowPanel();
84 buttonWrapper.setStylePrimaryName("mgnlEditorBarButtons");
85
86 add(buttonWrapper);
87
88 if (mgnlElement != null) {
89 this.label = mgnlElement.getAttribute("label");
90 if (label != null && !label.isEmpty()) {
91 Label areaName = new Label(this.label);
92
93 areaName.setTitle(this.label);
94 areaName.setStylePrimaryName("mgnlEditorBarLabel");
95
96
97 add(areaName);
98 }
99 }
100
101 setStyleName("mgnlEditor mgnlEditorBar");
102 }
103
104 @Override
105 public void onAttach() {
106 super.onAttach();
107 }
108
109 protected void setId(String id) {
110 getElement().setId(id);
111 }
112
113
114
115
116
117 protected void addButton(final Widget button, final Float cssFloat) {
118 button.setStylePrimaryName("mgnlEditorButton");
119 button.getElement().getStyle().setFloat(cssFloat);
120
121 buttonWrapper.add(button);
122 }
123
124
125
126
127
128 protected void addSecondaryButton(final Widget button) {
129 if (secondaryButtons == null) {
130 secondaryButtons = new FlowPanel();
131 secondaryButtons.setStylePrimaryName("mgnlEditorBarSecondaryButtons");
132 buttonWrapper.add(secondaryButtons);
133 }
134 secondaryButtons.add(button);
135 }
136
137
138
139
140
141 protected void addPrimaryButton(final Widget button) {
142 if (primaryButtons == null) {
143 primaryButtons = new FlowPanel();
144 primaryButtons.setStylePrimaryName("mgnlEditorBarPrimaryButtons");
145 buttonWrapper.add(primaryButtons);
146 }
147
148 primaryButtons.add(button);
149 }
150
151
152
153
154
155 protected void addButton(final Widget button, final Float cssFloat, final String primaryStyleName) {
156 if (JavascriptUtils.isEmpty(primaryStyleName)) {
157 addButton(button, cssFloat);
158 return;
159 }
160 button.setStylePrimaryName(primaryStyleName);
161 button.getElement().getStyle().setFloat(cssFloat);
162
163 buttonWrapper.add(button);
164 }
165
166
167
168
169
170
171 protected Style getStyle() {
172 return getElement().getStyle();
173 }
174
175
176
177 public void toggleVisible() {
178 setVisible(!isVisible());
179 }
180
181
182 public void setCmsNode(CmsNode cmsNode) {
183 this.cmsNode = cmsNode;
184 }
185
186 public CmsNode getCmsNode() {
187 return cmsNode;
188 }
189
190 public void toggleButtons(boolean visible) {
191 CmsNode parent = cmsNode.getParent();
192 if (parent != null) {
193 for (CmsNode component : parent.getComponents()) {
194 component.asMgnlElement().getControlBar().primaryButtons.setVisible(visible);
195 component.asMgnlElement().getControlBar().secondaryButtons.setVisible(visible);
196 }
197 }
198 }
199
200 public EventBus getEventBus() {
201 return eventBus;
202 }
203
204 public void removeFocus() {
205 removeStyleName(FOCUS_CLASSNAME);
206 removeStyleName(CHILD_FOCUS_CLASSNAME);
207 }
208
209 public void setFocus(boolean child) {
210 String className = (child) ? CHILD_FOCUS_CLASSNAME : FOCUS_CLASSNAME;
211 addStyleName(className);
212 }
213
214 public String getPath() {
215 return path;
216 }
217
218 public void setPath(String path) {
219 this.path = path;
220 }
221
222 public String getWorkspace() {
223 return workspace;
224 }
225
226 public void setWorkspace(String workspace) {
227 this.workspace = workspace;
228 }
229
230 public abstract String getDialog();
231
232 }