1 20 package org.enhydra.barracuda.core.comp; 21 22 import java.util.*; 23 24 import org.apache.log4j.*; 25 import org.w3c.dom.*; 26 import org.w3c.dom.html.*; 27 28 import org.enhydra.barracuda.core.comp.model.*; 29 import org.enhydra.barracuda.core.comp.renderer.*; 30 import org.enhydra.barracuda.core.comp.renderer.html.*; 31 import org.enhydra.barracuda.core.comp.renderer.xml.*; 32 import org.enhydra.barracuda.core.view.*; 33 import org.enhydra.barracuda.core.util.dom.DOMUtil; 34 import org.enhydra.barracuda.plankton.*; 35 36 46 public class BTable extends BComponent { 47 48 protected static final Logger logger = Logger.getLogger(BTable.class.getName()); 50 51 protected TableModel model = null; 53 protected TableModel headerModel = null; 54 protected TableModel footerModel = null; 55 private LocalModelListener callback = null; 56 private LocalModelListener headerCallback = null; 57 private LocalModelListener footerCallback = null; 58 protected Node templateNode = null; 59 protected BText caption = null; 61 65 public BTable() { 66 this (null); 67 } 68 69 81 public BTable(TableModel imodel) { 82 this (null, imodel, null, null); 83 } 84 85 100 BTable(TableModel iheaderModel, TableModel ibodyModel, TableModel ifooterModel, TableView view) { 101 if (iheaderModel!=null) setHeaderModel(iheaderModel); 102 if (ibodyModel!=null) setModel(ibodyModel); 103 if (ifooterModel!=null) setFooterModel(ifooterModel); 104 if (view!=null) this.addView(view); 105 } 106 107 108 109 110 111 115 static { 116 HTMLRendererFactory rfHTML = new HTMLRendererFactory(); 117 installRendererFactory(rfHTML, BTable.class, HTMLElement.class); 118 installRendererFactory(rfHTML, BTable.class, HTMLDocument.class); 119 } 120 121 124 static class HTMLRendererFactory implements RendererFactory { 125 public Renderer getInstance() {return new HTMLTableRenderer();} 126 } 127 128 129 130 131 139 public void setModel(TableModel imodel) { 140 141 if (model!=null && callback!=null) { 143 model.removeModelListener(callback); 145 } 146 147 model = imodel; 149 invalidate(); 150 151 if (model!=null) { 153 if (callback==null) callback = new LocalModelListener(); 154 model.addModelListener(callback); 156 } 157 } 158 159 164 public TableModel getModel() { 165 return model; 166 } 167 168 175 public void setHeaderModel(TableModel imodel) { 176 177 if (headerModel!=null && headerCallback!=null) { 179 headerModel.removeModelListener(headerCallback); 181 } 182 183 headerModel = imodel; 185 invalidate(); 186 187 if (headerModel!=null) { 189 if (headerCallback==null) headerCallback = new LocalModelListener(); 190 headerModel.addModelListener(headerCallback); 192 } 193 } 194 195 200 public TableModel getHeaderModel() { 201 return headerModel; 202 } 203 204 211 public void setFooterModel(TableModel imodel) { 212 213 if (footerModel!=null && footerCallback!=null) { 215 footerModel.removeModelListener(footerCallback); 217 } 218 219 footerModel = imodel; 221 invalidate(); 222 223 if (footerModel!=null) { 225 if (footerCallback==null) footerCallback = new LocalModelListener(); 226 footerModel.addModelListener(footerCallback); 228 } 229 } 230 231 236 public TableModel getFooterModel() { 237 return footerModel; 238 } 239 240 246 public void setCaption(BText icaption) { 247 this.caption = icaption; 248 } 249 250 256 public BText getCaption() { 257 return this.caption; 258 } 259 260 268 284 285 286 287 292 public void destroyCycle() { 293 super.destroyCycle(); 295 296 setModel(null); 301 setHeaderModel(null); 302 setFooterModel(null); 303 } 304 305 306 307 308 321 class LocalModelListener implements ModelListener { 322 public void modelChanged(Model m) { 324 invalidate(); 325 } 326 } 327 } | Popular Tags |