1 13 package info.magnolia.cms.gui.dialog; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.ItemType; 17 import info.magnolia.cms.gui.control.Button; 18 import info.magnolia.cms.gui.control.Edit; 19 import info.magnolia.cms.gui.misc.CssConstants; 20 21 import java.io.IOException ; 22 import java.io.Writer ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import javax.jcr.PropertyType; 28 import javax.jcr.RepositoryException; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 32 import org.slf4j.Logger; 33 import org.slf4j.LoggerFactory; 34 35 36 69 public class DialogEditWithCustomButtons extends DialogBox { 70 71 74 private static Logger log = LoggerFactory.getLogger(DialogEditWithCustomButtons.class); 75 76 79 private List buttons = new ArrayList (); 80 81 84 protected DialogEditWithCustomButtons() { 85 } 86 87 90 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode) 91 throws RepositoryException { 92 super.init(request, response, websiteNode, configNode); 93 94 try { 95 Iterator it = configNode.getContent("buttons").getChildren(ItemType.CONTENTNODE.getSystemName()).iterator(); while (it.hasNext()) { 97 Content n = (Content) it.next(); 98 99 Button button = new Button(); 100 button.setOnclick(n.getNodeData("onclick").getString()); 102 String label = null; 103 if (n.getNodeData("label").isExist()) { label = n.getNodeData("label").getString(); label = this.getMessage(label); 106 } 107 button.setLabel(label); 108 109 buttons.add(button); 110 } 111 } 112 catch (RepositoryException e) { 113 log.error("Exception caught: " + e.getMessage(), e); } 115 116 } 117 118 121 public void drawHtml(Writer out) throws IOException { 122 Edit control = new Edit(this.getName(), this.getValue()); 123 control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING)); if (this.getConfigValue("saveInfo").equals("false")) { control.setSaveInfo(false); 126 } 127 control.setCssClass(CssConstants.CSSCLASS_EDIT); 128 control.setRows(this.getConfigValue("rows", "1")); control.setCssStyles("width", "100%"); if (this.getConfigValue("onchange", null) != null) { control.setEvent("onchange", this.getConfigValue("onchange")); } 133 this.drawHtmlPre(out); 134 String width = this.getConfigValue("width", "95%"); out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"" + width + "\">"); out.write("<tr><td width=\"100%\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">"); out.write(control.getHtml()); 138 139 for (Iterator iter = this.buttons.iterator(); iter.hasNext();) { 140 Button button = (Button) iter.next(); 141 out.write("</td><td></td><td class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">"); out.write(button.getHtml()); 143 } 144 145 out.write("</td></tr></table>"); 147 this.drawHtmlPost(out); 148 } 149 } | Popular Tags |