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