Author: ljelinko
Date: 2011-12-23 05:05:53 -0500 (Fri, 23 Dec 2011)
New Revision: 37554
Modified:
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/debug/WriteAllWidgets.java
Log:
changed implementation
Modified:
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/debug/WriteAllWidgets.java
===================================================================
---
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/debug/WriteAllWidgets.java 2011-12-23
10:05:33 UTC (rev 37553)
+++
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/debug/WriteAllWidgets.java 2011-12-23
10:05:53 UTC (rev 37554)
@@ -1,56 +1,98 @@
package org.jboss.tools.portlet.ui.bot.task.debug;
-import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.asyncExec;
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
+import java.util.ArrayList;
import java.util.List;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.hamcrest.Matcher;
import org.jboss.tools.portlet.ui.bot.task.AbstractSWTTask;
+/**
+ * Finds all widgets recursively and writes debuggin information about each of them.
+ *
+ * @author Lucia Jelinkova
+ *
+ */
public class WriteAllWidgets extends AbstractSWTTask {
private Matcher<? extends Widget> matcher;
- private Widget widget;
+ private Widget parentWidget;
+ /**
+ * Finds all widgets for the active shell.
+ */
+ public WriteAllWidgets() {
+ this(widgetOfType(Widget.class));
+ }
+
+ /**
+ * Finds all widgets meeting specified matcher's condition for the active shell.
+ *
+ * @param matcher
+ */
public WriteAllWidgets(Matcher<? extends Widget> matcher) {
- super();
- this.matcher = matcher;
+ this(null, matcher);
}
+ /**
+ * Finds all widgets starting from the specified widget meeting
+ * specified matcher condition.
+ *
+ * @param widget
+ * @param matcher
+ */
public WriteAllWidgets(Widget widget, Matcher<? extends Widget> matcher) {
super();
this.matcher = matcher;
- this.widget = widget;
+ this.parentWidget = widget;
}
@Override
public void perform() {
- final List<? extends Widget> widgets = getBot().widgets(matcher,
getParentWidget());
+ syncExec(new VoidResult() {
- asyncExec(new VoidResult() {
-
@Override
public void run() {
- writeWidgets(widgets);
+ System.out.println("List of current widgets");
+ writeWidgetRecursive(getParentWidget(), new ArrayList<Widget>(),
"");
+ System.out.println("End of list");
}
});
}
- private Widget getParentWidget() {
- if (widget == null){
- return getBot().activeShell().widget;
+ private void writeWidgetRecursive(Widget widget, ArrayList<Widget> visited, String
prefix){
+
+ if (visited.contains(widget)){
+ return;
+ }
+
+ visited.add(widget);
+ writeWidget(widget, prefix);
+
+ if (widget instanceof Composite && ((Composite) widget).getChildren().length ==
0){
+ return;
}
- return widget;
+
+ List<? extends Widget> children = getBot().widgets(matcher, widget);
+ for (Widget child : children){
+ writeWidgetRecursive(child, visited, prefix + "---");
+ }
}
+
+ private void writeWidget(Widget widget, String prefix){
+ System.out.println(prefix + widget);
+ }
- private void writeWidgets(List<? extends Widget> widgets){
- System.out.println("List of current widgets");
- for (Widget w : widgets){
- System.out.println(w);
+ private Widget getParentWidget() {
+ if (parentWidget == null){
+ return getBot().activeShell().widget;
}
- System.out.println("End of list");
+ return parentWidget;
}
}
Show replies by date