1 13 44 package com.tonbeller.wcf.table; 45 46 import javax.servlet.http.HttpSession ; 47 import org.apache.commons.beanutils.PropertyUtils; 48 import org.w3c.dom.Element ; 49 import com.tonbeller.wcf.controller.RequestContext; 50 import com.tonbeller.wcf.form.FormComponent; 51 import com.tonbeller.wcf.form.NodeHandlerSupport; 52 import com.tonbeller.wcf.form.XmlComponent; 53 import com.tonbeller.wcf.selection.DefaultSelectionModel; 54 import com.tonbeller.wcf.selection.SelectionChangeListener; 55 import com.tonbeller.wcf.selection.SelectionModel; 56 import com.tonbeller.wcf.ui.XoplonCtrl; 57 import com.tonbeller.wcf.utils.DomUtils; 58 59 64 public class TableHandler extends NodeHandlerSupport { 65 66 TableComponent table; 67 68 FormComponent formComp; 69 70 public void initialize(RequestContext context, XmlComponent xmlComp, Element element) 71 throws Exception { 72 super.initialize(context, xmlComp, element); 73 formComp = (FormComponent) xmlComp; 75 String ref = XoplonCtrl.getModelReference(element); 76 Object bean = formComp.getBean(); 77 TableModel tm = (TableModel) PropertyUtils.getProperty(bean, ref); 78 table = createTableComp(element.getAttribute("id"), formComp, tm); 79 DefaultSelectionModel dsm = new DefaultSelectionModel(); 80 String selmode = element.getAttribute("selmode"); 81 if ("href".equals(selmode)) 82 dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF); 83 else if ("single".equals(selmode)) 84 dsm.setMode(SelectionModel.SINGLE_SELECTION); 85 else if ("multi".equals(selmode)) 86 dsm.setMode(SelectionModel.MULTIPLE_SELECTION); 87 else 88 dsm.setMode(SelectionModel.NO_SELECTION); 89 table.setSelectionModel(dsm); 90 if (tm instanceof SelectionChangeListener) 91 dsm.addSelectionListener((SelectionChangeListener) tm); 92 table.setClosable(false); 93 String border = element.getAttribute("border"); 94 if (border.length() > 0) 95 table.setBorder(border); 96 String width = element.getAttribute("width"); 97 if (width.length() > 0) 98 table.setWidth(width); 99 if("false".equals(element.getAttribute("colHeaders"))) 100 table.setColHeaders(false); 101 table.setRenderId(element.getAttribute("id")); 103 table.addFormListener(formComp); 104 formComp.addFormListener(table); 105 table.initialize(context); 106 } 107 108 protected TableComponent createTableComp(String id, FormComponent comp, TableModel tm) { 109 return new TableComponent(id, formComp, tm); 110 } 111 112 public void destroy(HttpSession session) throws Exception { 113 table.destroy(session); 114 super.destroy(session); 115 } 116 117 public void render(RequestContext context) throws Exception { 118 super.render(context); 119 Element parent = getElement(); 120 DomUtils.removeChildElements(parent); 121 Element child = table.render(context, parent.getOwnerDocument()); 122 parent.appendChild(child); 123 } 124 125 128 public FormComponent getFormComp() { 129 return formComp; 130 } 131 132 135 public TableComponent getTable() { 136 return table; 137 } 138 } | Popular Tags |