KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > view > pages > PrefixmappingPage


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: PrefixmappingPage.java,v 1.2 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages;
21
22 import java.io.IOException JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Locale JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import org.w3c.dom.Document JavaDoc;
27 //import org.enhydra.xml.xmlc.XMLCStdFactory;
28
import org.enhydra.barracuda.core.comp.BAction;
29 import org.enhydra.barracuda.core.comp.BComponent;
30 import org.enhydra.barracuda.core.comp.BTemplate;
31 import org.enhydra.barracuda.core.comp.BText;
32 import org.enhydra.barracuda.core.comp.DefaultTemplateView;
33 import org.enhydra.barracuda.core.comp.ViewContext;
34 import org.enhydra.barracuda.core.event.EventException;
35 import org.enhydra.barracuda.core.util.dom.DefaultDOMLoader;
36 import org.enhydra.barracuda.contrib.dbroggisch.display.HashMapModel;
37 import org.enhydra.barracuda.contrib.dbroggisch.display.IterativeListModel;
38 import org.enhydra.barracuda.contrib.dbroggisch.repopulation.RepopulationFormMap;
39 import org.apache.log4j.Logger;
40
41 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.events.*;
42 import org.enhydra.barracuda.contrib.dbroggisch.examples.model.forms.*;
43 import org.enhydra.barracuda.contrib.dbroggisch.examples.view.xmlc.*;
44
45
46 public class PrefixmappingPage extends ExampleBasePage {
47
48     private static final Logger logger = Logger.getLogger(PrefixmappingPage.class.getName());
49
50     List JavaDoc _maps;
51
52     public void setMaps(List JavaDoc maps) {
53         _maps = maps;
54     }
55
56     public void render(BComponent root, ViewContext vec, Document JavaDoc pDoc)
57             throws EventException, ServletException JavaDoc, IOException JavaDoc {
58         super.render(root, vec, pDoc);
59         Integer JavaDoc childCount = null;
60         PrefixMappingHTML doc = (PrefixMappingHTML) pDoc;
61         BTemplate mapComp = new BTemplate();
62
63         mapComp.setView(new DefaultTemplateView(doc.getElementTestHook()));
64
65         if(_maps.size() > 0) {
66             // This is the parent form map
67
RepopulationFormMap rfm = (RepopulationFormMap)_maps.remove(0);
68             mapComp.addModel(rfm);
69             childCount = (Integer JavaDoc)rfm.getVal(ParentFormMap.CHILD_COUNT);
70         }
71
72         IterativeListModel ilm = new IterativeListModel(ChildFormMap.MODEL_NAME, _maps) {
73                 public Object JavaDoc getItem(String JavaDoc key) {
74                     return ((RepopulationFormMap)_current).getItem(key);
75                 }
76             };
77
78         mapComp.addModel(ilm);
79         HashMapModel hmm = new HashMapModel();
80         hmm.setName("ControlModel");
81         hmm.setItem("SUBMIT", new BAction(new PrefixMapping()));
82         hmm.setItem("ADD", new BAction(new PrefixMappingAddChild()));
83         mapComp.addModel(hmm);
84
85         HashMapModel foo = new HashMapModel();
86         foo.setName("FooModel");
87         foo.setItem(ParentFormMap.CHILD_COUNT, new BText(childCount == null ? "None" :
88                                                          childCount.intValue() == 0 ? "None" :
89                                                          "" + childCount.intValue()));
90
91         mapComp.addModel(foo);
92         root.addChild(mapComp);
93     }
94
95     public Document JavaDoc getDocument(Locale JavaDoc iLocale) {
96         //return new XMLCStdFactory(null, null).create(PrefixMappingHTML.class);
97

98         Document JavaDoc doc = null;
99         //load the localized DOM template
100
try {doc = DefaultDOMLoader.getGlobalInstance().getDOM(PrefixMappingHTML.class, iLocale);}
101         catch (IOException JavaDoc ioe) {logger.fatal ("Fatal Error loading DOM template:", ioe);}
102         return doc;
103     }
104
105 }
106
Popular Tags