1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.contrib.table.components.inserted; |
16 |
|
|
17 |
|
import org.apache.tapestry.BaseComponent; |
18 |
|
import org.apache.tapestry.IAsset; |
19 |
|
import org.apache.tapestry.IRequestCycle; |
20 |
|
import org.apache.tapestry.contrib.table.components.TableColumns; |
21 |
|
import org.apache.tapestry.contrib.table.model.ITableColumn; |
22 |
|
import org.apache.tapestry.contrib.table.model.ITableModel; |
23 |
|
import org.apache.tapestry.contrib.table.model.ITableModelSource; |
24 |
|
import org.apache.tapestry.contrib.table.model.ITableRendererListener; |
25 |
|
import org.apache.tapestry.contrib.table.model.ITableSortingState; |
26 |
|
import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; |
27 |
|
import org.apache.tapestry.event.PageDetachListener; |
28 |
|
import org.apache.tapestry.event.PageEvent; |
29 |
|
import org.apache.tapestry.util.ComponentAddress; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
public abstract class SimpleTableColumnComponent extends BaseComponent |
40 |
|
implements ITableRendererListener, PageDetachListener |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
private ITableColumn m_objColumn; |
45 |
|
private ITableModelSource m_objModelSource; |
46 |
|
|
47 |
|
public SimpleTableColumnComponent() |
48 |
0 |
{ |
49 |
0 |
init(); |
50 |
0 |
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public void pageDetached(PageEvent arg0) |
56 |
|
{ |
57 |
0 |
init(); |
58 |
0 |
} |
59 |
|
|
60 |
|
private void init() |
61 |
|
{ |
62 |
0 |
m_objColumn = null; |
63 |
0 |
m_objModelSource = null; |
64 |
0 |
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
public void initializeRenderer(IRequestCycle objCycle, |
71 |
|
ITableModelSource objSource, ITableColumn objColumn, Object objRow) |
72 |
|
{ |
73 |
0 |
m_objModelSource = objSource; |
74 |
0 |
m_objColumn = objColumn; |
75 |
0 |
} |
76 |
|
|
77 |
|
public ITableModel getTableModel() |
78 |
|
{ |
79 |
0 |
return m_objModelSource.getTableModel(); |
80 |
|
} |
81 |
|
|
82 |
|
public boolean getColumnSorted() |
83 |
|
{ |
84 |
0 |
return m_objColumn.getSortable(); |
85 |
|
} |
86 |
|
|
87 |
|
public String getDisplayName() |
88 |
|
{ |
89 |
0 |
if (m_objColumn instanceof SimpleTableColumn) |
90 |
|
{ |
91 |
0 |
SimpleTableColumn objSimpleColumn = (SimpleTableColumn) m_objColumn; |
92 |
0 |
return objSimpleColumn.getDisplayName(); |
93 |
|
} |
94 |
0 |
return m_objColumn.getColumnName(); |
95 |
|
} |
96 |
|
|
97 |
|
public boolean getIsSorted() |
98 |
|
{ |
99 |
0 |
ITableSortingState objSortingState = getTableModel().getSortingState(); |
100 |
0 |
String strSortColumn = objSortingState.getSortColumn(); |
101 |
0 |
return m_objColumn.getColumnName().equals(strSortColumn); |
102 |
|
} |
103 |
|
|
104 |
|
public IAsset getSortImage() |
105 |
|
{ |
106 |
|
IAsset objImageAsset; |
107 |
|
|
108 |
0 |
IRequestCycle objCycle = getPage().getRequestCycle(); |
109 |
0 |
ITableSortingState objSortingState = getTableModel().getSortingState(); |
110 |
0 |
if (objSortingState.getSortOrder() == ITableSortingState.SORT_ASCENDING) |
111 |
|
{ |
112 |
0 |
objImageAsset = (IAsset) objCycle |
113 |
|
.getAttribute(TableColumns.TABLE_COLUMN_ARROW_UP_ATTRIBUTE); |
114 |
0 |
if (objImageAsset == null) objImageAsset = getAsset("sortUp"); |
115 |
|
} |
116 |
|
else |
117 |
|
{ |
118 |
0 |
objImageAsset = (IAsset) objCycle |
119 |
|
.getAttribute(TableColumns.TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE); |
120 |
0 |
if (objImageAsset == null) objImageAsset = getAsset("sortDown"); |
121 |
|
} |
122 |
|
|
123 |
0 |
return objImageAsset; |
124 |
|
} |
125 |
|
|
126 |
|
public Object[] getColumnSelectedParameters() |
127 |
|
{ |
128 |
0 |
return new Object[] { new ComponentAddress(m_objModelSource), |
129 |
|
m_objColumn.getColumnName() }; |
130 |
|
} |
131 |
|
|
132 |
|
public void columnSelected(IRequestCycle objCycle) |
133 |
|
{ |
134 |
0 |
Object[] arrArgs = objCycle.getListenerParameters(); |
135 |
0 |
ComponentAddress objAddr = (ComponentAddress) arrArgs[0]; |
136 |
0 |
String strColumnName = (String) arrArgs[1]; |
137 |
|
|
138 |
0 |
ITableModelSource objSource = (ITableModelSource) objAddr |
139 |
|
.findComponent(objCycle); |
140 |
0 |
objSource.storeTableAction(new TableActionColumnSort(strColumnName)); |
141 |
0 |
} |
142 |
|
|
143 |
|
} |