changeset 93:49816bcead4f

JemmyFX: WebNodeWrap
author Oleg Barbashov <oleg.barbashov@oracle.com>
date Tue, 23 Oct 2012 14:26:08 +0400
parents d6cb0fee1422
children 527f9a799850
files tools/Jemmy/JemmyFX/samples/org/jemmy/samples/webview/WebViewSample.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeParent.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeWrap.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebViewWrap.java tools/Jemmy/JemmyFX/test/org/jemmy/fx/control/WebViewTest.java
diffstat 5 files changed, 39 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/webview/WebViewSample.java	Tue Oct 16 21:17:24 2012 +0400
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/webview/WebViewSample.java	Tue Oct 23 14:26:08 2012 +0400
@@ -60,7 +60,7 @@
         });
 
         // WebViewWrap as parent for org.w3c.dom.Node
-        WebNodeDock body = new WebNodeDock(web_view.asWebViewParent(), new LookupCriteria<org.w3c.dom.Node>() {
+        WebNodeDock body = new WebNodeDock(web_view.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
             public boolean check(org.w3c.dom.Node cntrl) {
                 // looking for HTML's body
                 if (cntrl.getNodeName().equals("BODY")) {
@@ -71,7 +71,7 @@
         });
 
         // WebNodeWrap as parent for org.w3c.dom.Node
-        WebNodeDock button = new WebNodeDock(body.asWebViewParent(), new LookupCriteria<org.w3c.dom.Node>() {
+        WebNodeDock button = new WebNodeDock(body.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
             public boolean check(org.w3c.dom.Node cntrl) {
                 // looking for button
                 if (cntrl.getNodeName().equals("BUTTON")) {
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeParent.java	Tue Oct 16 21:17:24 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeParent.java	Tue Oct 23 14:26:08 2012 +0400
@@ -44,12 +44,18 @@
     protected Wrapper wrapper;
     protected Class<ITEM> itemClass;
     protected Scene scene;
-    WebViewWrap<? extends WebView> wrap;
+    protected WebViewWrap<? extends WebView> view;
+    protected WebNodeWrap<? extends org.w3c.dom.Node> node;
 
     public WebNodeParent(WebViewWrap<? extends WebView> webViewOp, Class<ITEM> itemClass) {
-        this.wrap = webViewOp;
+        this(webViewOp, null, itemClass);
+    }
+
+    public WebNodeParent(WebViewWrap<? extends WebView> webViewOp, WebNodeWrap<? extends org.w3c.dom.Node> webNodeOp, Class<ITEM> itemClass) {
+        this.view = webViewOp;
         this.wrapper = new ItemWrapper<ITEM>(webViewOp);
         this.itemClass = itemClass;
+        this.node = webNodeOp;
     }
 
     public Wrapper getWrapper() {
@@ -58,7 +64,7 @@
 
     @Override
     public <ST extends ITEM> Lookup<ST> lookup(Class<ST> controlClass, LookupCriteria<ST> criteria) {
-        return new PlainLookup<ST>(wrap.getEnvironment(),
+        return new PlainLookup<ST>(view.getEnvironment(),
                 this, wrapper, controlClass, criteria);
     }
 
@@ -92,14 +98,14 @@
 
     @Override
     public List<ITEM> getControls() {
-        wrap.getEnvironment().getWaiter(WebViewWrap.PAGE_LOADING_TIMEOUT).ensureValue(Worker.State.SUCCEEDED, new State<Worker.State>() {
+        view.getEnvironment().getWaiter(WebViewWrap.PAGE_LOADING_TIMEOUT).ensureValue(Worker.State.SUCCEEDED, new State<Worker.State>() {
             public Worker.State reached() {
                 return new GetAction<Worker.State>() {
                     @Override
                     public void run(Object... parameters) throws Exception {
-                        setResult(wrap.getControl().getEngine().getLoadWorker().getState());
+                        setResult(view.getControl().getEngine().getLoadWorker().getState());
                     }
-                }.dispatch(wrap.getEnvironment());
+                }.dispatch(view.getEnvironment());
             }
         });
 
@@ -115,11 +121,16 @@
             @Override
             public void run(Object... parameters) throws Exception {
                 List<ITEM> list = new ArrayList<ITEM>();
-                final NodeList childNodes = wrap.getControl().getEngine().getDocument().getChildNodes();
+
+                final NodeList childNodes;
+                if (node == null) {
+                    childNodes = view.getControl().getEngine().getDocument().getChildNodes();
+                } else {
+                    childNodes = node.getControl().getChildNodes();
+                }
                 addChildren(list, childNodes);
                 setResult(list);
             }
-        }.dispatch(wrap.getEnvironment());
+        }.dispatch(view.getEnvironment());
     }
-
 }
\ No newline at end of file
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeWrap.java	Tue Oct 16 21:17:24 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebNodeWrap.java	Tue Oct 23 14:26:08 2012 +0400
@@ -25,35 +25,29 @@
 package org.jemmy.fx.control;
 
 import com.sun.webpane.webkit.JSObject;
-import javafx.geometry.Orientation;
-import javafx.scene.Node;
-import javafx.scene.control.ScrollBar;
 import javafx.scene.web.WebView;
-import org.jemmy.JemmyException;
 import org.jemmy.Rectangle;
 import org.jemmy.action.GetAction;
+import org.jemmy.control.As;
 import org.jemmy.control.ControlInterfaces;
 import org.jemmy.control.ControlType;
 import org.jemmy.control.Wrap;
 import org.jemmy.dock.DockInfo;
 import org.jemmy.fx.Root;
-import org.jemmy.input.AbstractScroll;
 import org.jemmy.interfaces.*;
-import org.jemmy.lookup.Lookup;
-import org.jemmy.lookup.LookupCriteria;
 import org.w3c.dom.NodeList;
 
 @ControlType({org.w3c.dom.Node.class})
 @DockInfo(name = "org.jemmy.fx.control.WebNodeDock")
-@ControlInterfaces( value = {Parent.class, Showable.class},
+@ControlInterfaces( value = {Parent.class},
                     encapsulates = {org.w3c.dom.Node.class},
-                    name= {"asWebViewParent"})
+                    name= {"asWebNodeParent"})
 public class WebNodeWrap<CONTROL extends org.w3c.dom.Node> extends Wrap<CONTROL>
                                                            implements Showable, Show {
 
-    private WebViewWrap<? extends WebView> view;
-    private String path = new String();
-    private JSObject bounds;
+    protected WebViewWrap<? extends WebView> view;
+    protected String path = new String();
+    protected JSObject bounds;
 
     /**
      *
@@ -71,26 +65,9 @@
         return WebView.class;
     }
 
-    @Override
-    public <TYPE, INTERFACE extends TypeControlInterface<TYPE>> boolean is(Class<INTERFACE> interfaceClass, Class<TYPE> type) {
-        if (Parent.class.equals(interfaceClass)
-                && org.w3c.dom.Node.class.isAssignableFrom(type)) {
-            return true;
-        }
-        if (Selectable.class.equals(interfaceClass)) {
-            return true;
-        }
-        return super.is(interfaceClass, type);
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public <TYPE, INTERFACE extends TypeControlInterface<TYPE>> INTERFACE as(Class<INTERFACE> interfaceClass, Class<TYPE> type) {
-        if (Parent.class.equals(interfaceClass)
-                && org.w3c.dom.Node.class.isAssignableFrom(type)) {
-            return (INTERFACE) new WebNodeParent(view, type);
-        }
-        return super.as(interfaceClass, type);
+    @As(org.w3c.dom.Node.class)
+    public <T extends org.w3c.dom.Node> Parent<T> asWebNodeParent(Class<T> type) {
+        return new WebNodeParent(view, this, type);
     }
 
     @Override
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebViewWrap.java	Tue Oct 16 21:17:24 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/WebViewWrap.java	Tue Oct 23 14:26:08 2012 +0400
@@ -25,18 +25,19 @@
 package org.jemmy.fx.control;
 
 import javafx.scene.web.WebView;
+import org.jemmy.control.As;
 import org.jemmy.control.ControlInterfaces;
 import org.jemmy.control.ControlType;
 import org.jemmy.fx.NodeWrap;
 import org.jemmy.env.Environment;
 import org.jemmy.env.Timeout;
 import org.jemmy.interfaces.Parent;
-import org.jemmy.interfaces.TypeControlInterface;
+import org.jemmy.lookup.AbstractParent;
 
 @ControlType({WebView.class})
 @ControlInterfaces( value = {Parent.class}, 
                     encapsulates = {org.w3c.dom.Node.class},
-                    name= {"asWebViewParent"})
+                    name= {"asWebNodeParent"})
 public class WebViewWrap<CONTROL extends WebView> extends NodeWrap<CONTROL> {
 
     public static final Timeout PAGE_LOADING_TIMEOUT = new Timeout("webview.page.loading.timeout", 5000);
@@ -56,22 +57,8 @@
         super(env, nd);
     }
 
-    @Override
-    public <TYPE, INTERFACE extends TypeControlInterface<TYPE>> boolean is(Class<INTERFACE> interfaceClass, Class<TYPE> type) {
-        if (Parent.class.equals(interfaceClass)
-                && org.w3c.dom.Node.class.isAssignableFrom(type)) {
-            return true;
-        }
-        return super.is(interfaceClass, type);
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public <TYPE, INTERFACE extends TypeControlInterface<TYPE>> INTERFACE as(Class<INTERFACE> interfaceClass, Class<TYPE> type) {
-        if (Parent.class.equals(interfaceClass)
-                && org.w3c.dom.Node.class.isAssignableFrom(type)) {
-            return (INTERFACE) new WebNodeParent(this, type);
-        }
-        return super.as(interfaceClass, type);
+    @As(org.w3c.dom.Node.class)
+    public <T extends org.w3c.dom.Node> AbstractParent<T> asWebNodeParent(Class<T> type) {
+        return new WebNodeParent(this, type);
     }
 }
\ No newline at end of file
--- a/tools/Jemmy/JemmyFX/test/org/jemmy/fx/control/WebViewTest.java	Tue Oct 16 21:17:24 2012 +0400
+++ b/tools/Jemmy/JemmyFX/test/org/jemmy/fx/control/WebViewTest.java	Tue Oct 23 14:26:08 2012 +0400
@@ -54,7 +54,7 @@
             }
         });
 
-        WebNodeDock body = new WebNodeDock(web_view.asWebViewParent(), new LookupCriteria<org.w3c.dom.Node>() {
+        WebNodeDock body = new WebNodeDock(web_view.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
             public boolean check(org.w3c.dom.Node cntrl) {
                 if (cntrl.getNodeName().equals("BODY")) {
                     return true;
@@ -63,7 +63,7 @@
             }
         });
         
-        WebNodeDock button = new WebNodeDock(body.asWebViewParent(), new LookupCriteria<org.w3c.dom.Node>() {
+        WebNodeDock button = new WebNodeDock(body.asWebNodeParent(), new LookupCriteria<org.w3c.dom.Node>() {
             public boolean check(org.w3c.dom.Node cntrl) {
                 if (cntrl.getNodeName().equals("BUTTON")) {
                     return true;