changeset 7620:5c4df3d3ef9c

RT-37454: Node lookup with TabPane
author David Grieve<david.grieve@oracle.com>
date Mon, 04 Aug 2014 16:46:27 -0400
parents 39c4399a3630
children bda1da3ab917
files modules/controls/src/main/java/javafx/scene/control/Tab.java modules/controls/src/main/java/javafx/scene/control/TabPane.java
diffstat 2 files changed, 71 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/Tab.java	Mon Aug 04 16:42:03 2014 -0400
+++ b/modules/controls/src/main/java/javafx/scene/control/Tab.java	Mon Aug 04 16:46:27 2014 -0400
@@ -50,9 +50,11 @@
 import com.sun.javafx.event.EventHandlerManager;
 
 import java.lang.ref.WeakReference;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 
 import javafx.beans.DefaultProperty;
 import javafx.beans.InvalidationListener;
@@ -792,6 +794,42 @@
         eventHandlerManager.setEventHandler(eventType, eventHandler);
     }
 
+    /*
+     * See Node#lookup(String)
+     */
+    Node lookup(String selector) {
+        if (selector == null) return null;
+        Node n = null;
+        if (getContent() != null) {
+            n = getContent().lookup(selector);
+        }
+        if (n == null && getGraphic() != null) {
+            n = getGraphic().lookup(selector);
+        }
+        return n;
+    }
+
+    /*
+     * See Node#lookupAll(String)
+     */
+    List<Node> lookupAll(String selector) {
+        final List<Node> results = new ArrayList<>();
+        if (getContent() != null) {
+            Set set = getContent().lookupAll(selector);
+            if (!set.isEmpty()) {
+                results.addAll(set);
+            }
+        }
+        if (getGraphic() != null) {
+            Set set = getGraphic().lookupAll(selector);
+            if (!set.isEmpty()) {
+                results.addAll(set);
+            }
+        }
+        return results;
+    }
+
+
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o) return true;
--- a/modules/controls/src/main/java/javafx/scene/control/TabPane.java	Mon Aug 04 16:42:03 2014 -0400
+++ b/modules/controls/src/main/java/javafx/scene/control/TabPane.java	Mon Aug 04 16:46:27 2014 -0400
@@ -27,8 +27,12 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
+import com.sun.javafx.collections.UnmodifiableListSet;
+import com.sun.javafx.css.Selector;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.property.ObjectProperty;
@@ -52,6 +56,7 @@
 import javafx.beans.DefaultProperty;
 import javafx.css.Styleable;
 import javafx.css.StyleableProperty;
+import javafx.scene.Node;
 
 /**
  * <p>A control that allows switching between a group of {@link Tab Tabs}.  Only one tab
@@ -500,6 +505,34 @@
         return new TabPaneSkin(this);
     }
 
+    /** {@inheritDoc} */
+    @Override public Node lookup(String selector) {
+        Node n = super.lookup(selector);
+        if (n == null) {
+            for(Tab tab : tabs) {
+                n = tab.lookup(selector);
+                if (n != null) break;
+            }
+        }
+        return n;
+    }
+
+    /** {@inheritDoc} */
+    public Set<Node> lookupAll(String selector) {
+
+        if (selector == null) return null;
+
+        final List<Node> results = new ArrayList<>();
+
+        results.addAll(super.lookupAll(selector));
+        for(Tab tab : tabs) {
+            results.addAll(tab.lookupAll(selector));
+        }
+
+        return new UnmodifiableListSet<Node>(results);
+    }
+
+
     /***************************************************************************
      *                                                                         *
      *                         Stylesheet Handling                             *