1 13 package com.tonbeller.wcf.table; 14 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.MissingResourceException ; 18 19 import javax.servlet.jsp.JspException ; 20 21 import org.apache.log4j.Logger; 22 import org.w3c.dom.Document ; 23 24 import com.tonbeller.wcf.component.Component; 25 import com.tonbeller.wcf.component.ComponentTag; 26 import com.tonbeller.wcf.controller.RequestContext; 27 import com.tonbeller.wcf.selection.DefaultSelectionModel; 28 import com.tonbeller.wcf.selection.SelectionModel; 29 import com.tonbeller.wcf.utils.ResourceLocator; 30 import com.tonbeller.wcf.utils.XmlUtils; 31 32 37 public class TableComponentTag extends ComponentTag { 38 39 private static Logger logger = Logger.getLogger(TableComponentTag.class); 40 41 String model = null; 42 String selmode = "multi"; 43 boolean closable = true; 44 boolean pagable = true; 45 boolean sortable = true; 46 int pagesize = 10; 47 String editForm = null; 48 boolean editable = false; 49 boolean colHeaders = true; 50 51 54 public Component createComponent(RequestContext context) throws JspException { 55 try { 56 TableModel tm = EmptyTableModel.instance(); 57 if (model != null) { 58 tm = (TableModel)context.getModelReference(model); 59 if (tm == null) 60 throw new JspException ("table " + model + " not found"); 61 } 62 63 String tableId = editForm == null ? id : id + ".table"; 64 TableComponent tableComp = createTable(tableId, tm); 65 tableComp.setPageable(pagable); 66 tableComp.setSortable(sortable); 67 tableComp.setClosable(closable); 68 tableComp.setColHeaders(colHeaders); 69 70 DefaultSelectionModel dsm = new DefaultSelectionModel(); 71 if ("href".equals(selmode)) 72 dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF); 73 else if ("single".equals(selmode)) 74 dsm.setMode(SelectionModel.SINGLE_SELECTION); 75 else if ("multi".equals(selmode)) 76 dsm.setMode(SelectionModel.MULTIPLE_SELECTION); 77 else 78 dsm.setMode(SelectionModel.NO_SELECTION); 79 tableComp.setSelectionModel(dsm); 80 tableComp.setPageSize(pagesize); 81 82 if (editForm != null) { 83 URL url = ResourceLocator.getResource(context.getServletContext(), context.getLocale(), editForm); 85 Document doc = XmlUtils.parse(url); 86 TablePropertiesFormComponent formComp = new TablePropertiesFormComponent(id + ".form", null, doc, tableComp); 87 formComp.setVisible(false); 88 formComp.setCloseable(true); 89 return new EditableTableComponent(id, null, tableComp, formComp); 90 } 91 else if (editable) 92 return EditableTableComponent.instance(context, id, tableComp); 93 return tableComp; 94 95 } catch (MalformedURLException e) { 96 logger.error(id, e); 97 throw new JspException (e); 98 } catch (MissingResourceException e) { 99 logger.error(id, e); 100 throw new JspException (e); 101 } 102 } 103 104 protected TableComponent createTable(String tableId, TableModel tm) { 105 return new TableComponent(tableId, null, tm); 106 } 107 108 public void setModel(String model) { 109 this.model = model; 110 } 111 112 public void setSelmode(String string) { 113 selmode = string; 114 } 115 116 public void setClosable(boolean b) { 117 closable = b; 118 } 119 120 public void setPagable(boolean b) { 121 pagable = b; 122 } 123 124 public void setSortable(boolean b) { 125 sortable = b; 126 } 127 128 public void setPagesize(int i) { 129 pagesize = i; 130 } 131 132 public String getModel() { 133 return model; 134 } 135 136 public void setEditForm(String string) { 137 editForm = string; 138 } 139 140 public void setEditable(boolean editable) { 141 this.editable = editable; 142 } 143 144 public boolean isColHeaders() { 145 return colHeaders; 146 } 147 148 public void setColHeaders(boolean colHeaders) { 149 this.colHeaders = colHeaders; 150 } 151 } 152 | Popular Tags |