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.i18n.MessagesManager; 19 import info.magnolia.cms.security.Permission; 20 import info.magnolia.cms.util.Resource; 21 22 import java.io.IOException ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.jsp.JspWriter ; 26 27 import org.apache.commons.lang.StringUtils; 28 29 30 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 request) { 43 this.setRequest(request); 44 } 45 46 51 public void setDefaultButtons() { 52 this.setButtonEdit(); 53 this.setButtonMove(); 54 this.setButtonDelete(); 55 } 56 57 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 96 public void setButtonEdit(String path, String nodeCollectionName, String nodeName, String 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 121 public void setButtonMove(String nodeCollectionName, String nodeName) { 122 Button b = new Button(); 123 b.setLabel(MessagesManager.getMessages(getRequest()).get("buttons.move")); this.setId(nodeCollectionName + "__" + nodeName); b.setOnclick("mgnlMoveNodeStart('" + nodeCollectionName + "','" + nodeName + "','" + this.getId() + "');"); 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 150 public void setButtonDelete(String path, String nodeCollectionName, String nodeName) { 151 Button b = new Button(); 152 b.setLabel(MessagesManager.getMessages(getRequest()).get("buttons.delete")); b.setOnclick("mgnlDeleteNode('" + path + "','" + nodeCollectionName + "','" + nodeName + "');"); this.setButtonDelete(b); 155 } 156 157 162 public void drawHtml(JspWriter out) throws IOException { 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() + "');"); this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);"); this.setEvent("onmouseout", "mgnlMoveNodeReset(this);"); out.println(this.getHtml()); 169 } 170 } 171 } 172 | Popular Tags |