changeset 31:9db2cf30aeb5

JemmyFX: Accordion wrap
author Oleg Barbashov <oleg.barbashov@oracle.com>
date Wed, 20 Jun 2012 02:31:32 +0400
parents e37f6f5cb0cd
children f592be068a8e
files tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionApp.java tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionTest.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/NodeWrapper.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/AccordionWrap.java tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/TabPaneWrap.java
diffstat 5 files changed, 364 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionApp.java	Wed Jun 20 02:31:32 2012 +0400
@@ -0,0 +1,57 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jemmy.samples.accordion;
+
+import java.awt.AWTException;
+import javafx.application.Application;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.geometry.Pos;
+import javafx.scene.Node;
+import javafx.scene.Scene;
+import javafx.scene.control.Accordion;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TitledPane;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+
+public class AccordionApp extends Application {
+    public static void main(String[] args) throws AWTException {
+        launch(args);
+    }
+
+    @Override
+    public void start(Stage stage) throws Exception {
+        VBox box = new VBox();
+        Scene scene = new Scene(box);
+
+        final Accordion accordion = new Accordion();
+
+        accordion.getPanes().add(new TitledPane("First pane", new Label("First pane's content")));
+        accordion.getPanes().add(new TitledPane("Second pane", new Label("Second pane's content")));
+
+        box.getChildren().add(accordion);
+
+        Button reset = new Button("Reset");
+        reset.setOnAction(new EventHandler<ActionEvent>() {
+            public void handle(ActionEvent t) {
+                TitledPane pane = accordion.getExpandedPane();
+                if (pane != null) {
+                    accordion.getExpandedPane().setExpanded(false);
+                }
+            }
+        });
+        box.getChildren().add(reset);
+
+        stage.setScene(scene);
+
+        stage.setWidth(300);
+        stage.setHeight(300);
+
+        stage.show();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionTest.java	Wed Jun 20 02:31:32 2012 +0400
@@ -0,0 +1,90 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jemmy.samples.accordion;
+
+import javafx.scene.control.Accordion;
+import org.jemmy.fx.AppExecutor;
+import org.jemmy.fx.SceneDock;
+import org.jemmy.fx.control.AccordionDock;
+import org.jemmy.fx.control.AccordionWrap;
+import org.jemmy.fx.control.LabeledDock;
+import org.jemmy.fx.control.TitledPaneDock;
+import org.jemmy.resources.StringComparePolicy;
+import org.jemmy.timing.State;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AccordionTest {
+    static SceneDock scene;
+    
+    @BeforeClass
+    public static void launch() {
+        AppExecutor.executeNoBlock(AccordionApp.class);
+        scene = new SceneDock();
+    }
+
+    @Before
+    public void reset() {
+        new LabeledDock(scene.asParent(), "Reset", StringComparePolicy.EXACT).mouse().click();
+    }
+
+    /**
+     * How to expandand collapse TitledPane of Accordion control using Expandable interface.
+     */
+    @Test
+    public void expandAandCollapse() {
+        TitledPaneDock first_pane = new TitledPaneDock(scene.asParent(), "First pane", StringComparePolicy.EXACT);
+        first_pane.asExpandable().expand();
+        first_pane.asCollapsible().collapse();
+
+        TitledPaneDock second_pane = new TitledPaneDock(scene.asParent(), "Second pane", StringComparePolicy.EXACT);
+        second_pane.asExpandable().expand();
+        second_pane.asCollapsible().collapse();
+    }
+
+    /**
+     * How to expand TitledPane of Accordion control by title of TitledPane using Selectable interface.
+     */
+    @Test
+    public void selectByTitle() {
+        AccordionDock accordion = new AccordionDock(scene.asParent(), Accordion.class);
+
+        accordion.asTitleSelectable().selector().select("First pane");
+        accordion.wrap().waitProperty(AccordionWrap.SELECTED_TITLE, "First pane");
+
+        accordion.asTitleSelectable().selector().select("Second pane");
+        accordion.wrap().waitProperty(AccordionWrap.SELECTED_TITLE, "Second pane");
+    }
+
+    /**
+     * How to expand TitledPane of Accordion control by TitledPane object using Selectable interface.
+     */
+    @Test
+    public void selectByTitlePane() {
+        AccordionDock accordion = new AccordionDock(scene.asParent(), Accordion.class);
+
+        TitledPaneDock first_pane = new TitledPaneDock(scene.asParent(), "First pane", StringComparePolicy.EXACT);
+        accordion.asTitledPaneSelectable().selector().select(first_pane.wrap().getControl());
+
+        TitledPaneDock second_pane = new TitledPaneDock(scene.asParent(), "Second pane", StringComparePolicy.EXACT);
+        accordion.asTitledPaneSelectable().selector().select(second_pane.wrap().getControl());
+    }
+
+    /**
+     * How to collapse TitledPane in an Accordion control using Selectable interface.
+     */
+    @Test
+    public void collapseTitlePane() {
+        final AccordionDock accordion = new AccordionDock(scene.asParent(), Accordion.class);
+        accordion.asTitleSelectable().selector().select(null);
+        accordion.wrap().waitState(new State<Boolean>() {
+            public Boolean reached() {
+                return accordion.wrap().getProperty(AccordionWrap.SELECTED_TITLED_PANE_PROP) == null ? Boolean.TRUE : Boolean.FALSE;
+            }
+        }, Boolean.TRUE);
+    }
+}
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/NodeWrapper.java	Fri Jun 15 19:20:15 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/NodeWrapper.java	Wed Jun 20 02:31:32 2012 +0400
@@ -72,6 +72,7 @@
         OPERATORS.add(SplitPaneWrap.class);
         OPERATORS.add(SeparatorWrap.class);
         OPERATORS.add(TitledPaneWrap.class);
+        OPERATORS.add(AccordionWrap.class);
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/AccordionWrap.java	Wed Jun 20 02:31:32 2012 +0400
@@ -0,0 +1,215 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jemmy.fx.control;
+
+import java.util.ArrayList;
+import java.util.List;
+import javafx.collections.ObservableList;
+import javafx.scene.Node;
+import javafx.scene.control.Accordion;
+import javafx.scene.control.TitledPane;
+import org.jemmy.action.GetAction;
+import org.jemmy.control.ControlInterfaces;
+import org.jemmy.control.ControlType;
+import org.jemmy.control.Property;
+import org.jemmy.env.Environment;
+import org.jemmy.fx.ByObject;
+import org.jemmy.fx.NodeWrap;
+import org.jemmy.interfaces.ControlInterface;
+import org.jemmy.interfaces.Parent;
+import org.jemmy.interfaces.Selectable;
+import org.jemmy.interfaces.Selector;
+import org.jemmy.interfaces.TypeControlInterface;
+import org.jemmy.lookup.LookupCriteria;
+
+@ControlType(Accordion.class)
+@ControlInterfaces(value = {Selectable.class, Selectable.class},
+                   encapsulates = {TitledPane.class, String.class},
+                   name= {"asTitledPaneSelectable", "asTitleSelectable"})
+
+public class AccordionWrap<CONTROL extends Accordion> extends NodeWrap<CONTROL> {
+    
+    public static final String SELECTED_TITLED_PANE_PROP = "selectedTitledPane";
+    public static final String SELECTED_TITLE = "selectedTitle";
+    public static final String ITEMS_PROP = "titledPanes";
+
+    private Selectable<TitledPane> titledPaneSelectable = new TitledPaneSelectable();
+    private Selectable<String> stringSelectable = new StringSelectable();
+
+    /**
+     *
+     * @param env
+     * @param scene
+     * @param nd
+     */
+    @SuppressWarnings("unchecked")
+    public AccordionWrap(Environment env, CONTROL nd) {
+        super(env, nd);
+    }
+
+    @Override
+    public <INTERFACE extends ControlInterface> boolean is(Class<INTERFACE> interfaceClass) {
+        // Default Parent is Parent<Node> which is super
+        if (Selectable.class.equals(interfaceClass)) {
+            return true;
+        }
+        return super.is(interfaceClass);
+    }
+
+    @Override
+    public <TYPE, INTERFACE extends TypeControlInterface<TYPE>> boolean is(Class<INTERFACE> interfaceClass, Class<TYPE> type) {
+        if (Selectable.class.equals(interfaceClass)) {
+            return true;
+        }
+        return super.is(interfaceClass, type);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <INTERFACE extends ControlInterface> INTERFACE as(Class<INTERFACE> interfaceClass) {
+        if (Selectable.class.equals(interfaceClass)) {
+            return (INTERFACE) titledPaneSelectable;
+        }
+        return super.as(interfaceClass);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <TYPE, INTERFACE extends TypeControlInterface<TYPE>> INTERFACE as(Class<INTERFACE> interfaceClass, Class<TYPE> type) {
+        if (Selectable.class.equals(interfaceClass) && TitledPane.class.equals(type)) {
+            return (INTERFACE) titledPaneSelectable;
+        }
+        if (Selectable.class.equals(interfaceClass) && String.class.equals(type)) {
+            return (INTERFACE) stringSelectable;
+        }
+        return super.as(interfaceClass, type);
+    }
+
+    @Property(ITEMS_PROP)
+    public ObservableList<TitledPane> getItems() {
+        return new GetAction<ObservableList<TitledPane>>() {
+            @Override
+            public void run(Object... os) throws Exception {
+                setResult(getControl().getPanes());
+            }
+        }.dispatch(getEnvironment());
+    }
+
+    @Property(SELECTED_TITLED_PANE_PROP)
+    public TitledPane getSelectedItem() {
+        return new GetAction<TitledPane>() {
+            @Override
+            public void run(Object... os) throws Exception {
+                setResult(getControl().getExpandedPane());
+            }
+        }.dispatch(getEnvironment());
+    }
+
+    @Property(SELECTED_TITLE)
+    public String getSelectedTitle() {
+        return new GetAction<String>() {
+            @Override
+            public void run(Object... os) throws Exception {
+                TitledPane pane = getControl().getExpandedPane();
+                if (pane != null) {
+                    setResult(pane.getText());
+                } else {
+                    setResult(null);
+                }
+            }
+        }.dispatch(getEnvironment());
+    }
+
+    private class TitledPaneSelectable implements Selectable<TitledPane>, Selector<TitledPane> {
+
+        @Override
+        public List<TitledPane> getStates() {
+            return new GetAction<ArrayList<TitledPane>>() {
+                @Override
+                public void run(Object... parameters) {
+                    setResult(new ArrayList<TitledPane>(getItems()));
+                }
+
+                @Override
+                public String toString() {
+                    return "Fetching all data items from " + TitledPaneSelectable.this;
+                }
+            }.dispatch(getEnvironment());
+        }
+
+        @Override
+        public TitledPane getState() {
+            return getSelectedItem();
+        }
+
+        public Selector<TitledPane> selector() {
+            return this;
+        }
+
+        public Class getType() {
+            return TitledPane.class;
+        }
+
+        public void select(TitledPane state) {
+            if (getSelectedItem() != state) {
+                if (state == null) {
+                    state = getSelectedItem();
+                }
+                AccordionWrap.this.as(Parent.class, Node.class).lookup(TitledPane.class, new ByObject(state)).wrap().mouse().click();
+            }
+        }
+    }
+
+    private class StringSelectable implements Selectable<String>, Selector<String> {
+
+        @Override
+        public List<String> getStates() {
+            return new GetAction<ArrayList<String>>() {
+
+                @Override
+                public void run(Object... parameters) {
+                     ArrayList<String> list = new ArrayList<String>();
+                     for (TitledPane pane : getItems()) {
+                         list.add(pane.getText());
+                     }
+                    setResult(list);
+                }
+
+                @Override
+                public String toString() {
+                    return "Fetching all data items from " + StringSelectable.this;
+                }
+            }.dispatch(getEnvironment());
+        }
+
+        @Override
+        public String getState() {
+            return getSelectedTitle();
+        }
+
+        public Selector<String> selector() {
+            return this;
+        }
+
+        public Class getType() {
+            return TitledPane.class;
+        }
+
+        public void select(final String state) {
+            if (getState() != state) {
+                if (state == null) {
+                    AccordionWrap.this.as(Parent.class, Node.class).lookup(TitledPane.class, new ByObject(getSelectedItem())).wrap().mouse().click();
+                } else {
+                    AccordionWrap.this.as(Parent.class, Node.class).lookup(TitledPane.class, new LookupCriteria<TitledPane>() {
+                        public boolean check(TitledPane cntrl) {
+                            return cntrl.getText().equals(state);
+                        }
+                    }).wrap().mouse().click();
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/TabPaneWrap.java	Fri Jun 15 19:20:15 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/TabPaneWrap.java	Wed Jun 20 02:31:32 2012 +0400
@@ -27,19 +27,15 @@
 import java.util.ArrayList;
 import java.util.List;
 import javafx.collections.ObservableList;
-import javafx.scene.Scene;
 import javafx.scene.control.Tab;
 import javafx.scene.control.TabPane;
 import org.jemmy.JemmyException;
-import org.jemmy.Point;
 import org.jemmy.action.GetAction;
 import org.jemmy.control.ControlInterfaces;
 import org.jemmy.control.ControlType;
 import org.jemmy.control.Property;
 import org.jemmy.fx.NodeWrap;
-import org.jemmy.control.MethodProperties;
 import org.jemmy.env.Environment;
-import org.jemmy.fx.FXClickFocus;
 import org.jemmy.input.AbstractScroll;
 import org.jemmy.interfaces.ControlInterface;
 import org.jemmy.interfaces.Focus;
@@ -113,7 +109,7 @@
             return (INTERFACE) new TabParent(this, type);
         }
         if (Selectable.class.equals(interfaceClass)) {
-            return (INTERFACE) new TabPaneSelectable();
+            return (INTERFACE) objectSelectable;
         }
         return super.as(interfaceClass, type);
     }
@@ -155,7 +151,6 @@
         }
 
         @Override
-        @Property(Selectable.STATE_PROP_NAME)
         public Tab getState() {
             return getSelectedItem();
         }