changeset 5178:62e08c34a629

RT-31168: reset CssFlag to clean so css will be reapplied if the node is added back later.
author David Grieve<david.grieve@oracle.com>
date Mon, 30 Sep 2013 14:52:56 -0400
parents bdc3f404c931
children 88a48547ab6c
files modules/controls/src/test/java/javafx/scene/control/MiscellaneousTests.java modules/graphics/src/main/java/javafx/scene/Node.java
diffstat 2 files changed, 75 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/controls/src/test/java/javafx/scene/control/MiscellaneousTests.java	Mon Sep 30 14:52:56 2013 -0400
@@ -0,0 +1,70 @@
+package javafx.scene.control;
+
+import com.sun.javafx.pgstub.StubToolkit;
+import com.sun.javafx.tk.TKPulseListener;
+import com.sun.javafx.tk.Toolkit;
+import javafx.scene.Group;
+import javafx.scene.Scene;
+import javafx.scene.shape.Rectangle;
+import javafx.stage.Stage;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: dgrieve
+ * Date: 9/30/13
+ * Time: 2:22 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class MiscellaneousTests {
+
+    @Test
+    public void test_RT_31168() {
+        //
+        // Make sure that a control added and removed from the scene-graph before css is processed
+        // gets css processed when it is added back in.
+
+        Button button = new Button("RT-31168");
+        Rectangle rectangle = new Rectangle(50,50);
+
+        Group container = new Group();
+        container.getChildren().add(rectangle);
+
+        Scene scene = new Scene(new Group(container, new Button("button")));
+
+        //
+        // Gotta put this in a window for the pulse listener to get hooked up (see Scene#impl_initPeer().
+        // Need the pulse listener since we want to enter root via Scene#doCSSPass()
+        //
+        Stage stage = new Stage();
+        stage.setScene(scene);
+        stage.show();
+
+        //
+        // Has to be a pulse since we want to enter from Scene.doCSSPass()
+        //
+        ((StubToolkit)Toolkit.getToolkit()).fireTestPulse();
+
+        container.getChildren().set(0, button);
+        container.getChildren().set(0, rectangle);
+
+        //
+        // Has to be a pulse since we want to enter from Scene.doCSSPass()
+        //
+        ((StubToolkit)Toolkit.getToolkit()).fireTestPulse();
+
+        // Should be null since the button was added and removed before the pulse processed css
+        assertNull(button.getBackground());
+
+        container.getChildren().set(0, button);
+
+        ((StubToolkit)Toolkit.getToolkit()).fireTestPulse();
+
+        // Should no longer be null
+        assertNotNull(button.getBackground());
+
+    }
+}
--- a/modules/graphics/src/main/java/javafx/scene/Node.java	Fri Sep 27 11:15:48 2013 -0700
+++ b/modules/graphics/src/main/java/javafx/scene/Node.java	Mon Sep 30 14:52:56 2013 -0400
@@ -721,6 +721,11 @@
                         // See the comments there, also.
                         //
                         impl_reapplyCSS();
+                    } else {
+                        // RT-31168: reset CssFlag to clean so css will be reapplied if the node is added back later.
+                        // If flag is REAPPLY, then impl_reapplyCSS() will just return and the call to
+                        // notifyParentsOfInvalidatedCSS() will be skipped thus leaving the node un-styled.
+                        cssFlag = CssFlags.CLEAN;
                     }
                     updateTreeVisible();
                     oldParent = newParent;