KickJava   Java API By Example, From Geeks To Geeks.

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


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-2005 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.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 BarEdit extends Bar {
35
36     private Button buttonEdit = new ButtonEdit();
37
38     private Button buttonMove = new Button();
39
40     private Button buttonDelete = new Button();
41
42     public BarEdit(HttpServletRequest JavaDoc request) {
43         this.setRequest(request);
44     }
45
46     /**
47      * <p>
48      * sets the default buttons
49      * </p>
50      */

51     public void setDefaultButtons() {
52         this.setButtonEdit();
53         this.setButtonMove();
54         this.setButtonDelete();
55     }
56
57     /**
58      * <p>
59      * places the default buttons to the very right/left position
60      * </p>
61      */

62     public void placeDefaultButtons() {
63         if (this.getButtonMove() != null) {
64             this.getButtonsLeft().add(0, this.getButtonMove());
65         }
66         if (this.getButtonEdit() != null) {
67             this.getButtonsLeft().add(0, this.getButtonEdit());
68         }
69         if (this.getButtonDelete() != null) {
70             this.getButtonsRight().add(this.getButtonsRight().size(), this.getButtonDelete());
71         }
72     }
73
74     public Button getButtonEdit() {
75         return this.buttonEdit;
76     }
77
78     public void setButtonEdit(Button b) {
79         this.buttonEdit = b;
80     }
81
82     public void setButtonEdit() {
83         this.setButtonEdit(this.getPath(), this.getNodeCollectionName(StringUtils.EMPTY), this
84             .getNodeName(StringUtils.EMPTY), this.getParagraph());
85     }
86
87     /**
88      * <p>
89      * sets the default edit button
90      * </p>
91      * @param path , path of the current page
92      * @param nodeCollectionName , i.e. 'MainParagarphs'
93      * @param nodeName , i.e. '01'
94      * @param paragraph , paragraph type
95      */

96     public void setButtonEdit(String JavaDoc path, String JavaDoc nodeCollectionName, String JavaDoc nodeName, String JavaDoc paragraph) {
97         ButtonEdit b = new ButtonEdit(this.getRequest(), path, nodeCollectionName, nodeName, paragraph);
98         b.setDefaultOnclick(this.getRequest());
99         this.setButtonEdit(b);
100     }
101
102     public Button getButtonMove() {
103         return this.buttonMove;
104     }
105
106     public void setButtonMove(Button b) {
107         this.buttonMove = b;
108     }
109
110     public void setButtonMove() {
111         this.setButtonMove(this.getNodeCollectionName(StringUtils.EMPTY), this.getNodeName(StringUtils.EMPTY));
112     }
113
114     /**
115      * <p>
116      * sets the default move button
117      * </p>
118      * @param nodeCollectionName , i.e. 'MainParagarphs'
119      * @param nodeName , i.e. '01'
120      */

121     public void setButtonMove(String JavaDoc nodeCollectionName, String JavaDoc nodeName) {
122         Button b = new Button();
123         b.setLabel(MessagesManager.getMessages(getRequest()).get("buttons.move")); //$NON-NLS-1$
124
// sets the id of the bar
125
this.setId(nodeCollectionName + "__" + nodeName); //$NON-NLS-1$
126
b.setOnclick("mgnlMoveNodeStart('" + nodeCollectionName + "','" + nodeName + "','" + this.getId() + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
127
this.setButtonMove(b);
128     }
129
130     public Button getButtonDelete() {
131         return this.buttonDelete;
132     }
133
134     public void setButtonDelete(Button b) {
135         this.buttonDelete = b;
136     }
137
138     public void setButtonDelete() {
139         this.setButtonDelete(this.getPath(), this.getNodeCollectionName(), this.getNodeName());
140     }
141
142     /**
143      * <p>
144      * sets the default delete button
145      * </p>
146      * @param path , path of the current page
147      * @param nodeCollectionName , i.e. 'MainColumnParagraphs'
148      * @param nodeName , i.e. '01'
149      */

150     public void setButtonDelete(String JavaDoc path, String JavaDoc nodeCollectionName, String JavaDoc nodeName) {
151         Button b = new Button();
152         b.setLabel(MessagesManager.getMessages(getRequest()).get("buttons.delete")); //$NON-NLS-1$
153
b.setOnclick("mgnlDeleteNode('" + path + "','" + nodeCollectionName + "','" + nodeName + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
154
this.setButtonDelete(b);
155     }
156
157     /**
158      * <p>
159      * draws the main bar (incl. all magnolia specific js and css sources)
160      * </p>
161      */

162     public void drawHtml(JspWriter JavaDoc out) throws IOException JavaDoc {
163         boolean isGranted = Resource.getActivePage(this.getRequest()).isGranted(Permission.SET);
164         if (!Resource.showPreview(this.getRequest()) && isGranted && Server.isAdmin()) {
165             this.setEvent("onmousedown", "mgnlMoveNodeEnd(this,'" + this.getPath() + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
166
this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);"); //$NON-NLS-1$ //$NON-NLS-2$
167
this.setEvent("onmouseout", "mgnlMoveNodeReset(this);"); //$NON-NLS-1$ //$NON-NLS-2$
168
out.println(this.getHtml());
169         }
170     }
171 }
172
Popular Tags