KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > workbench > tree > examples > DirectoryTableView


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.workbench.tree.examples;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
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 /**
32  * @author ceco
33  */

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     /**
44      *
45      */

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     /**
59      * @see org.apache.tapestry.AbstractComponent#finishLoad()
60      */

61     protected void finishLoad()
62     {
63         super.finishLoad();
64         getPage().addPageDetachListener(this);
65     }
66
67     /**
68      * @see org.apache.tapestry.event.PageDetachListener#pageDetached(org.apache.tapestry.event.PageEvent)
69      */

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 JavaDoc 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 JavaDoc arrColumnsList = new ArrayList JavaDoc();
92             arrColumnsList.add(new SimpleTableColumn("Name", true)
93             {
94                 public Object JavaDoc getColumnValue(Object JavaDoc 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 JavaDoc getColumnValue(Object JavaDoc 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 JavaDoc getSelectedNodeName()
134     {
135         return getSelectedFolderSource().getSelectedNodeName();
136     }
137 }
Popular Tags