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.cms.gui.inline;
35
36 import info.magnolia.cms.beans.config.ServerConfiguration;
37 import info.magnolia.cms.core.AggregationState;
38 import info.magnolia.cms.gui.control.Bar;
39 import info.magnolia.cms.gui.control.Button;
40 import info.magnolia.cms.gui.control.Control;
41 import info.magnolia.cms.gui.control.ControlImpl;
42 import info.magnolia.cms.gui.i18n.I18nAuthoringSupport;
43 import info.magnolia.cms.gui.misc.Sources;
44 import info.magnolia.cms.i18n.MessagesManager;
45 import info.magnolia.cms.security.Permission;
46 import info.magnolia.context.MgnlContext;
47
48 import java.io.IOException;
49 import java.io.Writer;
50
51 import javax.servlet.http.HttpServletRequest;
52 import javax.servlet.jsp.JspWriter;
53
54
55
56
57
58
59 public class BarMain extends Bar {
60
61 private Button buttonEditView = new Button();
62
63 private Button buttonPreview = new ButtonEdit();
64
65 private Button buttonProperties = new Button();
66
67 private Button buttonSiteAdmin = new Button();
68
69 private Control languageChooser;
70
71 private String dialog;
72
73 private int top;
74
75 private int left;
76
77 private String width = "100%";
78
79 private boolean overlay = true;
80
81
82
83
84 private boolean adminButtonVisible = true;
85
86
87
88
89 public BarMain(HttpServletRequest request) {
90 }
91
92
93
94
95 public BarMain(HttpServletRequest request, String path, String nodeCollectionName, String nodeName, String paragraph) {
96 this(path, nodeCollectionName, nodeName, paragraph);
97 }
98
99 public BarMain(String path, String nodeCollectionName, String nodeName, String dialog) {
100 this.setPath(path);
101 this.setNodeCollectionName(nodeCollectionName);
102 this.setNodeName(nodeName);
103 this.setDialog(dialog);
104 }
105
106 public BarMain() {
107 }
108
109
110
111
112 public void setDefaultButtons() {
113 this.setButtonEditView();
114 this.setButtonPreview();
115 this.setButtonSiteAdmin();
116 this.setButtonProperties();
117 this.setLanguageChooser();
118 }
119
120
121
122
123 public void placeDefaultButtons() {
124 if (this.isAdminButtonVisible()) {
125 this.getButtonsLeft().add(0, this.getButtonSiteAdmin());
126 }
127 this.getButtonsLeft().add(0, this.getButtonPreview());
128
129 if(this.languageChooser != null){
130 getButtonsRight().add(this.languageChooser);
131 getButtonsRight().add(new ControlImpl(){
132 public String getHtml() {
133 return " ";
134 }
135 });
136 }
137
138 if (this.getDialog() != null) {
139 this.getButtonsRight().add(this.getButtonProperties());
140 }
141 }
142
143 public Button getButtonProperties() {
144 return this.buttonProperties;
145 }
146
147 public void setButtonProperties(Button b) {
148 this.buttonProperties = b;
149 }
150
151 public void setButtonProperties() {
152 this.setButtonProperties(this.getPath(), this.getDialog());
153 }
154
155
156
157
158
159
160
161 public void setButtonProperties(String path, String dialog) {
162 ButtonEdit b = new ButtonEdit();
163 b.setLabel(MessagesManager.get("buttons.properties"));
164 b.setPath(path);
165 b.setDialog(dialog);
166 b.setDefaultOnclick();
167 this.setButtonProperties(b);
168 }
169
170 public Button getButtonPreview() {
171 return this.buttonPreview;
172 }
173
174 public void setButtonPreview(Button b) {
175 this.buttonPreview = b;
176 }
177
178
179
180
181 public void setButtonPreview() {
182 Button b = new Button();
183 b.setLabel(MessagesManager.get("buttons.preview"));
184 b.setOnclick("mgnlPreview(true);");
185 this.setButtonPreview(b);
186 }
187
188 public Button getButtonEditView() {
189 return this.buttonEditView;
190 }
191
192 public void setButtonEditView(Button b) {
193 this.buttonEditView = b;
194 }
195
196
197
198
199 public void setButtonEditView() {
200 Button b = new Button();
201 b.setLabel(MessagesManager.get("buttons.preview.hidden"));
202 b.setOnclick("mgnlPreview(false);");
203 this.setButtonEditView(b);
204 }
205
206 public Button getButtonSiteAdmin() {
207 return this.buttonSiteAdmin;
208 }
209
210 public void setButtonSiteAdmin(Button b) {
211 this.buttonSiteAdmin = b;
212 }
213
214 public void setButtonSiteAdmin() {
215 this.setButtonSiteAdmin(this.getPath());
216 }
217
218
219
220
221
222 public void setButtonSiteAdmin(String path) {
223 Button b = new Button();
224 b.setLabel(MessagesManager.get("buttons.admincentral"));
225 String repository = MgnlContext.getAggregationState().getRepository();
226 b.setOnclick("MgnlAdminCentral.showTree('"+repository+"','" + path + "');");
227 this.setButtonSiteAdmin(b);
228 }
229
230 protected void setLanguageChooser() {
231 I18nAuthoringSupport i18nAuthoringSupport = I18nAuthoringSupport.Factory.getInstance();
232 if(i18nAuthoringSupport.isEnabled()){
233 languageChooser = i18nAuthoringSupport.getLanguageChooser();
234 }
235 }
236
237 public Control getLanguageChooser() {
238 return this.languageChooser;
239 }
240
241 public void setLanguageChooser(Control languageChooser) {
242 this.languageChooser = languageChooser;
243 }
244
245 public void setTop(int i) {
246 this.top = i;
247 }
248
249 public int getTop() {
250 return this.top;
251 }
252
253 public void setLeft(int i) {
254 this.left = i;
255 }
256
257 public int getLeft() {
258 return this.left;
259 }
260
261 public void setWidth(String s) {
262 this.width = s;
263 }
264
265 public String getWidth() {
266 return this.width;
267 }
268
269
270
271
272 public void setOverlay(boolean b) {
273 this.overlay = b;
274 }
275
276 public boolean getOverlay() {
277 return this.overlay;
278 }
279
280 public String getDialog() {
281 return this.dialog;
282 }
283
284 public void setDialog(String dialog) {
285 this.dialog = dialog;
286 }
287
288
289
290
291 public void drawHtml(JspWriter out) throws IOException {
292 drawHtml((Writer) out);
293 }
294
295
296
297
298 public void drawHtml(Writer out) throws IOException {
299 if (ServerConfiguration.getInstance().isAdmin()) {
300
301 final AggregationState aggregationState = MgnlContext.getAggregationState();
302 boolean isGranted = aggregationState.getMainContent().isGranted(Permission.SET);
303 if (isGranted) {
304
305
306 if (this.getRequest().getAttribute(Sources.REQUEST_LINKS_DRAWN) == null) {
307 this.drawHtmlLinks(out);
308 this.getRequest().setAttribute(Sources.REQUEST_LINKS_DRAWN, Boolean.TRUE);
309 }
310
311 int top = this.getTop();
312 int left = this.getLeft();
313
314 if (!aggregationState.isPreviewMode()) {
315
316 this.setSmall(false);
317 if (this.getOverlay()) {
318 println(out, "<div class=\"mgnlMainbar\" style=\"top:"
319 + top
320 + "px;left:"
321 + left
322 + "px;width:"
323 + this.getWidth()
324 + ";\">");
325 }
326 println(out, this.getHtml());
327 if (this.getOverlay()) {
328 println(out, "</div>");
329 }
330 }
331 else {
332
333 top += 4;
334 left += 4;
335 println(out, "<div class=\"mgnlMainbarPreview\" style=\"top:" + top + "px;left:" + left + "px;\">");
336 println(out, this.getButtonEditView().getHtml());
337 println(out, "</div>");
338 }
339 }
340 }
341 }
342
343
344
345
346 public void drawHtmlLinks(JspWriter out) throws IOException {
347 drawHtmlLinks((Writer) out);
348 }
349
350
351
352
353 public void drawHtmlLinks(Writer out) throws IOException {
354 println(out, new Sources(this.getRequest().getContextPath()).getHtmlCss());
355 println(out, new Sources(this.getRequest().getContextPath()).getHtmlJs());
356 }
357
358 public boolean isAdminButtonVisible() {
359 return this.adminButtonVisible;
360 }
361
362 public void setAdminButtonVisible(boolean adminButtonVisible) {
363 this.adminButtonVisible = adminButtonVisible;
364 }
365 }