aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrawagner2013-04-18 12:07:57 (EDT)
committerrawagner2013-04-22 12:03:34 (EDT)
commit8da08b87254552431c973ae3236413a0dee385f9 (patch)
treeffb40cbb7bb57a4795707eae38930f1810a87268
parenta7950588bdb97ea0f8aa97efec2b740cb9ed0130 (diff)
downloadorg.eclipse.swtbot-8da08b87254552431c973ae3236413a0dee385f9.zip
org.eclipse.swtbot-8da08b87254552431c973ae3236413a0dee385f9.tar.gz
org.eclipse.swtbot-8da08b87254552431c973ae3236413a0dee385f9.tar.bz2
406005 Added support for multi event mappingrefs/changes/24/12024/2
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationComplexRule.java42
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationRule.java39
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationSimpleRule.java53
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/Generator.java5
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/WidgetUtils.java46
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SWTBotGeneratorRules.java36
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/complex/ToolBarMenuComplexRule.java73
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/AbstractTreeGenerationRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/AbstractTreeGenerationRule.java)10
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/CComboSelectionRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/CComboSelectionRule.java)12
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/CheckboxClickedRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/CheckboxClickedRule.java)12
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ComboSelectionRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ComboSelectionRule.java)12
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ContextMenuRule.java78
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/DoubleClickTreeItemRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/DoubleClickTreeItemRule.java)6
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ExpandTreeItemRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ExpandTreeItemRule.java)6
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ModifyTextRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ModifyTextRule.java)12
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/PushButtonClickedRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/PushButtonClickedRule.java)12
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/RadioButtonClickedRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/RadioButtonClickedRule.java)12
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/SelectTreeItemRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SelectTreeItemRule.java)7
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ShellMenuClickedRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/MenuClickedRule.java)24
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/SingleListSelectionRule.java (renamed from org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SingleListSelectionRule.java)10
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ToolBarDropDownRule.java54
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/BotGeneratorEventDispatcher.java196
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/RecorderDialog.java6
-rw-r--r--org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/StartupRecorder.java9
24 files changed, 626 insertions, 146 deletions
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationComplexRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationComplexRule.java
new file mode 100644
index 0000000..b592381
--- /dev/null
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationComplexRule.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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:
+ * Rastislav Wagner (Red Hat) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.generator.framework;
+
+import java.util.List;
+
+
+/**
+ * This class represents complex rule which is being matched to two or more Simple Rules
+ *
+ */
+public abstract class GenerationComplexRule extends GenerationRule{
+
+ /**
+ * Checks whether given GenerationSimpleRule applies to complex rule
+ * @param rule to match with complex rule
+ * @param i which rule from complex rule to match
+ * @return true if given SimpleRule applies to i-indexed rule
+ */
+ public abstract boolean appliesTo(GenerationSimpleRule rule, int i);
+
+ /**
+ *
+ * @return list of simple rules defining this complex rule
+ */
+ public abstract List<GenerationSimpleRule> getRules();
+
+ /**
+ * Initializes complex rule for given simple rules
+ * @param rules to initialize complex rule for
+ */
+ public abstract void initializeForRules(List<GenerationSimpleRule> rules) ;
+
+}
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationRule.java
index 3e73bb5..f523527 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationRule.java
@@ -11,19 +11,32 @@
*******************************************************************************/
package org.eclipse.swtbot.generator.framework;
-import org.eclipse.swt.widgets.Event;
-
+/**
+ * This class represents abstract GenerationRule
+ *
+ */
public abstract class GenerationRule {
-
- public abstract boolean appliesTo(Event event);
-
- public abstract void initializeForEvent(Event event) ;
-
+
+ /**
+ * Generates code
+ * @return String of generated code
+ */
public String generateCode() {
- return getWidgetAccessor() + getActon();
+ if(getWidgetAccessor() !=null && getAction() != null){
+ return getWidgetAccessor() + getAction();
+ }
+ return null;
}
-
- protected abstract String getWidgetAccessor();
- protected abstract String getActon();
-
-}
+
+ /**
+ *
+ * @return String of code for accessing Widget
+ */
+ public abstract String getWidgetAccessor();
+
+ /**
+ *
+ * @return String of code to call action on widget
+ */
+ public abstract String getAction();
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationSimpleRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationSimpleRule.java
new file mode 100644
index 0000000..dd42a8d
--- /dev/null
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/GenerationSimpleRule.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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
+ * Rastislav Wagner (Red Hat) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.generator.framework;
+
+import org.eclipse.swt.widgets.Event;
+/**
+ * This class represents very basic simple rule which is being matched to one event
+ *
+ */
+public abstract class GenerationSimpleRule extends GenerationRule{
+
+ private String shellTitle;
+ private String viewTitle;
+
+ /**
+ * Checks whether event applies to this rule
+ * @param event to check if it applies to rule
+ * @return true if rules applies to given rule, false otherwise
+ */
+ public abstract boolean appliesTo(Event event);
+
+ /**
+ * Initializes rule for given event
+ * @param event to get needed data from
+ */
+ public abstract void initializeForEvent(Event event);
+
+ public String getShellTitle() {
+ return shellTitle;
+ }
+
+ public void setShellTitle(String shellTitle) {
+ this.shellTitle = shellTitle;
+ }
+
+ public String getViewTitle() {
+ return viewTitle;
+ }
+
+ public void setViewTitle(String viewTitle) {
+ this.viewTitle = viewTitle;
+ }
+
+}
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/Generator.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/Generator.java
index af0d5f0..a8ade7d 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/Generator.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/Generator.java
@@ -15,7 +15,8 @@ import java.util.List;
public interface Generator {
- public List<GenerationRule> createRules();
+ public List<GenerationSimpleRule> createSimpleRules();
+ public List<GenerationComplexRule> createComplexRules();
public String getLabel();
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/WidgetUtils.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/WidgetUtils.java
index fc55f19..5ea739b 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/WidgetUtils.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/WidgetUtils.java
@@ -13,6 +13,8 @@ package org.eclipse.swtbot.generator.framework;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class WidgetUtils {
@@ -38,5 +40,47 @@ public class WidgetUtils {
throw new RuntimeException("Could not determine index for widget " + control);
}
+
+ public static String getGroup(Control control){
+ Composite parent = control.getParent();
+ while(parent != null){
+ if(parent instanceof Group){
+ return ((Group)parent).getText();
+ }
+ parent = parent.getParent();
+ }
+
+ return null;
+ }
+
+ public static Shell getShell(Control widget) {
+ while (widget != null) {
+ if (widget instanceof Shell) {
+ return ((Shell)widget);
+ } else {
+ widget = ((Control)widget).getParent();
+ }
+ }
+ return null;
+ }
+
+ public static String getLabel(Control widget) {
+ Control[] controls = widget.getParent().getChildren();
+ for (int i = 0; i < controls.length; i++) {
+ if (controls[i] instanceof Label && controls[i + 1].equals(widget)) {
+ return ((Label) controls[i]).getText();
+ }
+ }
+ return null;
+ }
+
+ public static String cleanText(String text) {
+ if(text != null){
+ return text.replaceAll("&", "").split("\t")[0];
+ }
+ return null;
+ }
+
+
-}
+} \ No newline at end of file
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 24ff9c7..610eb06 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
@@ -13,13 +13,28 @@ package org.eclipse.swtbot.generator.framework.rules;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationComplexRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.Generator;
+import org.eclipse.swtbot.generator.framework.rules.complex.ToolBarMenuComplexRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.CComboSelectionRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.CheckboxClickedRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ComboSelectionRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ContextMenuRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.DoubleClickTreeItemRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ExpandTreeItemRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ModifyTextRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.PushButtonClickedRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.RadioButtonClickedRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.SelectTreeItemRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ShellMenuClickedRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ToolBarDropDownRule;
public class SWTBotGeneratorRules implements Generator {
- public List<GenerationRule> createRules() {
- List<GenerationRule> res = new ArrayList<GenerationRule>();
+ public List<GenerationSimpleRule> createSimpleRules() {
+ List<GenerationSimpleRule> res = new ArrayList<GenerationSimpleRule>();
+
res.add(new PushButtonClickedRule());
res.add(new CheckboxClickedRule());
res.add(new RadioButtonClickedRule());
@@ -27,14 +42,23 @@ public class SWTBotGeneratorRules implements Generator {
res.add(new CComboSelectionRule());
res.add(new ExpandTreeItemRule());
res.add(new DoubleClickTreeItemRule());
- res.add(new MenuClickedRule());
+ res.add(new ShellMenuClickedRule());
res.add(new SelectTreeItemRule());
res.add(new ModifyTextRule());
- res.add(new SingleListSelectionRule());
+ res.add(new ContextMenuRule());
+ res.add(new ToolBarDropDownRule());
+
return res;
+
}
public String getLabel() {
return "SWTBot";
}
-}
+
+ public List<GenerationComplexRule> createComplexRules() {
+ List<GenerationComplexRule> cres = new ArrayList<GenerationComplexRule>();
+ cres.add(new ToolBarMenuComplexRule());
+ return cres;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/complex/ToolBarMenuComplexRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/complex/ToolBarMenuComplexRule.java
new file mode 100644
index 0000000..86de6a2
--- /dev/null
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/complex/ToolBarMenuComplexRule.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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:
+ * Rastislav Wagner (Red Hat) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.generator.framework.rules.complex;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swtbot.generator.framework.GenerationComplexRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ContextMenuRule;
+import org.eclipse.swtbot.generator.framework.rules.simple.ToolBarDropDownRule;
+
+public class ToolBarMenuComplexRule extends GenerationComplexRule{
+
+ private List<GenerationSimpleRule> rules;
+ private List<GenerationSimpleRule> initializedRules;
+
+ public ToolBarMenuComplexRule(){
+ rules = new ArrayList<GenerationSimpleRule>();
+
+ ToolBarDropDownRule toolBar = new ToolBarDropDownRule();
+ ContextMenuRule menu = new ContextMenuRule();
+
+ rules.add(toolBar);
+ rules.add(menu);
+ }
+
+ @Override
+ public List<GenerationSimpleRule> getRules() {
+ return rules;
+
+
+ }
+
+ @Override
+ public String getWidgetAccessor(){
+ StringBuilder builder = new StringBuilder();
+ builder.append(((ToolBarDropDownRule)initializedRules.get(0)).getWidgetAccessor());
+ ContextMenuRule cmr = ((ContextMenuRule)initializedRules.get(1));
+ for(String s: cmr.getPath()){
+ builder.append(".menuItem(\""+s+"\")");
+ }
+ builder.append(".menuItem(\""+cmr.getMenu()+"\")");
+ return builder.toString();
+ }
+
+ @Override
+ public String getAction(){
+ return ".click()";
+ }
+
+
+ @Override
+ public boolean appliesTo(GenerationSimpleRule rule, int i) {
+ return rules.get(i).getClass().equals(rule.getClass());
+ }
+
+ @Override
+ public void initializeForRules(List<GenerationSimpleRule> rules) {
+ this.initializedRules=rules;
+
+ }
+
+}
+
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/AbstractTreeGenerationRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/AbstractTreeGenerationRule.java
index 99eab16..ab52b85 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/AbstractTreeGenerationRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/AbstractTreeGenerationRule.java
@@ -8,7 +8,7 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import java.util.ArrayList;
import java.util.Collections;
@@ -17,10 +17,10 @@ import java.util.List;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public abstract class AbstractTreeGenerationRule extends GenerationRule {
+public abstract class AbstractTreeGenerationRule extends GenerationSimpleRule {
private Tree tree;
private TreeItem item;
@@ -43,7 +43,7 @@ public abstract class AbstractTreeGenerationRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
StringBuilder res = new StringBuilder();
res.append("bot.tree(");
int index = WidgetUtils.getIndex(this.tree);
@@ -73,4 +73,4 @@ public abstract class AbstractTreeGenerationRule extends GenerationRule {
}
return res.toString();
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/CComboSelectionRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/CComboSelectionRule.java
index 6960b59..73f14f6 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/CComboSelectionRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/CComboSelectionRule.java
@@ -8,15 +8,15 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+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.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class CComboSelectionRule extends GenerationRule {
+public class CComboSelectionRule extends GenerationSimpleRule {
private Combo combo;
private String newSelection;
@@ -35,7 +35,7 @@ public class CComboSelectionRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
int index = WidgetUtils.getIndex(this.combo);
if (index != 0) {
return "bot.combo(" + index + ")";
@@ -45,7 +45,7 @@ public class CComboSelectionRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
StringBuilder res = new StringBuilder();
res.append(".select(");
if (this.newSelection != null) {
@@ -59,4 +59,4 @@ public class CComboSelectionRule extends GenerationRule {
return res.toString();
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/CheckboxClickedRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/CheckboxClickedRule.java
index 1f49368..da3de75 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/CheckboxClickedRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/CheckboxClickedRule.java
@@ -8,15 +8,15 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class CheckboxClickedRule extends GenerationRule {
+public class CheckboxClickedRule extends GenerationSimpleRule {
private String buttonText;
private int index;
@@ -37,7 +37,7 @@ public class CheckboxClickedRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
if (this.buttonText != null) {
return "bot.radio(\"" + this.buttonText + "\")";
} else {
@@ -46,8 +46,8 @@ public class CheckboxClickedRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".click()";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ComboSelectionRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ComboSelectionRule.java
index bad81e8..a9cc8a6 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ComboSelectionRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ComboSelectionRule.java
@@ -8,15 +8,15 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class ComboSelectionRule extends GenerationRule {
+public class ComboSelectionRule extends GenerationSimpleRule {
private CCombo combo;
private String newSelection;
@@ -35,7 +35,7 @@ public class ComboSelectionRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
int index = WidgetUtils.getIndex(this.combo);
if (index != 0) {
return "bot.combo(" + index + ")";
@@ -45,7 +45,7 @@ public class ComboSelectionRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
StringBuilder res = new StringBuilder();
res.append(".select(");
if (this.newSelection != null) {
@@ -59,4 +59,4 @@ public class ComboSelectionRule extends GenerationRule {
return res.toString();
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ContextMenuRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ContextMenuRule.java
new file mode 100644
index 0000000..4a44c72
--- /dev/null
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ContextMenuRule.java
@@ -0,0 +1,78 @@
+package org.eclipse.swtbot.generator.framework.rules.simple;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
+import org.eclipse.swtbot.generator.framework.WidgetUtils;
+
+public class ContextMenuRule extends GenerationSimpleRule{
+
+ private List<String> path;
+ private String menu;
+
+ @Override
+ public boolean appliesTo(Event event) {
+ boolean menu = event.widget instanceof MenuItem;
+ int style = 0;
+ if(menu){
+ MenuItem currentItem = ((MenuItem)event.widget);
+ Menu parent = null;
+ while (currentItem != null && (parent = currentItem.getParent()) != null) {
+ style = parent.getStyle();
+ currentItem = parent.getParentItem();
+ }
+ }
+ return event.type == SWT.Selection && menu && (style & SWT.POP_UP)!=0;
+ }
+
+ @Override
+ public void initializeForEvent(Event event) {
+ MenuItem item = (MenuItem) event.widget;
+ menu = WidgetUtils.cleanText(item.getText());
+ path = new ArrayList<String>();
+ MenuItem currentItem = item;
+ Menu parent = null;
+ while (currentItem != null && (parent = currentItem.getParent()) != null) {
+ currentItem = parent.getParentItem();
+ if (currentItem != null && currentItem.getText() != null) {
+ path.add(WidgetUtils.cleanText(currentItem.getText()));
+ }
+ }
+ Collections.reverse(path);
+ }
+
+ @Override
+ public String getWidgetAccessor() {
+ return null;
+ }
+
+ @Override
+ public String getAction() {
+ return null;
+ }
+
+ public List<String> getPath() {
+ return path;
+ }
+
+ public void setPath(List<String> path) {
+ this.path = path;
+ }
+
+ public String getMenu() {
+ return menu;
+ }
+
+ public void setMenu(String menu) {
+ this.menu = menu;
+ }
+
+
+
+}
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/DoubleClickTreeItemRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/DoubleClickTreeItemRule.java
index def4812..784db20 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/DoubleClickTreeItemRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/DoubleClickTreeItemRule.java
@@ -8,7 +8,7 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
@@ -21,8 +21,8 @@ public class DoubleClickTreeItemRule extends AbstractTreeGenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".doubleClick()";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ExpandTreeItemRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ExpandTreeItemRule.java
index 2de8e00..3e4a528 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ExpandTreeItemRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ExpandTreeItemRule.java
@@ -8,7 +8,7 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
@@ -21,8 +21,8 @@ public class ExpandTreeItemRule extends AbstractTreeGenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".expand()";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ModifyTextRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ModifyTextRule.java
index 3ee1506..ba0c36d 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/ModifyTextRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ModifyTextRule.java
@@ -8,15 +8,15 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class ModifyTextRule extends GenerationRule {
+public class ModifyTextRule extends GenerationSimpleRule {
private Text text;
private String newValue;
@@ -33,7 +33,7 @@ public class ModifyTextRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
StringBuilder res = new StringBuilder();
res.append("bot.text(");
int index = WidgetUtils.getIndex(this.text);
@@ -45,8 +45,8 @@ public class ModifyTextRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".setText(\"" + this.newValue + "\")";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/PushButtonClickedRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/PushButtonClickedRule.java
index a70df01..4edb7e0 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/PushButtonClickedRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/PushButtonClickedRule.java
@@ -8,15 +8,15 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class PushButtonClickedRule extends GenerationRule {
+public class PushButtonClickedRule extends GenerationSimpleRule {
private String buttonText;
private int index;
@@ -37,7 +37,7 @@ public class PushButtonClickedRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
if (this.buttonText != null) {
return "bot.button(\"" + this.buttonText + "\")";
} else {
@@ -46,8 +46,8 @@ public class PushButtonClickedRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".click()";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/RadioButtonClickedRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/RadioButtonClickedRule.java
index 7dc4b6e..dafb868 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/RadioButtonClickedRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/RadioButtonClickedRule.java
@@ -8,15 +8,15 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class RadioButtonClickedRule extends GenerationRule {
+public class RadioButtonClickedRule extends GenerationSimpleRule {
private String buttonText;
private int index;
@@ -37,7 +37,7 @@ public class RadioButtonClickedRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
if (this.buttonText != null) {
return "bot.checkBox(\"" + this.buttonText + "\")";
} else {
@@ -46,8 +46,8 @@ public class RadioButtonClickedRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".click()";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SelectTreeItemRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/SelectTreeItemRule.java
index 9cee9bf..fed129b 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/SelectTreeItemRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/SelectTreeItemRule.java
@@ -8,10 +8,9 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import org.eclipse.swt.widgets.Event;
-
import org.eclipse.swt.SWT;
public class SelectTreeItemRule extends AbstractTreeGenerationRule {
@@ -22,8 +21,8 @@ public class SelectTreeItemRule extends AbstractTreeGenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".select()";
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/MenuClickedRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ShellMenuClickedRule.java
index 8bfae4c..295255d 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/MenuClickedRule.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ShellMenuClickedRule.java
@@ -8,7 +8,7 @@
* Contributors:
* Mickael Istria (Red Hat) - initial API and implementation
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
import java.util.ArrayList;
import java.util.Collections;
@@ -18,15 +18,25 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
-public class MenuClickedRule extends GenerationRule {
+public class ShellMenuClickedRule extends GenerationSimpleRule {
private MenuItem item;
@Override
public boolean appliesTo(Event event) {
- return event.type == SWT.Selection && event.widget instanceof MenuItem;
+ boolean menu = event.widget instanceof MenuItem;
+ int style = 0;
+ if(menu){
+ MenuItem currentItem = ((MenuItem)event.widget);
+ Menu parent = null;
+ while (currentItem != null && (parent = currentItem.getParent()) != null) {
+ style = parent.getStyle();
+ currentItem = parent.getParentItem();
+ }
+ }
+ return event.type == SWT.Selection && menu && (style & SWT.BAR)!=0;
}
@Override
@@ -35,7 +45,7 @@ public class MenuClickedRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
StringBuilder code = new StringBuilder();
List<String> path = new ArrayList<String>();
path.add(cleanMenuText(this.item.getText()));
@@ -62,8 +72,8 @@ public class MenuClickedRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
return ".click()";
}
-}
+} \ No newline at end of file
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/simple/SingleListSelectionRule.java
index 5726479..c0ea970 100644
--- 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/simple/SingleListSelectionRule.java
@@ -9,15 +9,15 @@
* Mickael Istria (Red Hat) - initial API and implementation
* Vlado Pakan (Red Hat)
*******************************************************************************/
-package org.eclipse.swtbot.generator.framework.rules;
+package org.eclipse.swtbot.generator.framework.rules.simple;
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.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.WidgetUtils;
-public class SingleListSelectionRule extends GenerationRule {
+public class SingleListSelectionRule extends GenerationSimpleRule {
private List list;
private String newSelectionText = null;
@@ -37,7 +37,7 @@ public class SingleListSelectionRule extends GenerationRule {
}
@Override
- protected String getWidgetAccessor() {
+ public String getWidgetAccessor() {
int index = WidgetUtils.getIndex(this.list);
if (index != 0) {
return "bot.list(" + index + ")";
@@ -47,7 +47,7 @@ public class SingleListSelectionRule extends GenerationRule {
}
@Override
- protected String getActon() {
+ public String getAction() {
StringBuilder res = new StringBuilder();
if (this.newSelectionText != null){
res.append(".select(\"");
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ToolBarDropDownRule.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ToolBarDropDownRule.java
new file mode 100644
index 0000000..262c5ac
--- /dev/null
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/framework/rules/simple/ToolBarDropDownRule.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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:
+ * Rastislav Wagner (Red Hat) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.generator.framework.rules.simple;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
+
+public class ToolBarDropDownRule extends GenerationSimpleRule{
+
+ private String toolTipText;
+
+
+ @Override
+ public boolean appliesTo(Event event) {
+ return event.widget instanceof ToolItem && event.type == SWT.Selection &&
+ (((ToolItem)event.widget).getStyle() & SWT.DROP_DOWN)!= 0;
+ }
+
+ @Override
+ public void initializeForEvent(Event event) {
+ this.toolTipText = ((ToolItem)event.widget).getToolTipText();
+ }
+
+ @Override
+ public String getAction() {
+ return ".click()";
+
+ }
+
+ @Override
+ public String getWidgetAccessor() {
+ return "bot.toolbarDropDownButtonWithToolTip(\""+toolTipText+"\")";
+ }
+
+ public String getToolTipText() {
+ return toolTipText;
+ }
+
+ public void setToolTipText(String toolTipText) {
+ this.toolTipText = toolTipText;
+ }
+
+}
+
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/BotGeneratorEventDispatcher.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/BotGeneratorEventDispatcher.java
index 78db991..d9d8700 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/BotGeneratorEventDispatcher.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/BotGeneratorEventDispatcher.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Red Hat Inc..
+ * 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
@@ -12,114 +12,202 @@
package org.eclipse.swtbot.generator.ui;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swtbot.generator.framework.GenerationRule;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swtbot.generator.framework.GenerationComplexRule;
+import org.eclipse.swtbot.generator.framework.GenerationSimpleRule;
import org.eclipse.swtbot.generator.framework.Generator;
+import org.eclipse.swtbot.generator.framework.WidgetUtils;
+
+public class BotGeneratorEventDispatcher implements Listener{
-public class BotGeneratorEventDispatcher implements Listener {
public static interface CodeGenerationListener {
public void handleCodeGenerated(String code);
}
+ private List<GenerationSimpleRule> listOfSimpleRules = new ArrayList<GenerationSimpleRule>();
+
private Generator generator;
- private List<GenerationRule> generationRules;
private List<CodeGenerationListener> listeners = new ArrayList<CodeGenerationListener>();
private Shell ignoredShell;
private boolean recording;
private Event lastModifyEvent;
+
+ private GenerationComplexRule longestMatchedComplex;
- public void setGenerator(Generator generator) {
+ private boolean newGenerationComplexRules = true;
+ private List<GenerationComplexRule> modifGenerationComplexRules = new ArrayList<GenerationComplexRule>();
+
+ public void setGenerator(Generator generator) {
this.generator = generator;
- this.generationRules = generator.createRules();
+ }
+
+ public void addListener(CodeGenerationListener listener) {
+ this.listeners.add(listener);
+ }
+
+ public void ignoreShell(Shell shell) {
+ this.ignoredShell = shell;
+ }
+
+ public boolean isRecording() {
+ return this.recording;
+ }
+
+ public void switchRecording() {
+ this.recording = !this.recording;
}
+ public Generator getCurrentGenerator() {
+ return this.generator;
+ }
+
public void handleEvent(Event event) {
- if (this.ignoredShell != null && event.widget instanceof Control && this.ignoredShell.equals(getShell((Control)event.widget))) {
+ if (!recording) {
return;
}
- if (event.widget instanceof Control &&
- ! (((Control)event.widget).isFocusControl() && ((Control)event.widget).isVisible() && ((Control)event.widget).isEnabled())) {
+ if(event.widget instanceof Control){
+ Shell shell = WidgetUtils.getShell((Control) event.widget);
+ if(shell.getParent() instanceof Shell){
+ if (this.ignoredShell != null && this.ignoredShell.equals(shell.getParent())) {
+ return;
+ }
+ }
+ }
+ if (!(event.widget instanceof Shell) && event.widget instanceof Control
+ && !(((Control) event.widget).isFocusControl()
+ && ((Control) event.widget).isVisible()
+ && ((Control) event.widget).isEnabled())) {
return;
}
-
- /* Excpetion 1: Modify Events are a stream, only last one is interesting
- We should check whether an event was supported by another rule between 2 modifies.
- If yes => It's a new setText, apply setText rule if any
- If no => It's still the same setText, event is stored for later
+
+
+ /*
+ * Excpetion 1: Modify Events are a stream, only last one is interesting
+ * We should check whether an event was supported by another rule
+ * between 2 modifies. If yes => It's a new setText, apply setText rule
+ * if any If no => It's still the same setText, event is stored for
+ * later
*/
if (this.lastModifyEvent != null) {
// unrelated event
- if (event.type != SWT.Modify || event.widget != this.lastModifyEvent.widget) {
+ if (event.type != SWT.Modify
+ || event.widget != this.lastModifyEvent.widget) {
processRules(this.lastModifyEvent);
this.lastModifyEvent = null;
}
}
if (event.type == SWT.Modify) {
- Control control = (Control)event.widget;
+ if(event.widget instanceof Text){
+ if(((Text)event.widget).getMessage() != null){
+ if(((Text)event.widget).getMessage().equals(((Text)event.widget).getText())){
+ return;
+ } else if(((Text)event.widget).getText().isEmpty()){
+ return;
+ }
+ }
+ }
+ Control control = (Control) event.widget;
// new event or next one on same widget
- if (this.lastModifyEvent == null || this.lastModifyEvent.widget == control) {
+ if (this.lastModifyEvent == null
+ || this.lastModifyEvent.widget == control) {
this.lastModifyEvent = event;
- // Store for later usage so it can be overriden if a newer ModifyEvent on samme widget happen
+ // Store for later usage so it can be overriden if a newer
+ // ModifyEvent on samme widget happen
return;
}
}
-
+
processRules(event);
}
-
+
private void processRules(Event event) {
- for (GenerationRule rule : this.generationRules) {
+ for (GenerationSimpleRule rule : generator.createSimpleRules()) {
if (rule.appliesTo(event)) {
rule.initializeForEvent(event);
- //rule.setPreviousEvent()
- dispatchCodeGenerated(rule.generateCode());
+ listOfSimpleRules.add(rule); //store simple rule for further processing
}
}
- }
-
- private static Shell getShell(Control widget) {
- while (widget != null) {
- if (widget.getParent() == null) {
- return (Shell)widget;
- } else {
- widget = ((Control)widget).getParent();
+ if(!listOfSimpleRules.isEmpty()){ //find complex rules
+
+ if(newGenerationComplexRules){
+ modifGenerationComplexRules.addAll(generator.createComplexRules());
+ Collections.sort(modifGenerationComplexRules, new Comparator<GenerationComplexRule>() {
+ public int compare(GenerationComplexRule g1, GenerationComplexRule g2) {
+ return g2.getRules().size()-g1.getRules().size();
+ }
+ });
+ }
+ newGenerationComplexRules = true;
+ Set<GenerationComplexRule> toDelete = matchComplexRules(modifGenerationComplexRules);
+ modifGenerationComplexRules.removeAll(toDelete);
+ if(longestMatchedComplex != null && ((modifGenerationComplexRules.size() == 0)||
+ (modifGenerationComplexRules.size() == 1 && longestMatchedComplex.equals(modifGenerationComplexRules.get(0))))){ //match
+ processComplexMatch();
+ } else if(modifGenerationComplexRules.size() == 0 && longestMatchedComplex == null){//no match,
+ processComplexNoMatch(); //keep looking for match without first simple rule
+ } else if(modifGenerationComplexRules.size() > 0){ //there's possibility to find better match
+ newGenerationComplexRules = false; //get next event
+ return;
}
}
- return null;
+
}
-
-
- private void dispatchCodeGenerated(String code) {
- for (CodeGenerationListener listener : this.listeners) {
- listener.handleCodeGenerated(code);
+
+ private void processComplexMatch(){
+ List<GenerationSimpleRule> rulesToKeep = new ArrayList<GenerationSimpleRule>();
+ int toKeep = listOfSimpleRules.size()-longestMatchedComplex.getRules().size();
+ for(int i=toKeep; i>0; i--){
+ rulesToKeep.add(listOfSimpleRules.get(listOfSimpleRules.size()-i));
}
+ listOfSimpleRules.removeAll(rulesToKeep);
+ longestMatchedComplex.initializeForRules(listOfSimpleRules);
+ dispatchCodeGenerated(WidgetUtils.cleanText(longestMatchedComplex.generateCode()));
+ longestMatchedComplex=null;
+ listOfSimpleRules.clear();
+ listOfSimpleRules.addAll(rulesToKeep);
}
-
- public void addListener(CodeGenerationListener listener) {
- this.listeners.add(listener);
- }
-
- public void ignoreShell(Shell shell) {
- this.ignoredShell = shell;
+
+ private void processComplexNoMatch(){
+ dispatchCodeGenerated(WidgetUtils.cleanText(listOfSimpleRules.get(0).generateCode())); //generate code for first simple rule
+ listOfSimpleRules.remove(0);
}
-
- public boolean isReording() {
- return this.recording;
- }
-
- public void switchRecording() {
- this.recording = !this.recording;
+
+ private Set<GenerationComplexRule> matchComplexRules(List<GenerationComplexRule> modifGenerationComplexRules){
+ Set<GenerationComplexRule> toDelete= new HashSet<GenerationComplexRule>();
+ for(int i=0; i<listOfSimpleRules.size(); i++){
+ for(GenerationComplexRule complexRule: modifGenerationComplexRules){
+ if(complexRule.getRules().size() < listOfSimpleRules.size()){ //complex rule has less rules that listofRules
+ toDelete.add(complexRule);
+ }else{
+ if(!complexRule.appliesTo(listOfSimpleRules.get(i), i)){
+ toDelete.add(complexRule);
+ } else if(complexRule.getRules().size()-1==i){
+ longestMatchedComplex=complexRule;
+ }
+ }
+ }
+ }
+ return toDelete;
}
- public Generator getCurrentGenerator() {
- return this.generator;
+ private void dispatchCodeGenerated(String code) {
+ if(code != null){
+ for (CodeGenerationListener listener : this.listeners) {
+ listener.handleCodeGenerated(code);
+ }
+ }
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/RecorderDialog.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/RecorderDialog.java
index e3293bb..fe9adfe 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/RecorderDialog.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/RecorderDialog.java
@@ -99,7 +99,7 @@ public class RecorderDialog extends TitleAreaDialog {
actionsComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
final Button recordPauseButton = new Button(actionsComposite, SWT.PUSH);
- recordPauseButton.setText(this.recorder.isReording() ? "Pause" : "Start Recording");
+ recordPauseButton.setText(this.recorder.isRecording() ? "Pause" : "Start Recording");
final Button copyButton = new Button(actionsComposite, SWT.PUSH);
copyButton.setToolTipText("Copy");
copyButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
@@ -108,7 +108,7 @@ public class RecorderDialog extends TitleAreaDialog {
@Override
public void widgetSelected(SelectionEvent e) {
recorder.switchRecording();
- recordPauseButton.setText(recorder.isReording() ? "Pause" : "Start Recording");
+ recordPauseButton.setText(recorder.isRecording() ? "Pause" : "Start Recording");
}
});
this.recorder.addListener(new CodeGenerationListener() {
@@ -141,4 +141,4 @@ public class RecorderDialog extends TitleAreaDialog {
protected Point getInitialSize() {
return new Point(450, 650);
}
-}
+} \ No newline at end of file
diff --git a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/StartupRecorder.java b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/StartupRecorder.java
index 3c121ba..7dee05b 100644
--- a/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/StartupRecorder.java
+++ b/org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/ui/StartupRecorder.java
@@ -12,7 +12,6 @@
package org.eclipse.swtbot.generator.ui;
import java.util.List;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
@@ -35,9 +34,7 @@ public class StartupRecorder implements IStartup {
Generator generator = availableGenerators.get(0);
final BotGeneratorEventDispatcher dispatcher = new BotGeneratorEventDispatcher();
dispatcher.setGenerator(generator);
-
final Display display = PlatformUI.getWorkbench().getDisplay();
-
display.asyncExec(new Runnable() {
public void run() {
display.addFilter(SWT.Activate, dispatcher);
@@ -45,6 +42,9 @@ public class StartupRecorder implements IStartup {
display.addFilter(SWT.Selection, dispatcher);
display.addFilter(SWT.Expand, dispatcher);
display.addFilter(SWT.Modify, dispatcher);
+ display.addFilter(SWT.MouseDown, dispatcher);
+ display.addFilter(SWT.MouseDoubleClick, dispatcher);
+
Shell recorderShell = new Shell(PlatformUI.getWorkbench().getDisplay(), SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE);
recorderShell.setText("SWTBot test recorder");
dispatcher.ignoreShell(recorderShell);
@@ -61,6 +61,7 @@ public class StartupRecorder implements IStartup {
display.removeFilter(SWT.Selection, dispatcher);
display.removeFilter(SWT.Expand, dispatcher);
display.removeFilter(SWT.Modify, dispatcher);
+ display.removeFilter(SWT.DefaultSelection, dispatcher);
}
});
}
@@ -68,4 +69,4 @@ public class StartupRecorder implements IStartup {
});
}
-}
+} \ No newline at end of file