1 package org.enhydra.barracuda.examples.xmlc; 2 3 import java.io.*; 4 import java.util.*; 5 import javax.servlet.*; 6 import javax.servlet.http.*; 7 8 import org.w3c.dom.*; 9 import org.w3c.dom.html.*; 10 import org.enhydra.xml.xmlc.*; 11 12 import org.enhydra.barracuda.core.comp.*; 13 import org.enhydra.barracuda.core.comp.helper.*; 14 import org.enhydra.barracuda.core.util.dom.*; 15 import org.enhydra.barracuda.core.event.*; 16 import org.enhydra.barracuda.core.util.dom.*; 17 import org.enhydra.barracuda.core.view.*; 18 import org.enhydra.barracuda.examples.xmlc.data.*; 19 20 24 public class CompEx5 extends ComponentGateway { 25 26 30 public Document handleDefault (BComponent root, ViewContext vc, HttpServletRequest req, HttpServletResponse resp) throws IOException { 31 Document page = DefaultDOMLoader.getGlobalInstance().getDOM(CompEx5HTML.class); 33 34 35 BTemplate templateComp = new BTemplate(new SimpleTemplateModel()); 37 templateComp.setView(new DefaultTemplateView(page.getElementById("SimpleTemplateID"))); 38 root.addChild(templateComp); 39 40 41 BList blist1 = new BList(); 44 blist1.setName("BList 1"); 45 DefaultListModel dlm1 = new DefaultListModel(); 46 blist1.setModel(dlm1); 47 dlm1.add(new BLink("list link ok 1", "http://blah.com/testBLink.html", vc)); 48 dlm1.add(new BLink("list link ok 2", "http://blah.com/testBLink.html", vc)); 49 dlm1.add(new BLink("list link ok 3", "http://blah.com/testBLink.html", vc)); 50 for (int i=1; i<999; i++) { 53 Node n = page.getElementById("SimpleListID"+i); 54 if (n==null) break; 55 blist1.addView(new DefaultView(n)); 56 } 57 root.addChild(blist1); 58 59 BList blist2 = new BList(); 61 blist2.setName("BList 2"); 62 ListModel dlm2 = new DefinitionListModel(); 63 blist2.setModel(dlm2); 64 blist2.addView(new DefaultView(page.getElementById("DefinitionListID1"))); 65 root.addChild(blist2); 66 67 68 BTable btable1 = new BTable(); 71 btable1.setName("BTable 1"); 72 TableModel tm1 = new SimpleTableModel(); 73 btable1.setModel(tm1); 74 btable1.addView(new DefaultTableView(page.getElementById("SimpleTableID1"))); 75 btable1.addView(new DefaultTableView(page.getElementById("SimpleTableID2"))); 76 root.addChild(btable1); 77 78 return page; 80 } 81 82 88 public DOMWriter getDOMWriter() { 89 return new DefaultDOMWriter(true); 91 } 93 94 98 class SimpleTemplateModel extends AbstractTemplateModel { 99 public String getName() { 101 return "Test1"; 102 } 103 104 public Object getItem(String key) { 106 ViewContext vc = getViewContext(); 107 if (key.startsWith("Link")) { 108 BLink blink = new BLink("template link ok "+key.substring(4), "http://blah.com/testBLink1.html", vc); 109 return blink; 110 } else if (key.equals("TextAndLink")) { 111 BLink blink = new BLink("template link ok 5", "http://blah.com/testBLink2.html", vc); 112 BInput binput = new BInput(BInput.TEXT, "InputName", "value goes here"); 113 binput.setDefaultViewContext(vc); BToggleButton btoggle = new BToggleButton(BInput.RADIO, "ToggleName", "value goes here", true); 115 btoggle.setDefaultViewContext(vc); DefaultListModel dlm = new DefaultListModel(); 117 dlm.add(new DefaultItemMap("Key 1","Value 1")); 118 dlm.add(new DefaultItemMap("Key 2","Value 2")); 119 dlm.add(new DefaultItemMap("Key 3","Value 3")); 120 BSelect bselect = new BSelect(dlm); 121 bselect.setDefaultViewContext(vc); BText btext = new BText("Inline text, link ("+blink+"), input control "+binput+", toggle button "+btoggle+" and even a select item "+bselect); 124 btext.setAllowMarkupInText(true); 125 return btext; 126 } else if (key.equals("BComp1")) { 127 BComponent bcomp = new BComponent(); 132 bcomp.setVisible(false); 133 return bcomp; 134 } else return super.getItem(key); 135 } 136 } 137 138 139 class DefinitionListModel extends DefaultListModel { 141 public Object getItemAt(int index) { 142 ViewContext vc = getViewContext(); 143 Object [] items = null; 144 ElementFactory ef = vc.getElementFactory(); 145 BLink blDescr = new BLink("definition descr link ok"+(index+1), "http://blah.com/testBLink.html", vc); 146 return new Object [] {"Term "+(index+1), blDescr}; 147 } 148 149 public int getSize() {return 3;} 150 } 151 152 153 class SimpleTableModel extends AbstractTableModel { 155 public Object getItemAt(int row, int col) { 156 ViewContext vc = getViewContext(); 157 if (col==0) { 158 return "Row "+(row+1); 159 } else if (col==1) { 160 return new BLink("table link ok"+(row+1), "http://blah.com/testBLink.html", vc); 161 } else { 162 return null; 163 } 164 } 165 166 public int getRowCount() {return 3;} 167 public int getColumnCount() {return 2;} 168 } 169 170 } 171 | Popular Tags |