aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvpakan2013-03-11 11:26:38 (EDT)
committerGerrit Code Review @ Eclipse.org2013-03-25 14:08:48 (EDT)
commit1a2d65a6ae1d6c63fd343476a0883f31c8ad1fea (patch)
tree633490a9c1c98a0233097bc4ae52ae84d4dd440d
parent105d59ee872d97953e44168720e1b3c305919141 (diff)
downloadorg.eclipse.swtbot-1a2d65a6ae1d6c63fd343476a0883f31c8ad1fea.zip
org.eclipse.swtbot-1a2d65a6ae1d6c63fd343476a0883f31c8ad1fea.tar.gz
org.eclipse.swtbot-1a2d65a6ae1d6c63fd343476a0883f31c8ad1fea.tar.bz2
402921: Add support for List widget to SWTBot Test recorderrefs/changes/53/11053/2
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SWTBotGeneratorRules.java1
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SingleListSelectionRule.java63
2 files changed, 64 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SWTBotGeneratorRules.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SWTBotGeneratorRules.java
index b19b3b2..24ff9c7 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SWTBotGeneratorRules.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SWTBotGeneratorRules.java
@@ -30,6 +30,7 @@ public class SWTBotGeneratorRules implements Generator {
res.add(new MenuClickedRule());
res.add(new SelectTreeItemRule());
res.add(new ModifyTextRule());
+ res.add(new SingleListSelectionRule());
return res;
}
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SingleListSelectionRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SingleListSelectionRule.java
new file mode 100644
index 0000000..5726479
--- /dev/null
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SingleListSelectionRule.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ * Vlado Pakan (Red Hat)
+ *******************************************************************************/
+package org.eclipse.swtbot.generator.framework.rules;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.WidgetUtils;
+
+public class SingleListSelectionRule extends GenerationRule {
+
+ private List list;
+ private String newSelectionText = null;
+
+ @Override
+ public boolean appliesTo(Event event) {
+ return event.widget instanceof List && event.type == SWT.Selection &&
+ (((List)event.widget).getStyle() & SWT.SINGLE) != 0;
+ }
+
+ @Override
+ public void initializeForEvent(Event event) {
+ this.list = (List)event.widget;
+ if (this.list.getSelectionCount() > 0){
+ this.newSelectionText = this.list.getSelection()[0];
+ }
+ }
+
+ @Override
+ protected String getWidgetAccessor() {
+ int index = WidgetUtils.getIndex(this.list);
+ if (index != 0) {
+ return "bot.list(" + index + ")";
+ } else {
+ return "bot.list()";
+ }
+ }
+
+ @Override
+ protected String getActon() {
+ StringBuilder res = new StringBuilder();
+ if (this.newSelectionText != null){
+ res.append(".select(\"");
+ res.append(this.newSelectionText);
+ res.append("\")");
+ }
+ else {
+ res.append(".unselect()");
+ }
+ return res.toString();
+ }
+
+}