View Javadoc

1   package org.informagen.echo.webcontainer;
2   
3   // Custom Component
4   import org.informagen.echo.app.RegExTextField;
5   
6   // Echo Component Framework
7   import nextapp.echo.app.Component;
8   import nextapp.echo.app.update.ClientUpdateManager;
9   import nextapp.echo.app.util.Context;
10  
11  // Echo WebContainer Framework
12  import nextapp.echo.webcontainer.Service;
13  import nextapp.echo.webcontainer.ServerMessage;
14  import nextapp.echo.webcontainer.WebContainerServlet;
15  import nextapp.echo.webcontainer.service.JavaScriptService;
16  
17  // Custom component's superclass
18  import org.informagen.echo.webcontainer.ActiveTextFieldPeer;
19  
20  
21  public class RegExTextFieldPeer extends ActiveTextFieldPeer {
22  
23      private static final String REGISTRY_KEY = "Informagen.RegExTextField";
24      private static final String JAVASCRIPT_PATH = "org/informagen/echo/resource/RegExTextField.js";
25  
26      static {
27          Service service = JavaScriptService.forResource(REGISTRY_KEY, JAVASCRIPT_PATH);
28          WebContainerServlet.getServiceRegistry().add(service);
29      }
30  
31      public RegExTextFieldPeer() {
32          super();
33          
34          // This essentially registers 'PropertyChange' events with the JavaScript client
35          addOutputProperty(RegExTextField.PROPERTY_FILTER);
36          addOutputProperty(RegExTextField.PROPERTY_REGEX);
37      }
38  
39  
40      public void init(Context context, Component component) {
41          super.init(context, component);
42          ServerMessage serverMessage = (ServerMessage) context.get(ServerMessage.class);
43          serverMessage.addLibrary(REGISTRY_KEY);
44      }
45  
46      // Abstract methods from 'ComponentSynchronizePeer' -----------------------------------
47      //  Return application class and registry unique name
48      
49     public Class getComponentClass() {
50          return RegExTextField.class;
51      }
52  
53      public String getClientComponentType(boolean shortType) {
54          return REGISTRY_KEY;
55      }
56   
57      /**
58       *  The WebContainer will invoke this peer method in order to respond to 'PropertyChange'
59       *      events in the Java which need to be passed to the JavaScript client
60       */
61   
62      public Object getOutputProperty(Context context, Component component, String propertyName, int propertyIndex) {
63          
64          if (propertyName.equals(RegExTextField.PROPERTY_FILTER)) 
65              return ((RegExTextField)component).getFilter();
66          else if (propertyName.equals(RegExTextField.PROPERTY_REGEX))
67              return ((RegExTextField)component).getRegEx();
68          else 
69              return super.getOutputProperty(context, component, propertyName, propertyIndex);
70      }
71  }