blob: bbb7c6d47941e20c08cb5e613eda621afc8b2ff4 (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2014 Red Hat Inc..
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
package org.eclipse.swtbot.generator.framework.rules.simple;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
public class ComboSelectionRule extends GenerationSimpleRule {
private String newSelection;
private int newSelectionIndex;
private int index;
private Combo combo;
@Override
public boolean appliesTo(Event event) {
if (! (event.widget instanceof Combo)) {
return false;
}
Combo combo = (Combo)event.widget;
return event.type == SWT.Selection &&
Arrays.asList(combo.getItems()).contains(combo.getText());
}
@Override
public void initializeForEvent(Event event) {
this.combo = (Combo)event.widget;
this.newSelection = this.combo.getText();
this.newSelectionIndex = this.combo.getSelectionIndex();
this.index = WidgetUtils.getIndex(this.combo);
}
@Override
public List<String> getActions() {
List<String> actions = new ArrayList<String>();
StringBuilder res = new StringBuilder();
if (index != 0) {
res.append("bot.comboBox(" + index + ")");
} else {
res.append("bot.comboBox()");
}
res.append(".setSelection(");
if (this.newSelection != null) {
res.append('"');
res.append(this.newSelection);
res.append("\")");
} else {
res.append(this.newSelectionIndex);
res.append(")");
}
actions.add(res.toString());
return actions;
}
@Override
public List<String> getImports() {
// TODO Auto-generated method stub
return null;
}
@Override
public Combo getWidget() {
return this.combo;
}
}
|