1 package com.genimen.djeneric.web.renderers; 2 3 import java.util.ArrayList ; 4 5 import javax.xml.parsers.FactoryConfigurationError ; 6 import javax.xml.parsers.ParserConfigurationException ; 7 8 import org.w3c.dom.Document ; 9 import org.w3c.dom.Element ; 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 asXml(DjenericSessionManager sessionManager, WebTree tree) throws FactoryConfigurationError , ParserConfigurationException , 24 DjenericException 25 { 26 Document doc = createDocument(); 27 Element main = doc.createElement("main"); 28 doc.appendChild(main); 29 Element treeElem = tree.asXml(doc); 30 ArrayList preLoadList = new ArrayList (); 31 Element bar = createButtonBar(doc, preLoadList); 32 Element 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 createButtonBar(Document doc, ArrayList preLoadList) 42 { 43 Element 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 doc, Element root) 62 { 63 Element button = doc.createElement("divider"); 64 root.appendChild(button); 65 } 66 67 private void createButton(Document doc, Element root, ArrayList preLoadList, String cmd, String src, String srcDown, String srcDisabled, String tooltipId) 68 { 69 String tooltip = Messages.getString(tooltipId); 70 Element 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 createPreload(Document doc, DjenericSessionManager sessionManager, ArrayList preLoadList) throws DjenericException 82 { 83 Element preload = doc.createElement("preload"); 84 85 ResourceDefinition[] images = sessionManager.getImages(); 86 for(int i=0; i<images.length; i++) 87 { 88 Element 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 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 |