Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 73f14f64f8e4373eeecb81550cf09b9b72c4abe3 (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
/*******************************************************************************
 * Copyright (c) 2012 Red Hat Inc..
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Mickael Istria (Red Hat) - initial API and implementation
 *******************************************************************************/
package org.eclipse.swtbot.generator.framework.rules.simple;

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 CComboSelectionRule extends GenerationSimpleRule {

	private Combo combo;
	private String newSelection;
	private int newSelectionIndex;

	@Override
	public boolean appliesTo(Event event) {
		return event.widget instanceof Combo && event.type == SWT.Selection;
	}

	@Override
	public void initializeForEvent(Event event) {
		this.combo = (Combo)event.widget;
		this.newSelection = this.combo.getText();
		this.newSelectionIndex = this.combo.getSelectionIndex();
	}

	@Override
	public String getWidgetAccessor() {
		int index = WidgetUtils.getIndex(this.combo);
		if (index != 0) {
			return "bot.combo(" + index + ")";
		} else {
			return "bot.combo()";
		}
	}

	@Override
	public String getAction() {
		StringBuilder res = new StringBuilder();
		res.append(".select(");
		if (this.newSelection != null) {
			res.append('"');
			res.append(this.newSelection);
			res.append("\")");
		} else {
			res.append(this.newSelectionIndex);
			res.append(")");
		}
		return res.toString();
	}

}

Back to the top