1 15 package org.apache.tapestry.workbench.tree.examples; 16 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 20 import org.apache.tapestry.BaseComponent; 21 import org.apache.tapestry.IBinding; 22 import org.apache.tapestry.contrib.table.components.Table; 23 import org.apache.tapestry.contrib.table.model.ITableColumn; 24 import org.apache.tapestry.contrib.table.model.ITableModel; 25 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; 26 import org.apache.tapestry.contrib.table.model.simple.SimpleTableModel; 27 import org.apache.tapestry.event.PageDetachListener; 28 import org.apache.tapestry.event.PageEvent; 29 import org.apache.tapestry.workbench.tree.examples.fsmodel.SFObject; 30 31 34 public abstract class DirectoryTableView extends BaseComponent implements PageDetachListener 35 { 36 37 private ITableModel m_objTableModel = null; 38 39 private ITableColumn[] m_arrColumns = null; 40 41 private ISelectedFolderSource m_objSelectedFolderSource = null; 42 43 46 public DirectoryTableView() 47 { 48 super(); 49 initialize(); 50 } 51 52 private void initialize() 53 { 54 m_objTableModel = null; 55 m_objSelectedFolderSource = null; 56 } 57 58 61 protected void finishLoad() 62 { 63 super.finishLoad(); 64 getPage().addPageDetachListener(this); 65 } 66 67 70 public void pageDetached(PageEvent arg0) 71 { 72 initialize(); 73 } 74 75 public ITableModel getTableModel() 76 { 77 if (m_objTableModel == null) 78 { 79 ISelectedFolderSource objSelectedFolderSource = getSelectedFolderSource(); 80 Collection colChildrens = objSelectedFolderSource.getSelectedFolderChildren(); 81 82 m_objTableModel = new SimpleTableModel(colChildrens.toArray(), getColumns()); 83 } 84 return m_objTableModel; 85 } 86 87 public ITableColumn[] getColumns() 88 { 89 if (m_arrColumns == null) 90 { 91 ArrayList arrColumnsList = new ArrayList (); 92 arrColumnsList.add(new SimpleTableColumn("Name", true) 93 { 94 public Object getColumnValue(Object objValue) 95 { 96 SFObject objSFObject = (SFObject) objValue; 97 return objSFObject.getName(); 98 } 99 }); 100 101 arrColumnsList.add(new SimpleTableColumn("Date", true) 102 { 103 public Object getColumnValue(Object objValue) 104 { 105 SFObject objSFObject = (SFObject) objValue; 106 return objSFObject.getDate(); 107 } 108 }); 109 110 m_arrColumns = new SimpleTableColumn[arrColumnsList.size()]; 111 arrColumnsList.toArray(m_arrColumns); 112 } 113 return m_arrColumns; 114 } 115 116 public ISelectedFolderSource getSelectedFolderSource() 117 { 118 if (m_objSelectedFolderSource == null) 119 { 120 IBinding objBinding = getBinding("selectedFolderSource"); 121 m_objSelectedFolderSource = (ISelectedFolderSource) objBinding.getObject(); 122 } 123 return m_objSelectedFolderSource; 124 } 125 126 public void resetState() 127 { 128 initialize(); 129 Table objTable = (Table) getComponent("table"); 130 objTable.reset(); 131 } 132 133 public String getSelectedNodeName() 134 { 135 return getSelectedFolderSource().getSelectedNodeName(); 136 } 137 } | Popular Tags |