summaryrefslogtreecommitdiff
path: root/src/plugins/android/src/com/motorola/studio/android/monkey/options/MonkeyOption.java
blob: 54963b4745e4eff05e103e05dfead1d373e94883 (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.motorola.studio.android.monkey.options;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;

/**
 * Bean that represents an monkey option
 */
public class MonkeyOption
{

    // Checked status (whether the monkey options is being used or not)
    private boolean checked;

    // Widget that represents the checked status in the UI
    private Widget checkedWidget;

    // monkey option name
    private String name;

    // monkey option user-friendly name
    private String userFriendlyName;

    // monkey option description (user-friendly description)
    private String description;

    // monkey option type (which type of values that the monkey option accepts)
    private int type;

    // monkey option type details (details of the values that the monkey option accepts)
    private String typeDetails;

    // monkey option value (monkey option configured value)
    private String value;

    // Widget that represents the monkey option value in the UI
    private Widget valueWidget;

    // monkey option predefined values (list of values the monkey option accepts)
    private List<String> preDefinedValues;

    /**
     * Constructor
     * 
     * @param name
     * @param type
     */
    public MonkeyOption(String name, int type)
    {
        this.checked = false;
        this.name = name;
        this.type = type;
        this.value = "";
        this.preDefinedValues = new ArrayList<String>();
    }

    /**
     * Get monkey option name
     * 
     * @return monkey option name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Set monkey option name
     * 
     * @param name monkey option name
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * Get monkey option user-friendly name
     * 
     * @return
     */
    public String getUserFriendlyName()
    {
        return userFriendlyName;
    }

    /**
     * Set monkey option user-friendly name
     * 
     * @param userFriendlyName
     */
    public void setUserFriendlyName(String userFriendlyName)
    {
        this.userFriendlyName = userFriendlyName;
    }

    /**
     * Get monkey option type
     * 
     * @return monkey option type
     */
    public int getType()
    {
        return type;
    }

    /**
     * Set monkey option type
     * 
     * @param type monkey option type
     */
    public void setType(int type)
    {
        this.type = type;
    }

    /**
     * Get monkey option value
     * 
     * @return monkey option value
     */
    public String getValue()
    {
        return value;
    }

    /**
     * Set monkey option value
     * 
     * @param value monkey option value
     */
    public void setValue(String value)
    {
        this.value = value;
    }

    /**
     * Get monkey option pre-defined values
     * 
     * @return monkey option pre-defined values
     */
    public List<String> getPreDefinedValues()
    {
        return preDefinedValues;
    }

    /**
     * Set monkey option pre-defined values
     * 
     * @param preDefinedValues monkey option pre-defined values
     */
    public void setPreDefinedValues(List<String> preDefinedValues)
    {
        this.preDefinedValues = preDefinedValues;
    }

    /**
     * Check if the monkey option is being used
     * 
     * @return true if the monkey option is being used, false otherwise
     */
    public boolean isChecked()
    {
        return checked;
    }

    /**
     * Set that the monkey option is being used or not
     * 
     * @param checked true if the monkey option is being used, false otherwise
     */
    public void setChecked(boolean checked)
    {
        this.checked = checked;
    }

    /**
     * Get monkey option description
     * 
     * @return monkey option description
     */
    public String getDescription()
    {
        return description;
    }

    /**
     * Set monkey option description
     * 
     * @param description monkey option description
     */
    public void setDescription(String description)
    {
        this.description = description;
    }

    /**
     * Get monkey option type details
     * 
     * @return monkey option type details
     */
    public String getTypeDetails()
    {
        return typeDetails;
    }

    /**
     * Get monkey option type details
     * 
     * @param typeDetails valuable information for validating if the value assigned is correct
     */
    public void setTypeDetails(String typeDetails)
    {
        this.typeDetails = typeDetails;
    }

    /**
     * Get the widget that represents the checked status in the UI
     * 
     * @return widget that represents the checked status in the UI
     */
    public Widget getCheckedWidget()
    {
        return checkedWidget;
    }

    /**
     * Set the widget that represents the checked status in the UI
     * 
     * @param checkedWidget widget that represents the checked status in the UI
     */
    public void setCheckedWidget(Widget checkedWidget)
    {
        this.checkedWidget = checkedWidget;
    }

    /**
     * Get the widget that represents the monkey option value in the UI
     * 
     * @return widget that represents the monkey option value in the UI
     */
    public Widget getValueWidget()
    {
        return valueWidget;
    }

    /**
     * Set the widget that represents the monkey option value in the UI
     * 
     * @param valueWidget widget that represents the monkey option value in the UI
     */
    public void setValueWidget(Widget valueWidget)
    {
        this.valueWidget = valueWidget;
    }

    /**
     * Update the widgets that represent this monkey options in the UI
     * by changing their state to match the current values for checked and value
     */
    public void updateUI()
    {
        if ((checkedWidget != null) && !checkedWidget.isDisposed())
        {
            ((Button) this.checkedWidget).setSelection(this.checked);
        }
        if ((valueWidget != null) && !checkedWidget.isDisposed())
        {
            if (this.valueWidget instanceof Text)
            {
                ((Text) this.valueWidget).setText(this.value);
            }
            else if (this.valueWidget instanceof Combo)
            {
                if ((this.value == null) || (this.value.equals("")))
                {
                    ((Combo) this.valueWidget).deselectAll();
                }
                else
                {
                    ((Combo) this.valueWidget).select(getPreDefinedValues().indexOf(this.value));
                }
            }
        }
    }
}