KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > web > renderers > MainRenderer


1 package com.genimen.djeneric.web.renderers;
2
3 import java.util.ArrayList JavaDoc;
4
5 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
6 import javax.xml.parsers.ParserConfigurationException JavaDoc;
7
8 import org.w3c.dom.Document JavaDoc;
9 import org.w3c.dom.Element JavaDoc;
10
11 import com.genimen.djeneric.language.Messages;
12 import com.genimen.djeneric.repository.exceptions.DjenericException;
13 import com.genimen.djeneric.structure.ResourceDefinition;
14 import com.genimen.djeneric.web.renderers.tree.WebTree;
15 import com.genimen.djeneric.web.util.DjenericSessionManager;
16
17 public class MainRenderer extends AbstractRenderer
18 {
19   public MainRenderer()
20   {
21   }
22
23   public Document JavaDoc asXml(DjenericSessionManager sessionManager, WebTree tree) throws FactoryConfigurationError JavaDoc, ParserConfigurationException JavaDoc,
24       DjenericException
25   {
26     Document JavaDoc doc = createDocument();
27     Element JavaDoc main = doc.createElement("main");
28     doc.appendChild(main);
29     Element JavaDoc treeElem = tree.asXml(doc);
30     ArrayList JavaDoc preLoadList = new ArrayList JavaDoc();
31     Element JavaDoc bar = createButtonBar(doc, preLoadList);
32     Element JavaDoc preload = createPreload(doc, sessionManager, preLoadList);
33
34     main.appendChild(treeElem);
35     main.appendChild(bar);
36     main.appendChild(preload);
37     
38     return doc;
39   }
40
41   private Element JavaDoc createButtonBar(Document JavaDoc doc, ArrayList JavaDoc preLoadList)
42   {
43     Element JavaDoc bar = doc.createElement("buttonbar");
44
45     createButton(doc, bar, preLoadList, "refresh", "images/butrefresh.gif", "images/butrefreshdown.gif", "images/butrefreshdisabled.gif", "Specifier.ReloadSelected");
46     createButton(doc, bar, preLoadList, "filter", "images/butfilter.gif", "images/butfilterdown.gif", "images/butfilterdisabled.gif", "Specifier.Find");
47     createDivider(doc, bar);
48     createButton(doc, bar, preLoadList, "edit", "images/butedit.gif", "images/buteditdown.gif", "images/buteditdisabled.gif", "Specifier.EditSelected");
49     createButton(doc, bar, preLoadList, "copy", "images/butcopy.gif", "images/butcopydown.gif", "images/butcopydisabled.gif", "Specifier.CopySelected");
50     createButton(doc, bar, preLoadList, "add", "images/butadd.gif", "images/butadddown.gif", "images/butadddisabled.gif", "Specifier.CreateNew");
51     createButton(doc, bar, preLoadList, "delete", "images/butdelete.gif", "images/butdeletedown.gif", "images/butdeletedisabled.gif", "Specifier.DeleteSelected");
52     createDivider(doc, bar);
53     createButton(doc, bar, preLoadList, "export", "images/butexport.gif", "images/butexportdown.gif", "images/butexportdisabled.gif", "Specifier.ExportSelected");
54     createButton(doc, bar, preLoadList, "import", "images/butimport.gif", "images/butimportdown.gif", "images/butimportdisabled.gif", "Specifier.Import");
55     createDivider(doc, bar);
56     createButton(doc, bar, preLoadList, "collapse", "images/butcollapse.gif", "images/butcollapsedown.gif", "images/butcollapsedisabled.gif", "Specifier.CollapseAll");
57     createButton(doc, bar, preLoadList, "expand", "images/butexpand.gif", "images/butexpanddown.gif", "images/butexpanddisabled.gif", "Specifier.ExpandAll");
58     return bar;
59   }
60
61   private void createDivider(Document JavaDoc doc, Element JavaDoc root)
62   {
63     Element JavaDoc button = doc.createElement("divider");
64     root.appendChild(button);
65   }
66
67   private void createButton(Document JavaDoc doc, Element JavaDoc root, ArrayList JavaDoc preLoadList, String JavaDoc cmd, String JavaDoc src, String JavaDoc srcDown, String JavaDoc srcDisabled, String JavaDoc tooltipId)
68   {
69     String JavaDoc tooltip = Messages.getString(tooltipId);
70     Element JavaDoc button = doc.createElement("button");
71     button.setAttribute("cmd", cmd);
72     button.setAttribute("src", src);
73     button.setAttribute("srcdown", srcDown);
74     button.setAttribute("srcdisabled", srcDisabled);
75     button.setAttribute("tooltip", tooltip);
76     root.appendChild(button);
77     preLoadList.add(srcDown);
78     preLoadList.add(srcDisabled);
79   }
80
81   private Element JavaDoc createPreload(Document JavaDoc doc, DjenericSessionManager sessionManager, ArrayList JavaDoc preLoadList) throws DjenericException
82   {
83     Element JavaDoc preload = doc.createElement("preload");
84     
85     ResourceDefinition[] images = sessionManager.getImages();
86     for(int i=0; i<images.length; i++)
87     {
88       Element JavaDoc img = doc.createElement("image");
89       img.setAttribute("src", images[i].getAbsolutePath());
90       img.setAttribute("resource", "true");
91       preload.appendChild(img);
92     }
93     for(int i=0; i<preLoadList.size(); i++)
94     {
95       Element JavaDoc img = doc.createElement("image");
96       img.setAttribute("src", preLoadList.get(i).toString());
97       img.setAttribute("resource", "false");
98       preload.appendChild(img);
99     }
100     return preload;
101   }
102 }
103
Popular Tags