View Javadoc

1   package org.kuali.student.common.ui.client.widgets;
2   
3   import com.google.gwt.event.dom.client.HasKeyUpHandlers;
4   import com.google.gwt.event.dom.client.KeyUpEvent;
5   import com.google.gwt.event.dom.client.KeyUpHandler;
6   import com.google.gwt.user.client.ui.HasText;
7   /**
8    * TextLinkageHelper is used to link two text fields. As you type in one field the text 
9    * appears on the linked field.
10   * 
11   * */
12  public class TextLinkageHelper {
13      static String masterString;
14      public static void link(final HasText master, final HasText slave) {
15          masterString = master.getText();
16          if (master instanceof HasKeyUpHandlers) {
17                HasKeyUpHandlers masterTextBox = (HasKeyUpHandlers) master;
18                masterTextBox.addKeyUpHandler(new KeyUpHandler() {
19                  @Override
20                  public void onKeyUp(KeyUpEvent event) {
21                        if(masterString.equals(slave.getText()) 
22                                ||"".equals(slave.getText()) ){
23                            masterString = master.getText();
24                            slave.setText(masterString);
25                        }
26                  }
27                });
28            }
29        } 
30  }