1 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 ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.jsp.JspWriter ; 27 28 29 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 width = "100%"; 49 private boolean overlay = true; 50 51 54 private boolean adminButtonVisible = true; 55 56 public BarMain(HttpServletRequest request) { 57 this.setRequest(request); 58 } 59 60 public BarMain(HttpServletRequest request, String path, String nodeCollectionName, String nodeName, String paragraph) { 61 this.setRequest(request); 62 this.setPath(path); 63 this.setNodeCollectionName(nodeCollectionName); 64 this.setNodeName(nodeName); 65 this.setParagraph(paragraph); 66 } 67 68 73 public void setDefaultButtons() { 74 this.setButtonEditView(); 75 this.setButtonPreview(); 76 this.setButtonSiteAdmin(); 77 this.setButtonProperties(); 78 } 79 80 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 114 public void setButtonProperties(String path, String paragraph) { 115 ButtonEdit b = new ButtonEdit(this.getRequest()); 116 b.setLabel(MessagesManager.get("buttons.properties")); 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 136 public void setButtonPreview() { 137 Button b = new Button(); 138 String str = MessagesManager.get("buttons.preview"); b.setLabel("« " + str); b.setOnclick("mgnlPreview(true);"); 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 157 public void setButtonEditView() { 158 Button b = new Button(); 159 String str = MessagesManager.get("buttons.preview.hidden"); 160 b.setLabel("»" + str); b.setOnclick("mgnlPreview(false);"); 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 183 public void setButtonSiteAdmin(String path) { 184 Button b = new Button(); 185 b.setLabel(MessagesManager.get("buttons.admincentral")); String repository = (String ) getRequest().getAttribute(info.magnolia.cms.core.Aggregator.REPOSITORY); 187 b.setOnclick("MgnlAdminCentral.showTree('"+repository+"','" + path + "');"); 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 s) { 208 this.width = s; 209 } 210 211 public String getWidth() { 212 return this.width; 213 } 214 215 220 public void setOverlay(boolean b) { 221 this.overlay = b; 222 } 223 224 public boolean getOverlay() { 225 return this.overlay; 226 } 227 228 233 public void drawHtml(JspWriter out) throws IOException { 234 if (Server.isAdmin()) { 235 236 boolean isGranted = Resource.getActivePage(this.getRequest()).isGranted(Permission.SET); 237 if (isGranted) { 238 239 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 this.setSmall(false); 251 if (this.getOverlay()) { 252 out.println("<div class=\"mgnlMainbar\" style=\"top:" + top 254 + "px;left:" + left 256 + "px;width:" + this.getWidth() 258 + ";\">"); } 260 out.println(this.getHtml()); 261 if (this.getOverlay()) { 262 out.println("</div>"); } 264 } 265 else { 266 top += 4; 268 left += 4; 269 out.println("<div class=\"mgnlMainbarPreview\" style=\"top:" + top + "px;left:" + left + "px;\">"); out.println(this.getButtonEditView().getHtml()); 271 out.println("</div>"); } 273 } 274 } 275 } 276 277 282 public void drawHtmlLinks(JspWriter out) throws IOException { 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 |