View Javadoc

1   package org.informagen.echo.webcontainer;
2   
3   import org.informagen.echo.app.Spinner;
4   
5   import nextapp.echo.app.Component;
6   import nextapp.echo.app.update.ClientUpdateManager;
7   import nextapp.echo.app.util.Context;
8   import nextapp.echo.webcontainer.AbstractComponentSynchronizePeer;
9   import nextapp.echo.webcontainer.ServerMessage;
10  import nextapp.echo.webcontainer.Service;
11  import nextapp.echo.webcontainer.WebContainerServlet;
12  import nextapp.echo.webcontainer.service.JavaScriptService;
13  
14  public class SpinnerPeer extends AbstractComponentSynchronizePeer {
15  
16  
17      private static final String REGISTRY_KEY = "Informagen.Spinner";
18      private static final String JAVASCRIPT_PATH = "org/informagen/echo/resource/Spinner.js";
19  
20      static {
21          Service service = JavaScriptService.forResource(REGISTRY_KEY, JAVASCRIPT_PATH);
22          WebContainerServlet.getServiceRegistry().add(service);
23      }
24  
25      public SpinnerPeer() {
26          super();
27          addOutputProperty(Spinner.PROPERTY_VALUE);
28      }
29  
30      // Intialize and invoke superclass initialization -------------------------------------
31  
32      public void init(Context context, Component component) {
33          super.init(context, component);
34          ServerMessage serverMessage = (ServerMessage) context.get(ServerMessage.class);
35          serverMessage.addLibrary(REGISTRY_KEY);
36      }
37  
38      // Abstract methods from 'ComponentSynchronizePeer' -----------------------------------
39      //  Return application class and registry unique name
40      
41      public String getClientComponentType(boolean shortType) {
42          return REGISTRY_KEY;
43      }
44  
45      public Class getComponentClass() {
46          return Spinner.class;
47      }
48  
49      //-------------------------------------------------------------------------------------
50      // Override the following three methods in order to work with local component properties
51      //
52      //  - getOutputProperty - used when sending property changes to the JavaScript client
53      //  - getInputPropertyClass
54      //  - storeInputProperty
55  
56      public Object getOutputProperty(Context context, Component component,
57                                      String propertyName, int propertyIndex) {
58                          
59          if (Spinner.PROPERTY_VALUE.equals(propertyName)) 
60              return ((Spinner)component).getValue();
61          
62          return super.getOutputProperty(context, component, propertyName, propertyIndex);
63      }
64  
65  
66      public Class getInputPropertyClass(String propertyName) {
67          
68          if (Spinner.PROPERTY_VALUE.equals(propertyName)) 
69              return Integer.class;
70          
71          return super.getInputPropertyClass(propertyName);
72      }
73  
74  
75      public void storeInputProperty(Context context, Component component,
76                                     String propertyName, int propertyIndex, Object newValue) {
77  
78          ClientUpdateManager clientUpdateManager = (ClientUpdateManager) context.get(ClientUpdateManager.class);
79                                
80          if (Spinner.PROPERTY_VALUE.equals(propertyName)) 
81              clientUpdateManager.setComponentProperty(component, Spinner.PROPERTY_VALUE, newValue);
82      }
83  }