1 15 package org.apache.tapestry.workbench.tree.examples.fsmodel; 16 17 import org.apache.tapestry.IMarkupWriter; 18 import org.apache.tapestry.IRender; 19 import org.apache.tapestry.IRequestCycle; 20 import org.apache.tapestry.asset.PrivateAsset; 21 import org.apache.tapestry.contrib.tree.components.INodeRenderFactory; 22 import org.apache.tapestry.contrib.tree.model.ITreeDataModel; 23 import org.apache.tapestry.contrib.tree.model.ITreeModelSource; 24 import org.apache.tapestry.contrib.tree.model.ITreeStateModel; 25 26 29 public class NodeRenderFactory implements INodeRenderFactory { 30 31 34 public NodeRenderFactory() { 35 super(); 36 } 37 38 public IRender getRenderByID(Object objUniqueKey, 39 ITreeModelSource objTreeModelSource, 40 IRequestCycle objCycle) { 41 Object objValue = objTreeModelSource.getTreeModel().getTreeDataModel().getObject(objUniqueKey); 42 return getRender(objValue, objTreeModelSource, objCycle); 43 } 44 45 public IRender getRender(Object objValue, 46 ITreeModelSource objTreeModelSource, 47 IRequestCycle objCycle) { 48 return new CFileSystemRender(objValue, objTreeModelSource); 49 } 50 51 52 public class CFileSystemRender implements IRender{ 53 private Object m_objNode; 54 private ITreeModelSource m_objTreeModelSource; 55 56 public CFileSystemRender(Object objNode, ITreeModelSource objTreeModelSource) { 57 super(); 58 m_objNode = objNode; 59 m_objTreeModelSource = objTreeModelSource; 60 } 61 62 public boolean isOpen() { 63 ITreeDataModel objDataModel = 64 m_objTreeModelSource.getTreeModel().getTreeDataModel(); 65 ITreeStateModel objStateModel = 66 m_objTreeModelSource.getTreeModel().getTreeStateModel(); 67 Object objUniqueKey = objDataModel.getUniqueKey(m_objNode, null); 68 return objStateModel.isUniqueKeyExpanded(objUniqueKey); 69 } 70 71 public boolean isSelected(){ 72 ITreeDataModel objDataModel = 73 m_objTreeModelSource.getTreeModel().getTreeDataModel(); 74 ITreeStateModel objStateModel = 75 m_objTreeModelSource.getTreeModel().getTreeStateModel(); 76 Object objUniqueKey = objDataModel.getUniqueKey(m_objNode, null); 77 return objUniqueKey.equals(objStateModel.getSelectedNode()); 78 } 79 80 public void render(IMarkupWriter objWriter, IRequestCycle objCycle) { 81 PrivateAsset objAsset = getAsset(); 82 objWriter.begin("img"); 83 objWriter.attribute("border", "0"); 84 objWriter.attribute("src", objAsset.buildURL(objCycle)); 85 objWriter.attribute("valign", "middle"); 86 objWriter.end(); 87 objWriter.print(" "); 88 objWriter.begin("span"); 89 String strClassName = "fsNodeValue"; 90 objWriter.attribute("class", strClassName); 91 objWriter.closeTag(); 92 objWriter.print(getNode().toString().trim()); 93 objWriter.end(); 94 } 95 96 public IFileSystemTreeNode getNode(){ 97 return (IFileSystemTreeNode) m_objNode; 98 } 99 100 private PrivateAsset getAsset(){ 101 PrivateAsset objAsset; 102 103 if (!isOpen()) { 104 objAsset = getNode().getAssets().getAssetForCloseNode(); 105 } else { 106 objAsset = getNode().getAssets().getAssetForOpenNode(); 107 } 108 109 return objAsset; 110 } 111 } 112 } 113 | Popular Tags |