KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > inline > BarMain


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.inline;
14
15 import info.magnolia.cms.beans.config.Server;
16 import info.magnolia.cms.gui.control.Bar;
17 import info.magnolia.cms.gui.control.Button;
18 import info.magnolia.cms.gui.misc.Sources;
19 import info.magnolia.cms.i18n.MessagesManager;
20 import info.magnolia.cms.security.Permission;
21 import info.magnolia.cms.util.Resource;
22
23 import java.io.IOException JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.jsp.JspWriter JavaDoc;
27
28
29 /**
30  * @author Vinzenz Wyser
31  * @version 2.0
32  */

33 public class BarMain extends Bar {
34
35     private Button buttonEditView = new Button();
36
37     private Button buttonPreview = new ButtonEdit();
38
39     private Button buttonProperties = new Button();
40
41     private Button buttonSiteAdmin = new Button();
42
43     private int top;
44
45     private int left;
46
47     private String JavaDoc width = "100%"; //$NON-NLS-1$
48

49     private boolean overlay = true;
50
51     /**
52      * true if the AdminCentral button is visible
53      */

54     private boolean adminButtonVisible = true;
55
56     public BarMain(HttpServletRequest JavaDoc request) {
57         this.setRequest(request);
58     }
59
60     public BarMain(HttpServletRequest JavaDoc request, String JavaDoc path, String JavaDoc nodeCollectionName, String JavaDoc nodeName, String JavaDoc paragraph) {
61         this.setRequest(request);
62         this.setPath(path);
63         this.setNodeCollectionName(nodeCollectionName);
64         this.setNodeName(nodeName);
65         this.setParagraph(paragraph);
66     }
67
68     /**
69      * <p>
70      * sets the default buttons
71      * </p>
72      */

73     public void setDefaultButtons() {
74         this.setButtonEditView();
75         this.setButtonPreview();
76         this.setButtonSiteAdmin();
77         this.setButtonProperties();
78     }
79
80     /**
81      * <p>
82      * places the default buttons to the very right/left position
83      * </p>
84      */

85     public void placeDefaultButtons() {
86         if (this.isAdminButtonVisible()) {
87             this.getButtonsLeft().add(0, this.getButtonSiteAdmin());
88         }
89         this.getButtonsLeft().add(0, this.getButtonPreview());
90         if (this.getParagraph() != null) {
91             this.getButtonsRight().add(this.getButtonsRight().size(), this.getButtonProperties());
92         }
93     }
94
95     public Button getButtonProperties() {
96         return this.buttonProperties;
97     }
98
99     public void setButtonProperties(Button b) {
100         this.buttonProperties = b;
101     }
102
103     public void setButtonProperties() {
104         this.setButtonProperties(this.getPath(), this.getParagraph());
105     }
106
107     /**
108      * <p>
109      * sets the default page properties button
110      * </p>
111      * @param path , path of the current page
112      * @param paragraph , paragraph type
113      */

114     public void setButtonProperties(String JavaDoc path, String JavaDoc paragraph) {
115         ButtonEdit b = new ButtonEdit(this.getRequest());
116         b.setLabel(MessagesManager.get("buttons.properties")); //$NON-NLS-1$
117
b.setPath(path);
118         b.setParagraph(paragraph);
119         b.setDefaultOnclick(this.getRequest());
120         this.setButtonProperties(b);
121     }
122
123     public Button getButtonPreview() {
124         return this.buttonPreview;
125     }
126
127     public void setButtonPreview(Button b) {
128         this.buttonPreview = b;
129     }
130
131     /**
132      * <p>
133      * sets the default preview button (to switch from edit to preview mode)
134      * </p>
135      */

136     public void setButtonPreview() {
137         Button b = new Button();
138         String JavaDoc str = MessagesManager.get("buttons.preview"); //$NON-NLS-1$
139
b.setLabel("&laquo; " + str); //$NON-NLS-1$
140
b.setOnclick("mgnlPreview(true);"); //$NON-NLS-1$
141
this.setButtonPreview(b);
142     }
143
144     public Button getButtonEditView() {
145         return this.buttonEditView;
146     }
147
148     public void setButtonEditView(Button b) {
149         this.buttonEditView = b;
150     }
151
152     /**
153      * <p>
154      * sets the default edit view button (to switch form preview to edit view mode)
155      * </p>
156      */

157     public void setButtonEditView() {
158         Button b = new Button();
159         String JavaDoc str = MessagesManager.get("buttons.preview.hidden");
160         b.setLabel("&raquo;" + str); //$NON-NLS-1$
161
b.setOnclick("mgnlPreview(false);"); //$NON-NLS-1$
162
this.setButtonEditView(b);
163     }
164
165     public Button getButtonSiteAdmin() {
166         return this.buttonSiteAdmin;
167     }
168
169     public void setButtonSiteAdmin(Button b) {
170         this.buttonSiteAdmin = b;
171     }
172
173     public void setButtonSiteAdmin() {
174         this.setButtonSiteAdmin(this.getPath());
175     }
176
177     /**
178      * <p>
179      * sets the default site admin button
180      * </p>
181      * @param path , path of the current page (will show up in site admin)
182      */

183     public void setButtonSiteAdmin(String JavaDoc path) {
184         Button b = new Button();
185         b.setLabel(MessagesManager.get("buttons.admincentral")); //$NON-NLS-1$
186
String JavaDoc repository = (String JavaDoc) getRequest().getAttribute(info.magnolia.cms.core.Aggregator.REPOSITORY);
187         b.setOnclick("MgnlAdminCentral.showTree('"+repository+"','" + path + "');"); //$NON-NLS-1$ //$NON-NLS-2$
188
this.setButtonSiteAdmin(b);
189     }
190
191     public void setTop(int i) {
192         this.top = i;
193     }
194
195     public int getTop() {
196         return this.top;
197     }
198
199     public void setLeft(int i) {
200         this.left = i;
201     }
202
203     public int getLeft() {
204         return this.left;
205     }
206
207     public void setWidth(String JavaDoc s) {
208         this.width = s;
209     }
210
211     public String JavaDoc getWidth() {
212         return this.width;
213     }
214
215     /**
216      * <p>
217      * sets if the main bar overlays the content (true, default) or if it is moving it downward (false)
218      * </p>
219      */

220     public void setOverlay(boolean b) {
221         this.overlay = b;
222     }
223
224     public boolean getOverlay() {
225         return this.overlay;
226     }
227
228     /**
229      * <p>
230      * draws the main bar (incl. all magnolia specific js and css links)
231      * </p>
232      */

233     public void drawHtml(JspWriter JavaDoc out) throws IOException JavaDoc {
234         if (Server.isAdmin()) {
235
236             boolean isGranted = Resource.getActivePage(this.getRequest()).isGranted(Permission.SET);
237             if (isGranted) {
238
239                 // check if links have already been added.
240
if (this.getRequest().getAttribute(Sources.REQUEST_LINKS_DRAWN) == null) {
241                     this.drawHtmlLinks(out);
242                     this.getRequest().setAttribute(Sources.REQUEST_LINKS_DRAWN, Boolean.TRUE);
243                 }
244
245                 int top = this.getTop();
246                 int left = this.getLeft();
247
248                 if (!Resource.showPreview(this.getRequest())) {
249                     // is edit mode
250
this.setSmall(false);
251                     if (this.getOverlay()) {
252                         out.println("<div class=\"mgnlMainbar\" style=\"top:" //$NON-NLS-1$
253
+ top
254                             + "px;left:" //$NON-NLS-1$
255
+ left
256                             + "px;width:" //$NON-NLS-1$
257
+ this.getWidth()
258                             + ";\">"); //$NON-NLS-1$
259
}
260                     out.println(this.getHtml());
261                     if (this.getOverlay()) {
262                         out.println("</div>"); //$NON-NLS-1$
263
}
264                 }
265                 else {
266                     // is in preview mode
267
top += 4;
268                     left += 4;
269                     out.println("<div class=\"mgnlMainbarPreview\" style=\"top:" + top + "px;left:" + left + "px;\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
270
out.println(this.getButtonEditView().getHtml());
271                     out.println("</div>"); //$NON-NLS-1$
272
}
273             }
274         }
275     }
276
277     /**
278      * <p>
279      * draws the magnolia specific js and css links)
280      * </p>
281      */

282     public void drawHtmlLinks(JspWriter JavaDoc out) throws IOException JavaDoc {
283         out.println(new Sources(this.getRequest().getContextPath()).getHtmlCss());
284         out.println(new Sources(this.getRequest().getContextPath()).getHtmlJs());
285     }
286
287     public boolean isAdminButtonVisible() {
288         return this.adminButtonVisible;
289     }
290
291     public void setAdminButtonVisible(boolean adminButtonVisible) {
292         this.adminButtonVisible = adminButtonVisible;
293     }
294 }
295
Popular Tags