Coverage Report - org.kuali.student.lum.lu.ui.tools.client.widgets.BrowsePanel
 
Classes in this File Line Coverage Branch Coverage Complexity
BrowsePanel
0%
0/74
0%
0/20
1.714
BrowsePanel$OnSelectedCallback
N/A
N/A
1.714
BrowsePanel$SelectButtonClickHandler
0%
0/6
N/A
1.714
 
 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.lum.lu.ui.tools.client.widgets;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.LinkedHashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 import java.util.Map.Entry;
 23  
 
 24  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 25  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 26  
 import org.kuali.student.common.ui.client.widgets.search.SelectedResults;
 27  
 import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow;
 28  
 import org.kuali.student.core.assembly.data.LookupMetadata;
 29  
 import org.kuali.student.core.assembly.data.LookupParamMetadata;
 30  
 import org.kuali.student.core.search.dto.SearchParam;
 31  
 import org.kuali.student.core.search.dto.SearchRequest;
 32  
 
 33  
 import com.google.gwt.event.dom.client.ClickEvent;
 34  
 import com.google.gwt.event.dom.client.ClickHandler;
 35  
 import com.google.gwt.user.client.ui.Composite;
 36  
 import com.google.gwt.user.client.ui.FlowPanel;
 37  
 
 38  
 public class BrowsePanel extends Composite
 39  
 {
 40  
         //Layout configuration
 41  
 
 42  
         private FlowPanel layout;
 43  
         private FlowPanel tablePanel;
 44  0
         private LookupMetadata lookupMetadata = null;
 45  0
         private SearchBackedTable searchBackedTable = null;
 46  0
         private boolean multiSelect = false;
 47  
 
 48  
         public interface OnSelectedCallback
 49  
         {
 50  
 
 51  
                 public void selected (List<String> selectedIds);
 52  
 
 53  
         }
 54  
         private OnSelectedCallback onSelectectedCallback;
 55  
 
 56  
         public BrowsePanel (LookupMetadata lookupMetadata)
 57  0
         {
 58  0
                 this.lookupMetadata = lookupMetadata;
 59  0
                 layout = new FlowPanel ();
 60  0
                 layout.addStyleName ("KS-Picker-Border");
 61  0
                 layout.addStyleName ("KS-Advanced-Search-Panel");
 62  0
                 tablePanel = new FlowPanel ();
 63  0
                 this.initWidget (layout);
 64  0
         }
 65  
 
 66  
         public Map<String, Object> parameters;
 67  
 
 68  
         public Map<String, Object> getParameters ()
 69  
         {
 70  0
                 if (parameters == null)
 71  
                 {
 72  0
                         parameters = new LinkedHashMap<String, Object> ();
 73  
                 }
 74  0
                 return parameters;
 75  
         }
 76  
 
 77  
         public void setParameters (Map<String, Object> parameters)
 78  
         {
 79  0
                 this.parameters = parameters;
 80  0
         }
 81  
 
 82  
         private Map<String, Object> getDefaultParameters ()
 83  
         {
 84  0
                 Map<String, Object> defParms = new LinkedHashMap<String, Object> ();
 85  0
                 for (LookupParamMetadata paramMeta : lookupMetadata.getParams ())
 86  
                 {
 87  0
                         if (paramMeta.getDefaultValueString () != null)
 88  
                         {
 89  0
                                 defParms.put (paramMeta.getKey (), paramMeta.getDefaultValueString ());
 90  0
                                 continue;
 91  
                         }
 92  0
                         if (paramMeta.getDefaultValueList () != null)
 93  
                         {
 94  0
                                 defParms.put (paramMeta.getKey (), paramMeta.getDefaultValueList ());
 95  
                         }
 96  
                 }
 97  0
                 return defParms;
 98  
         }
 99  
 
 100  
         public OnSelectedCallback getOnSelectectedCallback ()
 101  
         {
 102  0
                 return onSelectectedCallback;
 103  
         }
 104  
 
 105  
         public void setOnSelectectedCallback (OnSelectedCallback onSelectectedCallback)
 106  
         {
 107  0
                 this.onSelectectedCallback = onSelectectedCallback;
 108  0
         }
 109  
 
 110  
         private class SelectButtonClickHandler implements ClickHandler
 111  
         {
 112  
 
 113  
                 private OnSelectedCallback callback;
 114  
                 private SearchBackedTable searchBackedTable;
 115  
 
 116  
                 public SelectButtonClickHandler (OnSelectedCallback callback,
 117  
                                 SearchBackedTable searchBackedTable)
 118  0
                 {
 119  0
                         this.callback = callback;
 120  0
                         this.searchBackedTable = searchBackedTable;
 121  0
                 }
 122  
 
 123  
                 @Override
 124  
                 public void onClick (ClickEvent event)
 125  
                 {
 126  0
                         this.callback.selected (this.searchBackedTable.getSelectedIds ());
 127  0
                 }
 128  
 
 129  
         }
 130  
 
 131  
 
 132  
         @SuppressWarnings("unchecked")
 133  
         public void executeSearch ()
 134  
         {
 135  
 
 136  0
                 tablePanel.clear ();
 137  0
                 layout.clear ();
 138  0
                 tablePanel.setVisible (false);
 139  0
                 layout.add (tablePanel);
 140  
                 //  layout.addStyleName ("KS-Picker-Border");
 141  
                 //  layout.addStyleName (Style.BROWSE.getStyle ());
 142  0
                 searchBackedTable = new SearchBackedTable ();
 143  0
                 searchBackedTable.addStyleName ("KS-Advanced-Search-Results-Table");
 144  0
                 KSButton selectButton =
 145  
                         new KSButton ("Select",
 146  
                                         new SelectButtonClickHandler (this.onSelectectedCallback,
 147  
                                                         this.searchBackedTable));
 148  0
                 tablePanel.add (searchBackedTable);
 149  0
                 tablePanel.add (selectButton);  
 150  0
                 tablePanel.setVisible (false);
 151  
 
 152  0
                 SearchRequest searchRequest = new SearchRequest ();
 153  0
                 List<SearchParam> searchParams = new ArrayList<SearchParam> ();
 154  0
                 Map<String, Object> parms = getDefaultParameters ();
 155  0
                 parms.putAll (getParameters ());
 156  0
                 for (Entry<String, Object> entry : parms.entrySet())
 157  
                 {
 158  0
                         Object value = entry.getValue();
 159  0
                         SearchParam searchParam = new SearchParam ();
 160  0
                         searchParam.setKey (entry.getKey());
 161  0
                         if (value instanceof String){
 162  0
                                 searchParam.setValue ((String) value);
 163  
                         } else {
 164  0
                                 searchParam.setValue ((List<String>) value);
 165  
                         }
 166  0
                         searchParams.add (searchParam);
 167  0
                 }
 168  0
                 searchRequest.setParams (searchParams);
 169  0
                 searchRequest.setSearchKey (lookupMetadata.getSearchTypeId ());
 170  
 
 171  
                 //  StringBuilder builder = new StringBuilder ();
 172  
                 //  builder.append ("About to invoke search: type=");
 173  
                 //  builder.append (lookupMetadata.getSearchTypeId ());
 174  
                 //  builder.append (" with ");
 175  
                 //  builder.append (searchParams.size ());
 176  
                 //  builder.append (" parametrs.");
 177  
                 //  String comma = "\n";
 178  
                 //  for (SearchParam param : searchParams)
 179  
                 //  {
 180  
                 //   builder.append (comma);
 181  
                 //   builder.append (param.getKey ());
 182  
                 //   builder.append ("=");
 183  
                 //   builder.append (param.getValue ());
 184  
                 //  }
 185  
                 //  Window.alert (builder.toString ());
 186  
 
 187  
 
 188  0
                 searchBackedTable.performSearch (searchRequest, lookupMetadata.getResults (), lookupMetadata.
 189  
                                 getResultReturnKey ());
 190  0
                 tablePanel.setVisible (true);
 191  0
                 layout.setVisible (true);
 192  0
         }
 193  
 
 194  
         public List<String> getSelectedIds ()
 195  
         {
 196  0
                 List<String> ids = new ArrayList<String> ();
 197  0
                 if (searchBackedTable != null)
 198  
                 {
 199  0
                         ids = searchBackedTable.getSelectedIds ();
 200  
                 }
 201  0
                 return ids;
 202  
         }
 203  
 
 204  
         public List<SelectedResults> getSelectedValues ()
 205  
         {
 206  
 
 207  0
                 List<SelectedResults> selectedValues = new ArrayList<SelectedResults> ();
 208  0
                 if (searchBackedTable != null)
 209  
                 {
 210  0
                         List<ResultRow> selectedRows = searchBackedTable.getSelectedRows ();
 211  0
                         for (ResultRow row : selectedRows)
 212  
                         {
 213  0
                                 String displayKey = row.getValue (lookupMetadata.getResultDisplayKey ());
 214  0
                                 String returnKey = row.getValue (lookupMetadata.getResultReturnKey ());
 215  0
                                 selectedValues.add (new SelectedResults (displayKey, returnKey));
 216  0
                                 if (multiSelect == false)
 217  
                                 {
 218  0
                                         break;
 219  
                                 }
 220  0
                         }
 221  
                 }
 222  
 
 223  0
                 return selectedValues;
 224  
         }
 225  
 
 226  
         public boolean isMultiSelect ()
 227  
         {
 228  0
                 return multiSelect;
 229  
         }
 230  
 
 231  
         public void setMultiSelect (boolean multiSelect)
 232  
         {
 233  0
                 this.multiSelect = multiSelect;
 234  0
         }
 235  
 
 236  
 }