KickJava   Java API By Example, From Geeks To Geeks.

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


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.ContentRepository;
16 import info.magnolia.cms.gui.control.Bar;
17 import info.magnolia.cms.gui.control.Button;
18 import info.magnolia.cms.i18n.MessagesManager;
19 import info.magnolia.cms.security.Permission;
20 import info.magnolia.cms.util.Resource;
21
22 import java.io.IOException JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.jsp.JspWriter JavaDoc;
26
27 import org.apache.commons.lang.StringUtils;
28
29
30 /**
31  * @author Vinzenz Wyser
32  * @version 2.0
33  */

34 public class BarNew extends Bar {
35
36     private Button buttonNew = new Button();
37
38     public BarNew(HttpServletRequest JavaDoc request) {
39         this.setRequest(request);
40     }
41
42     /**
43      * Sets the default buttons.
44      */

45     public void setDefaultButtons() {
46         this.setButtonNew();
47     }
48
49     /**
50      * Places the default buttons to the very right/left position.
51      */

52     public void placeDefaultButtons() {
53         if (this.getButtonNew() != null) {
54             this.getButtonsLeft().add(0, this.getButtonNew());
55         }
56     }
57
58     public Button getButtonNew() {
59         return this.buttonNew;
60     }
61
62     public void setButtonNew(Button b) {
63         this.buttonNew = b;
64     }
65
66     public void setButtonNew() {
67         this.setButtonNew(this.getPath(), this.getNodeCollectionName(StringUtils.EMPTY), this
68             .getNodeName(StringUtils.EMPTY), this.getParagraph());
69     }
70
71     /**
72      * Sets the default edit button.
73      * @param path , path of the current page
74      * @param nodeCollectionName , i.e. 'MainParagarphs'
75      * @param nodeName , i.e. '01'
76      * @param paragraph , paragraph type
77      */

78     public void setButtonNew(String JavaDoc path, String JavaDoc nodeCollectionName, String JavaDoc nodeName, String JavaDoc paragraph) {
79         Button b = new Button();
80         b.setLabel(MessagesManager.getMessages().get("buttons.new")); //$NON-NLS-1$
81

82         String JavaDoc repository = (String JavaDoc) getRequest().getAttribute(info.magnolia.cms.core.Aggregator.REPOSITORY);
83         // if there are multiple paragraphs show the selectParagraph dialog
84
if (StringUtils.contains(paragraph, ',')) {
85             b.setOnclick("mgnlOpenDialog('" // //$NON-NLS-1$
86
+ path
87                 + "','" //$NON-NLS-1$
88
+ nodeCollectionName
89                 + "','" // //$NON-NLS-1$
90
+ nodeName
91                 + "','" // //$NON-NLS-1$
92
+ paragraph // this is a list
93
+ "','" // //$NON-NLS-1$
94
+ repository
95                 + "','.magnolia/dialogs/selectParagraph.html');"); //$NON-NLS-1$
96
}
97         // there is only one paragraph
98
else {
99             b.setOnclick("mgnlOpenDialog('" //$NON-NLS-1$
100
+ path
101                 + "','" //$NON-NLS-1$
102
+ nodeCollectionName
103                 + "','" //$NON-NLS-1$
104
+ nodeName
105                 + "','" //$NON-NLS-1$
106
+ paragraph
107                 + "','" //$NON-NLS-1$
108
+ repository
109                 + "');"); //$NON-NLS-1$
110
}
111         this.setButtonNew(b);
112     }
113
114     /**
115      * <p>
116      * draws the main bar (incl. all magnolia specific js and css sources)
117      * </p>
118      */

119     public void drawHtml(JspWriter JavaDoc out) throws IOException JavaDoc {
120         boolean isGranted = Resource.getActivePage(this.getRequest()).isGranted(Permission.SET);
121         if (!Resource.showPreview(this.getRequest()) && isGranted) {
122             this.setEvent("onmousedown", "mgnlMoveNodeEnd(this,'" + this.getPath() + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
123
this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);"); //$NON-NLS-1$ //$NON-NLS-2$
124
this.setEvent("onmouseout", "mgnlMoveNodeReset(this);"); //$NON-NLS-1$ //$NON-NLS-2$
125
this.setId(this.getNodeCollectionName() + "__" + this.getNodeName()); //$NON-NLS-1$
126
out.println(this.getHtml());
127         }
128     }
129 }
130
Popular Tags