View Javadoc

1   package org.kuali.student.common.ui.client.widgets;
2   
3   import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
4   
5   import com.google.gwt.event.logical.shared.ValueChangeEvent;
6   import com.google.gwt.event.logical.shared.ValueChangeHandler;
7   import com.google.gwt.user.client.ui.Composite;
8   import com.google.gwt.user.client.ui.HasText;
9   /**
10   * CheckBoxTextArea is for linking a master text area with a slave text area.
11   * A check box is used to control when to use the text from master or from 
12   * slave text area.
13   * 
14   * 
15   * */
16  public class CheckBoxTextArea extends Composite implements HasText{
17      HasText master;
18      KSTextArea slave = new KSTextArea();
19      KSCheckBox checkBox = new KSCheckBox();
20      public CheckBoxTextArea(HasText master, String checkBoxText){
21          this.master = master;
22          VerticalFlowPanel flowPanel = new VerticalFlowPanel();
23          
24          flowPanel.add(checkBox);
25          flowPanel.add(slave);
26          super.initWidget(flowPanel);
27          
28          checkBox.setStyleName("CheckBoxTextArea-CheckBox");
29          slave.setStyleName("CheckBoxTextArea-TextArea");
30          
31          
32          checkBox.addValueChangeHandler(new ValueChangeHandler(){
33              @Override
34              public void onValueChange(ValueChangeEvent event) {
35                 if(checkBox.getValue() == true){
36                     slave.setVisible(false);
37                 }else{
38                     slave.setVisible(true);
39                 }
40              }
41          });
42          checkBox.setValue(true);
43          checkBox.setText(checkBoxText);
44      }
45      @Override
46      public String getText() {
47          if(checkBox.getValue() == true){
48              return master.getText();
49          }else{
50              return slave.getText();
51          }
52      }
53  
54      @Override
55      public void setText(String text) {
56          if(master.getText().equals(text)){
57              checkBox.setValue(true);
58          }else{
59              checkBox.setValue(false);
60              slave.setText(text);
61          }
62      }
63  }