Clover Coverage Report - Kuali Student 1.2-M5-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Aug 29 2011 05:04:27 EDT
../../../../../../../../img/srcFileCovDistChart0.png 42% of files have more coverage
72   199   19   5.14
10   154   0.26   14
14     1.36  
1    
 
  TempSearchBackedTable       Line # 47 72 0% 19 96 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.ui.client.widgets.search;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20    import java.util.Set;
21   
22    import org.kuali.student.common.assembly.data.LookupResultMetadata;
23    import org.kuali.student.common.search.dto.SearchRequest;
24    import org.kuali.student.common.search.dto.SearchResult;
25    import org.kuali.student.common.search.dto.SearchResultCell;
26    import org.kuali.student.common.search.dto.SearchResultRow;
27    import org.kuali.student.common.ui.client.application.Application;
28    import org.kuali.student.common.ui.client.application.KSAsyncCallback;
29    import org.kuali.student.common.ui.client.service.CachingSearchService;
30    import org.kuali.student.common.ui.client.service.SearchRpcServiceAsync;
31    import org.kuali.student.common.ui.client.widgets.pagetable.GenericTableModel;
32    import org.kuali.student.common.ui.client.widgets.pagetable.PagingScrollTableBuilder;
33    import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow;
34    import org.kuali.student.common.ui.client.widgets.searchtable.SearchColumnDefinition;
35   
36    import com.google.gwt.core.client.GWT;
37    import com.google.gwt.gen2.table.client.AbstractColumnDefinition;
38    import com.google.gwt.gen2.table.client.PagingOptions;
39    import com.google.gwt.gen2.table.client.PagingScrollTable;
40    import com.google.gwt.gen2.table.client.AbstractScrollTable.ResizePolicy;
41    import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
42    import com.google.gwt.user.client.Window;
43    import com.google.gwt.user.client.ui.Composite;
44    import com.google.gwt.user.client.ui.Label;
45    import com.google.gwt.user.client.ui.VerticalPanel;
46   
 
