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.i18n.MessagesManager;
41 import info.magnolia.cms.security.Permission;
42 import info.magnolia.cms.security.PermissionUtil;
43 import info.magnolia.context.MgnlContext;
44
45 import java.io.IOException;
46 import java.io.Writer;
47
48 import javax.jcr.Node;
49 import javax.jcr.RepositoryException;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.jsp.JspWriter;
52
53 import org.apache.commons.lang.StringUtils;
54
55
56
57
58
59
60 public class BarEdit extends Bar {
61
62 private ButtonEdit buttonEdit = new ButtonEdit();
63
64 private Button buttonMove = new Button();
65
66 private Button buttonDelete = new Button();
67
68 private String paragraph;
69
70
71
72
73 @Deprecated
74 public BarEdit(HttpServletRequest request) {
75 }
76
77 public BarEdit() {
78
79 }
80
81
82
83
84 public void setDefaultButtons() {
85 this.setButtonEdit();
86 this.setButtonMove();
87 this.setButtonDelete();
88 }
89
90
91
92
93 public void placeDefaultButtons() {
94 if (this.getButtonMove() != null) {
95 this.getButtonsLeft().add(0, this.getButtonMove());
96 }
97 if (this.getButtonEdit() != null) {
98 this.getButtonsLeft().add(0, this.getButtonEdit());
99 }
100 if (this.getButtonDelete() != null) {
101 this.getButtonsRight().add(this.getButtonsRight().size(), this.getButtonDelete());
102 }
103 }
104
105 public ButtonEdit getButtonEdit() {
106 return this.buttonEdit;
107 }
108
109 public void setButtonEdit(ButtonEdit b) {
110 this.buttonEdit = b;
111 }
112
113 public void setButtonEdit() {
114 this.setButtonEdit(this.getPath(), this.getNodeCollectionName(StringUtils.EMPTY), this.getNodeName(StringUtils.EMPTY), this.getParagraph());
115 }
116
117
118
119
120
121
122
123
124
125 public void setButtonEdit(String path, String nodeCollectionName, String nodeName, String paragraph) {
126 ButtonEdit b = new ButtonEdit(path, nodeCollectionName, nodeName, paragraph);
127 b.setDefaultOnclick();
128 this.setButtonEdit(b);
129 }
130
131 public Button getButtonMove() {
132 return this.buttonMove;
133 }
134
135 public void setButtonMove(Button b) {
136 this.buttonMove = b;
137 }
138
139 public void setButtonMove() {
140 this.setButtonMove(this.getNodeCollectionName(StringUtils.EMPTY), this.getNodeName(StringUtils.EMPTY));
141 }
142
143
144
145
146
147
148
149 public void setButtonMove(String nodeCollectionName, String nodeName) {
150 Button b = new Button();
151 b.setLabel(MessagesManager.get("buttons.move"));
152
153 this.setId(nodeCollectionName + "__" + nodeName);
154 b.setOnclick("mgnlMoveNodeStart('" + nodeCollectionName + "','" + nodeName + "','" + this.getId() + "');");
155 this.setButtonMove(b);
156 }
157
158 public Button getButtonDelete() {
159 return this.buttonDelete;
160 }
161
162 public void setButtonDelete(Button b) {
163 this.buttonDelete = b;
164 }
165
166
167
168
169 @Deprecated
170 public void setButtonDelete() {
171 this.setButtonDelete(this.getPath(), this.getNodeCollectionName(), this.getNodeName());
172 }
173
174
175
176
177
178
179
180
181
182
183 @Deprecated
184 public void setButtonDelete(String path, String nodeCollectionName, String nodeName) {
185 Button b = new Button();
186 b.setLabel(MessagesManager.get("buttons.delete"));
187 b.setOnclick("mgnlDeleteNode('" + path + "','" + nodeCollectionName + "','" + nodeName + "');");
188 this.setButtonDelete(b);
189 }
190
191 public void setButtonDelete(String pathToDelete) {
192 Button b = new Button();
193 b.setLabel(MessagesManager.get("buttons.delete"));
194 b.setOnclick("mgnlDeleteNode('" + pathToDelete + "');");
195 this.setButtonDelete(b);
196 }
197
198
199
200
201 @Deprecated
202 public void drawHtml(JspWriter out) throws IOException {
203 drawHtml((Writer) out);
204 }
205
206
207
208
209 public void drawHtml(Writer out) throws IOException {
210 final AggregationState aggregationState = MgnlContext.getAggregationState();
211 final Node mainContent = aggregationState.getMainContent().getJCRNode();
212 boolean isGranted;
213 try {
214 isGranted = PermissionUtil.isGranted(mainContent.getSession(), mainContent.getPath(), Permission.SET);
215 } catch (RepositoryException e) {
216
217 throw new RuntimeException(e);
218 }
219 if (!aggregationState.isPreviewMode() && isGranted && ServerConfiguration.getInstance().isAdmin()) {
220 this.setEvent("onmousedown", "mgnlMoveNodeEnd(this,'" + this.getPath() + "');");
221 this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);");
222 this.setEvent("onmouseout", "mgnlMoveNodeReset(this);");
223 println(out, getHtml());
224 }
225 }
226
227 public String getParagraph() {
228 return this.paragraph;
229 }
230
231 public void setParagraph(String paragraph) {
232 this.paragraph = paragraph;
233 }
234 }