summaryrefslogtreecommitdiffstats
path: root/qx08/source/class/tr/ui/ActionButton.js
blob: 6b91e5dfb804837e42a94f39fe39ce7106e05576 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* ************************************************************************
#module(Tr)
************************************************************************ */

/**
 * a widget showing the Tr graph overview
 */
qx.Class.define('tr.ui.ActionButton', {
    extend : qx.ui.container.Composite,




    /*
                *****************************************************************************
                   CONSTRUCTOR
                *****************************************************************************
                */

    construct : function() {
        this.base(arguments, new qx.ui.layout.VBox);

        //    this.set({ alignX : 'left' });
        //    return this;
        var hbox = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({
            alignY  : 'middle',
            spacing : 5
        }));

        var lab1 = new qx.ui.basic.Label(this.tr("Host"));
        lab1.set({ paddingRight : 6 });
        hbox.add(lab1);
        var host = new qx.ui.form.TextField();

        host.set({
            width   : 200,
            padding : 1
        });

        hbox.add(host);
        this.__host = host;
        var lab2 = new qx.ui.basic.Label(this.tr("Delay"));

        lab2.set({
            paddingRight : 6,
            paddingLeft  : 12
        });

        hbox.add(lab2);

        var delay = new qx.ui.form.Spinner(0, 2, 60);

        delay.set({ width : 45 });
        hbox.add(delay);
        this.__delay = delay;

        var lab3 = new qx.ui.basic.Label(this.tr("Rounds"));

        lab3.set({
            paddingRight : 6,
            paddingLeft  : 12
        });

        hbox.add(lab3);
        var rounds = new qx.ui.form.Spinner(0, 20, 200);

        rounds.set({ width : 45 });

        hbox.add(rounds);
        this.__rounds = rounds;

        var button = new qx.ui.form.Button('');
        this.__button = button;

        button.set({
            marginLeft : 10,
            width      : 60,
            padding    : 2,
            center     : true
        });

        hbox.add(button);

        var config = new qx.ui.form.Button(this.tr("Config ..."));
        hbox.add(config);

        config.addListener('execute', function(e) {
            qx.event.message.Bus.dispatch('tr.config', 'open');
        });

        this.add(hbox);

        var info = new qx.ui.basic.Atom();

        info.set({
            marginTop       : 3,
            padding         : 3,
            textColor       : 'red',
            backgroundColor : '#f0f0f0',
            visibility      : 'hidden'
        });

        qx.event.message.Bus.subscribe('tr.info', this.__set_info, this);
        this.add(info);
        this.__info = info;

        qx.event.message.Bus.subscribe('tr.status', this.__set_status, this);
        qx.event.message.Bus.dispatch('tr.status', 'stopped');

        var start_trace = function(event) {
            qx.event.message.Bus.dispatch('tr.cmd', {
                action : button.getUserData('action'),
                host   : host.getValue(),
                delay  : delay.getValue(),
                rounds : rounds.getValue()
            });
        };

        host.addListener('keydown', function(e) {
            if (e.getKeyIdentifier() == 'Enter') {
                start_trace();
            }
        });

        // host.addListener('execute', start_trace);
        button.addListener('execute', start_trace);

        var history = qx.bom.History.getInstance();

        var history_action = function(event) {
            var targ = event.getData();
            host.setValue(targ);
            history.addToHistory(targ, 'SmokeTrace to ' + targ);
            start_trace();
        };

        history.addListener('request', history_action);

        // if we got called with a host on the commandline
        var initial_host = qx.bom.History.getInstance().getState();

        if (initial_host) {
            host.setValue(initial_host);
            history.addToHistory(initial_host, 'SmokeTrace to ' + initial_host);

            // dispatch this task once all the initializations are done
            qx.event.Timer.once(start_trace, this, 0);
        }
    },

    members : {
        __host : null,
        __delay : null,
        __rounds : null,
        __button : null,
        __info : null,


        /**
         * TODOC
         *
         * @type member
         * @param e {Event} TODOC
         * @return {void} 
         */
        __set_info : function(e) {
            this.__info.set({
                label      : e.getData(),
                visibility : 'visible'
            });
        },


        /**
         * TODOC
         *
         * @type member
         * @param m {var} TODOC
         * @return {void} 
         */
        __set_status : function(m) {
            var host = this.__host;
            var rounds = this.__rounds;
            var delay = this.__delay;
            var button = this.__button;
            var action = button.getUserData('action');

            // this.debug(m.getData());
            switch(m.getData())
            {
                case 'starting':
                    if (action == 'go') {
                        button.setLabel(this.tr("Starting"));
                        this.__info.setVisibility('hidden');

                        // border:'dark-shadow',
                        button.setEnabled(false);
                        host.setEnabled(false);
                        rounds.setEnabled(false);
                        delay.setEnabled(false);
                    }

                    break;

                case 'stopping':
                    if (action == 'stop') {
                        button.setLabel(this.tr("Stopping"));
                        button.setEnabled(false);
                        host.setEnabled(false);
                        rounds.setEnabled(false);
                        delay.setEnabled(false);
                    }

                    break;

                case 'stopped':
                    button.setUserData('action', 'go');
                    button.setLabel(this.tr("Go"));
                    button.setEnabled(true);
                    host.setEnabled(true);
                    rounds.setEnabled(true);
                    delay.setEnabled(true);
                    break;

                case 'started':
                    button.setUserData('action', 'stop');
                    button.setLabel(this.tr("Stop"));
                    button.setEnabled(true);
                    host.setEnabled(false);
                    rounds.setEnabled(false);
                    delay.setEnabled(false);
                    break;

                default:
                    this.error('Unknown Status Message: ' + m.getData());
            }
        }
    }
});