47    public class TempSearchBackedTable extends Composite{
48   
49    private List<ResultRow> resultRows = new ArrayList<ResultRow>();
50    private List<AbstractColumnDefinition<ResultRow, ?>> columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>();
51    private GenericTableModel<ResultRow> tableModel = new GenericTableModel<ResultRow>(resultRows);
52    private PagingScrollTableBuilder<ResultRow> builder = new PagingScrollTableBuilder<ResultRow>();
53    private String resultIdColumnKey;
54    protected PagingScrollTable<ResultRow> pagingScrollTable;
55    private VerticalPanel layout = new VerticalPanel();
56    private PagingOptions pagingOptions;
57   
58    private SearchRpcServiceAsync searchRpcServiceAsync = CachingSearchService.getSearchService();
59   
 
60  0 toggle private PagingOptions createPagingOptions(PagingScrollTable<ResultRow> pagingScrollTable) {
61  0 PagingOptions pagingOptions = new PagingOptions(pagingScrollTable);
62  0 pagingOptions.setPixelSize(pagingScrollTable.getOffsetWidth(), pagingOptions.getOffsetHeight());
63  0 return pagingOptions;
64    }
65   
 
66  0 toggle public TempSearchBackedTable(){
67  0 super();
68  0 redraw();
69  0 layout.setWidth("100%");
70  0 initWidget(layout);
71    }
72   
 
73  0 toggle public void clearTable(){
74  0 resultRows.clear();
75  0 this.redraw();
76    }
77   
 
78  0 toggle public void removeSelected(){
79  0 for(ResultRow r: getSelectedRows()){
80  0 resultRows.remove(r);
81    }
82  0 this.redraw();
83    }
84   
 
85  0 toggle public void performSearch(SearchRequest searchRequest, List<LookupResultMetadata> listResultMetadata, String resultIdKey){
86   
87  0 initializeTable(listResultMetadata, resultIdKey);
88   
89  0 searchRequest.setNeededTotalResults(false);
90   
91  0 if(pagingScrollTable != null){
92  0 pagingScrollTable.setEmptyTableWidget(new Label("Processing Search..."));
93    }
94   
95  0 searchRpcServiceAsync.search(searchRequest, new KSAsyncCallback<SearchResult>(){
96   
 
97  0 toggle @Override
98    public void handleFailure(Throwable cause) {
99  0 GWT.log("Failed to perform search", cause); //FIXME more detail info here
100  0 Window.alert("Failed to perform search");
101    }
102   
 
103  0 toggle @Override
104    public void onSuccess(SearchResult results) {
105   
106  0 resultRows.clear();
107  0 if(results != null){
108  0 for (SearchResultRow r: results.getRows()){
109  0 ResultRow theRow = new ResultRow();
110  0 for(SearchResultCell c: r.getCells()){
111  0 if(c.getKey().equals(resultIdColumnKey)){
112  0 theRow.setId(c.getValue());
113    }
114  0 theRow.setValue(c.getKey(), c.getValue());
115    }
116  0 resultRows.add(theRow);
117    }
118    }
119  0 redraw();
120    }
121    });
122    }
123   
 
124  0 toggle public void initializeTable(List<LookupResultMetadata> listResultMetadata, String resultIdKey) {
125  0 clearTable();
126   
127  0 this.resultIdColumnKey = resultIdKey;
128  0 builder = new PagingScrollTableBuilder<ResultRow>();
129  0 builder.tablePixelSize(400, 300);
130   
131  0 columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>();
132  0 for (LookupResultMetadata r: listResultMetadata){
133  0 String header = Application.getApplicationContext().getUILabel("", null, null, r.getName());
134  0 String key = r.getKey();
135  0 if(!r.isHidden()){
136  0 columnDefs.add(new SearchColumnDefinition(header, key));
137    }
138    }
139  0 if(columnDefs.size() == 1){
140    //FIXME auto adjusting width to fill table does not work with 1 column bug in incubator???
141  0 columnDefs.get(0).setMinimumColumnWidth(370);
142    }
143  0 builder.columnDefinitions(columnDefs);
144  0 tableModel.setColumnDefs(columnDefs);
145   
146  0 redraw();
147    }
148   
 
149  0 toggle public void redraw(){
150  0 tableModel.setRows(resultRows);
151  0 pagingScrollTable = builder.build(tableModel); // FIXME do we really need to recreate the table for every refresh?
152  0 pagingScrollTable.setResizePolicy(ResizePolicy.FILL_WIDTH);
153  0 pagingOptions = createPagingOptions(pagingScrollTable);
154  0 layout.clear();
155  0 layout.add(pagingOptions);
156  0 layout.add(pagingScrollTable);
157  0 pagingScrollTable.reloadPage(); //FIXME Undesirable solution to work with GWT 2.0
158  0 pagingScrollTable.fillWidth();
159    }
160   
 
161  0 toggle public void addSelectionHandler(RowSelectionHandler selectionHandler){
162  0 pagingScrollTable.getDataTable().addRowSelectionHandler(selectionHandler);
163    }
164   
 
165  0 toggle public List<ResultRow> getSelectedRows(){
166  0 List<ResultRow> rows = new ArrayList<ResultRow>();
167  0 Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows();
168  0 for(Integer i: selectedRows){
169  0 rows.add(pagingScrollTable.getRowValue(i));
170    }
171  0 return rows;
172    }
173   
 
174  0 toggle public List<String> getSelectedIds(){
175  0 List<String> ids = new ArrayList<String>();
176  0 Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows();
177  0 for(Integer i: selectedRows){
178  0 ids.add(pagingScrollTable.getRowValue(i).getId());
179    }
180  0 return ids;
181    }
182   
 
183  0 toggle public List<String> getAllIds(){
184  0 List<String> ids = new ArrayList<String>();
185  0 for(ResultRow r: resultRows){
186  0 ids.add(r.getId());
187    }
188  0 return ids;
189    }
190   
 
191  0 toggle public List<ResultRow> getAllRows(){
192  0 List<ResultRow> rows = new ArrayList<ResultRow>();
193  0 for(ResultRow r: resultRows){
194  0 rows.add(r);
195    }
196  0 return rows;
197    }
198   
199    }