1 13 package com.tonbeller.wcf.tree; 14 15 import javax.servlet.http.HttpSession ; 16 17 import org.apache.commons.beanutils.PropertyUtils; 18 import org.w3c.dom.Element ; 19 20 import com.tonbeller.wcf.controller.RequestContext; 21 import com.tonbeller.wcf.form.FormComponent; 22 import com.tonbeller.wcf.form.NodeHandlerSupport; 23 import com.tonbeller.wcf.form.XmlComponent; 24 import com.tonbeller.wcf.selection.DefaultSelectionModel; 25 import com.tonbeller.wcf.selection.SelectionChangeListener; 26 import com.tonbeller.wcf.selection.SelectionModel; 27 import com.tonbeller.wcf.ui.XoplonCtrl; 28 import com.tonbeller.wcf.utils.DomUtils; 29 30 34 public class TreeHandler extends NodeHandlerSupport { 35 36 TreeComponent tree; 37 FormComponent formComp; 38 39 public void initialize(RequestContext context, XmlComponent xmlComp, Element element) throws Exception { 40 super.initialize(context, xmlComp, element); 41 42 formComp = (FormComponent) xmlComp; 44 45 String ref = XoplonCtrl.getModelReference(element); 46 Object bean = formComp.getBean(); 47 TreeModel tm = (TreeModel) PropertyUtils.getProperty(bean, ref); 48 tree = new TreeComponent(element.getAttribute("id"), formComp, tm); 49 50 DefaultSelectionModel dsm = new DefaultSelectionModel(); 51 String selmode = element.getAttribute("selmode"); 52 if ("href".equals(selmode)) 53 dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF); 54 else if ("single".equals(selmode)) 55 dsm.setMode(SelectionModel.SINGLE_SELECTION); 56 else if ("multi".equals(selmode)) 57 dsm.setMode(SelectionModel.MULTIPLE_SELECTION); 58 else if ("button".equals(selmode)) 59 dsm.setMode(SelectionModel.MULTIPLE_SELECTION_BUTTON); 60 else 61 dsm.setMode(SelectionModel.NO_SELECTION); 62 tree.setSelectionModel(dsm); 63 if (tm instanceof SelectionChangeListener) 64 dsm.addSelectionListener((SelectionChangeListener) tm); 65 66 String border = element.getAttribute("border"); 68 if (border.length() > 0) 69 tree.setBorder(border); 70 71 String width = element.getAttribute("width"); 73 if (width.length() > 0) 74 tree.setWidth(width); 75 76 tree.setRenderId(element.getAttribute("id")); 78 79 tree.addFormListener(formComp); 81 formComp.addFormListener(tree); 82 83 tree.initialize(context); 84 } 85 86 public void destroy(HttpSession session) throws Exception { 87 tree.destroy(session); 88 super.destroy(session); 89 } 90 91 public void render(RequestContext context) throws Exception { 92 super.render(context); 93 Element parent = getElement(); 94 DomUtils.removeChildElements(parent); 95 Element child = tree.render(context, parent.getOwnerDocument()); 96 parent.appendChild(child); 97 } 98 99 102 public FormComponent getFormComp() { 103 return formComp; 104 } 105 106 109 public TreeComponent getTree() { 110 return tree; 111 } 112 } 113 | Popular Tags |