changeset 32:f592be068a8e

JemmyFX: AccordionWrap modifications
author Oleg Barbashov <oleg.barbashov@oracle.com>
date Wed, 20 Jun 2012 15:07:22 +0400
parents 9db2cf30aeb5
children 1a668f909aca
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/control/AccordionWrap.java
diffstat 3 files changed, 79 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionApp.java	Wed Jun 20 02:31:32 2012 +0400
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionApp.java	Wed Jun 20 15:07:22 2012 +0400
@@ -20,6 +20,8 @@
 import javafx.stage.Stage;
 
 public class AccordionApp extends Application {
+    Accordion accordion = new Accordion();
+
     public static void main(String[] args) throws AWTException {
         launch(args);
     }
@@ -29,7 +31,6 @@
         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")));
@@ -39,10 +40,7 @@
         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);
-                }
+                reset();
             }
         });
         box.getChildren().add(reset);
@@ -53,5 +51,15 @@
         stage.setHeight(300);
 
         stage.show();
+
+        reset();
+    }
+
+    private void reset() {
+        TitledPane pane = accordion.getExpandedPane();
+        if (pane != null) {
+            pane.setExpanded(false);
+        }
+        accordion.getPanes().get(1).setExpanded(true);
     }
 }
--- a/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionTest.java	Wed Jun 20 02:31:32 2012 +0400
+++ b/tools/Jemmy/JemmyFX/samples/org/jemmy/samples/accordion/AccordionTest.java	Wed Jun 20 15:07:22 2012 +0400
@@ -9,11 +9,10 @@
 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.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -33,31 +32,12 @@
     }
 
     /**
-     * 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");
+        new AccordionDock(scene.asParent(), Accordion.class).
+                asTitleSelectable().selector().select("First pane");
     }
 
     /**
@@ -66,25 +46,42 @@
     @Test
     public void selectByTitlePane() {
         AccordionDock accordion = new AccordionDock(scene.asParent(), Accordion.class);
-
+        // first you need find a titled pane you are going to select
         TitledPaneDock first_pane = new TitledPaneDock(scene.asParent(), "First pane", StringComparePolicy.EXACT);
+        // then select it through selectable interface
         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.
+     * How to expand or collapse a single TitledPane.
+     */
+    @Test
+    public void expandAndCollapse() {
+        // you could manually collapse the expanded titled pane
+        new TitledPaneDock(new AccordionDock(scene.asParent(), Accordion.class).asParent(), "Second pane", StringComparePolicy.EXACT).
+                asCollapsible().collapse();
+        // similarly, you can expand
+        // note that titled pane is just another node an so you can find it within any container
+        new TitledPaneDock(scene.asParent(), "First pane", StringComparePolicy.EXACT).asExpandable().expand();
+    }
+
+    /**
+     * How to collapse everything.
      */
     @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);
+        // you can collapse everything by selecting null
+        new AccordionDock(scene.asParent(), Accordion.class).asTitleSelectable().selector().select(null);
+    }
+
+    /**
+     * How to use properties.
+     */
+    @Test
+    public void properties() {
+        AccordionDock accordion = new AccordionDock(scene.asParent(), Accordion.class);
+        // you can use following properties: SelectedTitle, Titles, SelectedTitledPane, TitledPanes
+        Assert.assertEquals(accordion.getSelectedTitle(), accordion.getTitles().get(1));
+        Assert.assertEquals(accordion.getSelectedTitledPane(), accordion.getTitledPanes().get(1));
     }
 }
--- a/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/AccordionWrap.java	Wed Jun 20 02:31:32 2012 +0400
+++ b/tools/Jemmy/JemmyFX/src/org/jemmy/fx/control/AccordionWrap.java	Wed Jun 20 15:07:22 2012 +0400
@@ -24,6 +24,7 @@
 import org.jemmy.interfaces.Selector;
 import org.jemmy.interfaces.TypeControlInterface;
 import org.jemmy.lookup.LookupCriteria;
+import org.jemmy.timing.State;
 
 @ControlType(Accordion.class)
 @ControlInterfaces(value = {Selectable.class, Selectable.class},
@@ -35,6 +36,7 @@
     public static final String SELECTED_TITLED_PANE_PROP = "selectedTitledPane";
     public static final String SELECTED_TITLE = "selectedTitle";
     public static final String ITEMS_PROP = "titledPanes";
+    public static final String TITLES_PROP = "titles";
 
     private Selectable<TitledPane> titledPaneSelectable = new TitledPaneSelectable();
     private Selectable<String> stringSelectable = new StringSelectable();
@@ -89,7 +91,7 @@
     }
 
     @Property(ITEMS_PROP)
-    public ObservableList<TitledPane> getItems() {
+    public List<TitledPane> getItems() {
         return new GetAction<ObservableList<TitledPane>>() {
             @Override
             public void run(Object... os) throws Exception {
@@ -98,6 +100,20 @@
         }.dispatch(getEnvironment());
     }
 
+    @Property(TITLES_PROP)
+    public List<String> getTitles() {
+        return new GetAction<List<String>>() {
+            @Override
+            public void run(Object... os) throws Exception {
+                ArrayList<String> list = new ArrayList<String>();
+                for (TitledPane pane : getItems()) {
+                    list.add(pane.getText());
+                }
+                setResult(list);
+            }
+        }.dispatch(getEnvironment());
+    }
+
     @Property(SELECTED_TITLED_PANE_PROP)
     public TitledPane getSelectedItem() {
         return new GetAction<TitledPane>() {
@@ -127,17 +143,7 @@
 
         @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());
+            return getItems();
         }
 
         @Override
@@ -153,12 +159,18 @@
             return TitledPane.class;
         }
 
-        public void select(TitledPane state) {
+        public void select(final TitledPane state) {
             if (getSelectedItem() != state) {
                 if (state == null) {
-                    state = getSelectedItem();
+                    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 ByObject(state)).wrap().mouse().click();
                 }
-                AccordionWrap.this.as(Parent.class, Node.class).lookup(TitledPane.class, new ByObject(state)).wrap().mouse().click();
+                AccordionWrap.this.waitState(new State<Boolean>() {
+                    public Boolean reached() {
+                        return getState() == state;
+                    }
+                }, Boolean.TRUE);
             }
         }
     }
@@ -167,22 +179,7 @@
 
         @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());
+            return getTitles();
         }
 
         @Override
@@ -199,7 +196,7 @@
         }
 
         public void select(final String state) {
-            if (getState() != state) {
+            if (getState() == null ? state != null : !getState().equals(state)) {
                 if (state == null) {
                     AccordionWrap.this.as(Parent.class, Node.class).lookup(TitledPane.class, new ByObject(getSelectedItem())).wrap().mouse().click();
                 } else {
@@ -208,6 +205,11 @@
                             return cntrl.getText().equals(state);
                         }
                     }).wrap().mouse().click();
+                    AccordionWrap.this.waitState(new State<Boolean>() {
+                        public Boolean reached() {
+                            return (getState() == null ? state == null : getState().equals(state));
+                        }
+                    }, Boolean.TRUE);
                 }
             }
         }