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.lum.common.client.lo;
17  
18  import java.util.List;
19  
20  import org.kuali.student.common.assembly.data.Data;
21  import org.kuali.student.common.ui.client.widgets.KSLabel;
22  import org.kuali.student.common.ui.client.widgets.KSTextArea;
23  import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
24  import org.kuali.student.common.ui.client.widgets.list.HasSelectionChangeHandlers;
25  import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
26  import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
27  import org.kuali.student.lum.lo.dto.LoCategoryInfo;
28  
29  import com.google.gwt.event.logical.shared.ValueChangeEvent;
30  import com.google.gwt.event.logical.shared.ValueChangeHandler;
31  import com.google.gwt.event.shared.HandlerRegistration;
32  import com.google.gwt.user.client.ui.HorizontalPanel;
33  
34  /**
35   * This is a description of what this class does - hjohnson don't forget to fill this in. 
36   * 
37   * @author Kuali Student Team (kuali-student@googlegroups.com)
38   *
39   */
40  public class LOPicker extends HorizontalPanel implements HasSelectionChangeHandlers{
41  	KSLabel countLabel = new KSLabel();
42      KSTextArea loTextArea;
43      VerticalFlowPanel vp = new VerticalFlowPanel();
44      LOCategoryBuilder loCategoryBuilder;
45      Data metaInfoData; // temporary storage of metaInfo data this is needed when LO is updated
46      public LOPicker(String messageGroup, String type, String state, String loRepoKey, int maxLength) {
47          super();
48          this.loTextArea = new KSTextArea(countLabel, maxLength);
49          loCategoryBuilder = new LOCategoryBuilder(messageGroup, type, state, loRepoKey);
50          loTextArea.removeStyleName("ks-form-module-elements");
51          loTextArea.addStyleName("KS-LOTextArea");
52          countLabel.addStyleName("ks-form-module-elements-help-text");
53          countLabel.addStyleName("loText-count-label");
54          vp.add(loTextArea);
55          vp.add(countLabel);
56          super.add(vp);
57          super.add(loCategoryBuilder);
58          
59          loTextArea.addValueChangeHandler(new ValueChangeHandler<String>(){
60  			public void onValueChange(ValueChangeEvent<String> event) {
61  				fireChangeEvent();
62  			}        	
63          });
64          
65          loCategoryBuilder.addValueChangeHandler(new ValueChangeHandler<List<LoCategoryInfo>>(){
66  			public void onValueChange(
67  					ValueChangeEvent<List<LoCategoryInfo>> event) {
68  				fireChangeEvent();
69  			}        	
70          });
71      }
72      public void setLOCategories(List<LoCategoryInfo> categories){
73          loCategoryBuilder.setValue(categories);
74      }
75      public List<LoCategoryInfo> getLoCategories(){
76          return loCategoryBuilder.getValue();
77      }
78      public String getLOText(){
79          return this.loTextArea.getText();
80      }
81      public void setLOText(String value){
82          this.loTextArea.setText(value);
83      }
84      public Data getMetaInfoData() {
85          return metaInfoData;
86      }
87      public void setMetaInfoData(Data metaInfoData) {
88          this.metaInfoData = metaInfoData;
89      }
90  	
91      @Override
92  	public HandlerRegistration addSelectionChangeHandler(SelectionChangeHandler handler) {
93      	return addHandler(handler, SelectionChangeEvent.getType());
94      }
95      
96      public boolean hasChangeHandler(){
97      	return this.getHandlerCount(SelectionChangeEvent.getType()) > 0;
98      }
99  	
100     private void fireChangeEvent(){
101     	SelectionChangeEvent.fire(this);
102     }
103     @Override
104     protected void onEnsureDebugId(String baseID) {
105         super.onEnsureDebugId(baseID);
106         loTextArea.ensureDebugId(baseID);
107         loCategoryBuilder.ensureDebugId(baseID);
108     }
109     
110     
111 }