summaryrefslogtreecommitdiffstats
path: root/web-gui/live/source/class/live/Application.js
blob: 193e5063b56c427d4e6a28eef066146d6c169c3e (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ************************************************************************

   Copyright:

   License:

   Authors:

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

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

#asset(live/*)

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

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

properties: {
	online: {
		init: false,
		apply: "__applyOnline",
		check: "Boolean"
	}
},


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

members :
{
	__rpc: null,
	__call: null,
	__statusImageOn: null,
	__statusImageOff: null,
	__statusStack: null,
	__label: null,
	/**
	 * 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();
		doc.setBackgroundColor("#ffffff");

		var back = new qx.ui.basic.Image("live/back.png");
		back.setScale(true);
		doc.add(back, {left:0, top: 0});

		this.__label = new qx.ui.basic.Label("The Server is");
		doc.add(this.__label, {left:50, top: 50}); 
		this.__statusStack = new qx.ui.container.Stack();
		this.__statusStack.setAllowGrowX(false);
		this.__statusStack.setAllowGrowY(false);
		doc.add(this.__statusStack, {left:100, top: 100});
		this.__statusImageOn = new qx.ui.basic.Image("live/network-online.png");
		this.__statusStack.add(this.__statusImageOn);
		this.__statusImageOff = new qx.ui.basic.Image("live/network-offline.png");
		this.__statusStack.add(this.__statusImageOff);
		this.__statusStack.setSelection([this.__statusImageOff]);

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

		var timer = new qx.event.Timer(1000);
		timer.addListener("interval", this.__tick, this);
		timer.start();
	},
	__applyOnline: function(online) {
		if (online) {
			this.__statusStack.setSelection([this.__statusImageOn]);
			this.__label.setValue("The Server is online.");
		}
		else {
			this.__statusStack.setSelection([this.__statusImageOff]);
			this.__label.setValue("The Server is offline.");
		}
	},
	__tick : function()
	{
		if (this.__call != null) {
			this.__rpc.abort(this.__call);
			this.setOnline(false);
		}
		this.__call = this.__rpc.callAsync(
			qx.lang.Function.bind(this.__callback, this),
			"com.pengutronix.jdb.Hello.HelloWorld");
	},
	__callback: function(ret, err, id) {
		this.__call = null;
		if (err != null) {
			this.setOnline(false);
			return;
		}
		this.setOnline(true);
	}
}
});