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.Tapestry; |
21 |
|
import org.apache.tapestry.contrib.table.components.Table; |
22 |
|
import org.apache.tapestry.contrib.table.components.TableColumns; |
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.ITableModelSource; |
26 |
|
import org.apache.tapestry.contrib.table.model.ITableRendererListener; |
27 |
|
import org.apache.tapestry.contrib.table.model.ITableSortingState; |
28 |
|
import org.apache.tapestry.event.PageDetachListener; |
29 |
|
import org.apache.tapestry.event.PageEvent; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
public abstract class SimpleTableColumnSortImage extends BaseComponent |
38 |
|
implements PageDetachListener, ITableRendererListener |
39 |
|
{ |
40 |
|
|
41 |
|
private ITableModelSource m_objModelSource; |
42 |
|
private ITableColumn m_objColumn; |
43 |
|
|
44 |
|
public SimpleTableColumnSortImage() |
45 |
0 |
{ |
46 |
0 |
init(); |
47 |
0 |
} |
48 |
|
|
49 |
|
public abstract Table getTable(); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
public void pageDetached(PageEvent arg0) |
55 |
|
{ |
56 |
0 |
init(); |
57 |
0 |
} |
58 |
|
|
59 |
|
private void init() |
60 |
|
{ |
61 |
0 |
m_objModelSource = null; |
62 |
0 |
m_objColumn = null; |
63 |
0 |
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
public void initializeRenderer(IRequestCycle objCycle, |
70 |
|
ITableModelSource objSource, ITableColumn objColumn, Object objRow) |
71 |
|
{ |
72 |
0 |
m_objModelSource = objSource; |
73 |
0 |
m_objColumn = objColumn; |
74 |
0 |
} |
75 |
|
|
76 |
|
public void prepareForRender(IRequestCycle cycle) |
77 |
|
{ |
78 |
0 |
if (getTable()==null) |
79 |
0 |
throw Tapestry.createRequiredParameterException(this, "table"); |
80 |
|
|
81 |
0 |
m_objModelSource = getTable(); |
82 |
0 |
m_objColumn = getTable().getTableColumn(); |
83 |
|
|
84 |
0 |
} |
85 |
|
|
86 |
|
|
87 |
|
public ITableModel getTableModel() |
88 |
|
{ |
89 |
0 |
return m_objModelSource.getTableModel(); |
90 |
|
} |
91 |
|
|
92 |
|
public IAsset getSortImage() |
93 |
|
{ |
94 |
|
IAsset objImageAsset; |
95 |
|
|
96 |
0 |
IRequestCycle objCycle = getPage().getRequestCycle(); |
97 |
0 |
ITableSortingState objSortingState = getTableModel().getSortingState(); |
98 |
0 |
if (objSortingState.getSortOrder() == ITableSortingState.SORT_ASCENDING) |
99 |
|
{ |
100 |
0 |
objImageAsset = (IAsset) objCycle |
101 |
|
.getAttribute(TableColumns.TABLE_COLUMN_ARROW_UP_ATTRIBUTE); |
102 |
0 |
if (objImageAsset == null) objImageAsset = getAsset("sortUp"); |
103 |
|
} |
104 |
|
else |
105 |
|
{ |
106 |
0 |
objImageAsset = (IAsset) objCycle |
107 |
|
.getAttribute(TableColumns.TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE); |
108 |
0 |
if (objImageAsset == null) objImageAsset = getAsset("sortDown"); |
109 |
|
} |
110 |
|
|
111 |
0 |
return objImageAsset; |
112 |
|
} |
113 |
|
|
114 |
|
public boolean getIsSorted() |
115 |
|
{ |
116 |
0 |
ITableSortingState objSortingState = getTableModel().getSortingState(); |
117 |
0 |
String strSortColumn = objSortingState.getSortColumn(); |
118 |
0 |
return m_objColumn.getColumnName().equals(strSortColumn); |
119 |
|
} |
120 |
|
} |