View Javadoc

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.List;
19  
20  import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
21  import org.kuali.student.common.ui.client.mvc.Callback;
22  import org.kuali.student.common.ui.client.widgets.KSLightBox;
23  import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations;
24  import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.ButtonEnum;
25  import org.kuali.student.common.ui.client.widgets.field.layout.button.ActionCancelGroup;
26  import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup;
27  import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
28  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
29  
30  public class AdvancedSearchWindow {
31      
32      private VerticalFlowPanel layout = new VerticalFlowPanel();
33  	private KSLightBox dialog;
34  	private SearchPanel searchPanel;
35  		
36  	private ActionCancelGroup actionCancelButtons = new ActionCancelGroup(ButtonEnumerations.SearchCancelEnum.SEARCH, ButtonEnumerations.SearchCancelEnum.CANCEL);   
37  
38      public List<SelectedResults> getSelectedValues() {
39          return searchPanel.getSelectedValues();
40      }
41  
42      public SearchRequestInfo getSearchRequest() {
43          return searchPanel.getSearchRequest();
44      }
45      
46      public String getSelectedLookupName() {
47          return searchPanel.getSelectedLookupName();
48      }
49  
50  	public AdvancedSearchWindow(String title, SearchPanel panel){
51  	    
52  	    actionCancelButtons.addStyleName("KS-Advanced-Search-Buttons");
53  	    addCancelCompleteCallback(null);
54          searchPanel = panel;
55          searchPanel.setActionCancelButtonGroup(actionCancelButtons);
56          searchPanel.setupButtons();
57          
58  	    //dialog = new KSLightBox(title);	 
59  	    dialog = new KSLightBox();	 
60  	    layout.addStyleName("KS-Advanced-Search-Window");
61  	    SectionTitle sectionTitle = SectionTitle.generateH2Title(title);
62  	    dialog.setNonCaptionHeader(sectionTitle);
63  		layout.add(panel);
64  		layout.add(actionCancelButtons);
65  		dialog.setMaxHeight(620);
66  		ButtonGroup buttons = panel.getButtons();
67  		buttons.removeFromParent();
68  		dialog.addButtonGroup(buttons);
69  	}
70  	
71      public void show(){
72          searchPanel.setupSearch();
73          dialog.setWidget(layout);
74          dialog.setMaxHeight(600);
75          dialog.show();
76      }
77  
78      public void hide(){
79          dialog.hide();
80      }
81      
82      public void addCancelCompleteCallback(final Callback<Boolean> callback){
83          //actionCompletedCallbacks.add(callback);
84          actionCancelButtons.addCallback(new Callback<ButtonEnumerations.ButtonEnum>(){
85               @Override
86              public void exec(ButtonEnum result) {
87                   if (result == ButtonEnumerations.SearchCancelEnum.CANCEL) {
88                       if (callback != null) {
89                           callback.exec(true);   
90                       }
91                       dialog.hide();
92                   }
93              }
94          });
95      }    
96      
97      public void addActionCompleteCallback(Callback<Boolean> callback){
98          searchPanel.addActionCompleteCallback(callback);
99      }    
100 }