summaryrefslogtreecommitdiffstats
path: root/web-gui/hello-world/source/class/hello_world/Application.js
blob: 1a7e450681ce8b921a5bbada2ede30a2f4ce1382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************

   Copyright:

   License:

   Authors:

************************************************************************ */

/* ************************************************************************

#asset(hello_world/*)

************************************************************************ */

/**
 * This is the main application class of your custom application "hello_world"
 */
qx.Class.define("hello_world.Application",
{
  extend : qx.application.Standalone,



  /*
  *****************************************************************************
     MEMBERS
  *****************************************************************************
  */

  members :
  {
    /**
     * This method contains the initial application code and gets called 
     * during startup of the application
     * 
     * @lint ignoreDeprecated(alert)
     */
    main : function()
    {
      // Call super class
      this.base(arguments);

      // Enable logging in debug variant
      if (qx.core.Variant.isSet("qx.debug", "on"))
      {
        // support native logging capabilities, e.g. Firebug for Firefox
        qx.log.appender.Native;
        // support additional cross-browser console. Press F7 to toggle visibility
        qx.log.appender.Console;
      }

      /*
      -------------------------------------------------------------------------
        Below is your actual application code...
      -------------------------------------------------------------------------
      */

      // Document is the application root
      var doc = this.getRoot();

      var core = new qx.ui.container.Composite(new qx.ui.layout.Grid());
      doc.add(core, {left: 50, top: 50});
      core.getLayout().setSpacing(10);
      core.getLayout().setColumnAlign(0, "left", "middle");

      core.add( new qx.ui.basic.Label("RPC Hello World:"), {row: 0, column: 0});
      var helloLabel = new qx.ui.basic.Label("<waiting for hello>");
      core.add(helloLabel, {row: 0, column: 1});

      core.add( new qx.ui.basic.Label("Send Text:"), {row: 1, column: 0});
      var echoEdit = new qx.ui.form.TextField();
      echoEdit.setWidth(200);
      core.add(echoEdit, {row: 1, column: 1});

      var echoButton = new qx.ui.form.Button("Echo");
      core.add(echoButton, {row: 1, column: 2});

      core.add( new qx.ui.basic.Label("RPC Echo Receive:"), {row: 2, column: 0});
      var echoLabel = new qx.ui.basic.Label("<waiting for echo>");
      core.add(echoLabel, {row: 2, column: 1});

      var rpc = new qx.io.remote.Rpc("http://localhost:8080/rpc", "com.pengutronix.jdb.Hello|/");

      // synchronous RPC call. callSync() throws an exception on error
      try {
        var val = rpc.callSync("com.pengutronix.jdb.Hello.HelloWorld");
        helloLabel.setValue(val);
      }
      catch (error) {
        helloLabel.setValue("Error: " + error);
      }

      // Add an event listener
      echoButton.addListener("execute", function(e) {
        var text = echoEdit.getValue();
        if (text == null)
          text = "";
        var handler = function(result, error) {
           if (error == null) {
             echoLabel.setValue(result);
            }
            else {
              echoLabel.setValue("Error: " + error);
            }
        }
        // asynchronous RPC call. The handler will be called with result or error == null
        rpc.callAsync(handler, "com.pengutronix.jdb.Hello.Echo", "s", text);
      });
    }
  }
});