KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > common > BlockTableRendererSource


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.contrib.table.model.common;
16
17 import org.apache.tapestry.IRender;
18 import org.apache.tapestry.IRequestCycle;
19 import org.apache.tapestry.components.Block;
20 import org.apache.tapestry.components.BlockRenderer;
21 import org.apache.tapestry.contrib.table.model.ITableColumn;
22 import org.apache.tapestry.contrib.table.model.ITableModelSource;
23 import org.apache.tapestry.contrib.table.model.ITableRendererListener;
24 import org.apache.tapestry.contrib.table.model.ITableRendererSource;
25 import org.apache.tapestry.util.ComponentAddress;
26
27 /**
28  *
29  * @author mindbridge
30  * @since 2.3
31  */

32 public class BlockTableRendererSource implements ITableRendererSource
33 {
34     private static final long serialVersionUID = 1L;
35     
36     private ComponentAddress m_objBlockAddress;
37     private ComponentAddress m_objListenerAddress;
38
39     public BlockTableRendererSource(Block objBlock)
40     {
41         this(new ComponentAddress(objBlock));
42     }
43
44     public BlockTableRendererSource(
45         Block objBlock,
46         ITableRendererListener objListener)
47     {
48         this(new ComponentAddress(objBlock), new ComponentAddress(objListener));
49     }
50
51     public BlockTableRendererSource(ComponentAddress objBlockAddress)
52     {
53         this(objBlockAddress, null);
54     }
55
56     public BlockTableRendererSource(
57         ComponentAddress objBlockAddress,
58         ComponentAddress objListenerAddress)
59     {
60         setBlockAddress(objBlockAddress);
61         setListenerAddress(objListenerAddress);
62     }
63
64     /**
65      * @see org.apache.tapestry.contrib.table.model.ITableRendererSource#getRenderer(IRequestCycle, ITableModelSource, ITableColumn, Object)
66      */

67     public IRender getRenderer(
68         IRequestCycle objCycle,
69         ITableModelSource objSource,
70         ITableColumn objColumn,
71         Object JavaDoc objRow)
72     {
73         ComponentAddress objListenerAddress = getListenerAddress();
74         if (objListenerAddress != null)
75         {
76             ITableRendererListener objListener =
77                 (ITableRendererListener) objListenerAddress.findComponent(
78                     objCycle);
79             objListener.initializeRenderer(
80                 objCycle,
81                 objSource,
82                 objColumn,
83                 objRow);
84         }
85
86         Block objBlock = (Block) getBlockAddress().findComponent(objCycle);
87         return new BlockRenderer(objBlock);
88     }
89
90     /**
91      * Returns the blockAddress.
92      * @return ComponentAddress
93      */

94     public ComponentAddress getBlockAddress()
95     {
96         return m_objBlockAddress;
97     }
98
99     /**
100      * Sets the blockAddress.
101      * @param blockAddress The blockAddress to set
102      */

103     public void setBlockAddress(ComponentAddress blockAddress)
104     {
105         m_objBlockAddress = blockAddress;
106     }
107
108     /**
109      * Returns the listenerAddress.
110      * @return ComponentAddress
111      */

112     public ComponentAddress getListenerAddress()
113     {
114         return m_objListenerAddress;
115     }
116
117     /**
118      * Sets the listenerAddress.
119      * @param listenerAddress The listenerAddress to set
120      */

121     public void setListenerAddress(ComponentAddress listenerAddress)
122     {
123         m_objListenerAddress = listenerAddress;
124     }
125
126 }
127
Popular Tags