1818
1919import com .techsenger .annotations .Nullable ;
2020import javafx .scene .Node ;
21+ import javafx .scene .Scene ;
22+ import javafx .scene .control .Tab ;
2123
2224/**
2325 *
@@ -33,8 +35,6 @@ public final class FxViewUtils {
3335 * This method stores a reference to the view in the node's property map, allowing the view to be
3436 * retrieved later by traversing the JavaFX node tree. This is useful in scenarios where only a node is available
3537 * (e.g., during focus traversal or event handling) and the associated view needs to be identified.
36- * <p>
37- * This method should be called during initialization.
3838 *
3939 * @param node the JavaFX node to associate with the component; must not be {@code null}
4040 * @param view the view to associate with the node; must not be {@code null}
@@ -57,6 +57,21 @@ public static void setView(Node node, FxView<?> view) {
5757 return (FxView <?>) node .getProperties ().get (VIEW_KEY );
5858 }
5959
60+ /**
61+ * Removes the {@link FxView} associated with the specified {@link Node}.
62+ * <p>
63+ * This method clears the reference previously stored via {@link #setView(Node, FxView)} from the node's property
64+ * map. After calling this method, {@link #getView(Node)} will return {@code null} for the given node.
65+ * <p>
66+ * This can be useful during cleanup or when the association between a node and its view
67+ * is no longer valid.
68+ *
69+ * @param node the JavaFX node whose associated view should be removed; must not be {@code null}
70+ */
71+ public static void clearView (Node node ) {
72+ node .getProperties ().remove (VIEW_KEY );
73+ }
74+
6075 /**
6176 * Traverses the JavaFX node tree upward from the given {@link Node}, searching for the nearest node that has
6277 * an associated {@link ComponentFxView} component.
@@ -80,6 +95,50 @@ public static void setView(Node node, FxView<?> view) {
8095 return null ;
8196 }
8297
98+ /**
99+ * Associates the given root {@link FxView} with the specified JavaFX {@link Scene}.
100+ */
101+ public static void setView (Scene scene , FxView <?> root ) {
102+ scene .getProperties ().put (VIEW_KEY , root );
103+ }
104+
105+ /**
106+ * Returns the root {@link FxView} associated with the given {@link Scene}, or {@code null} if no view
107+ * has been associated with it.
108+ */
109+ public static @ Nullable FxView <?> getView (Scene scene ) {
110+ return (FxView <?>) scene .getProperties ().get (VIEW_KEY );
111+ }
112+
113+ /**
114+ * Removes the {@link FxView} associated with the specified {@link Scene}.
115+ */
116+ public static void clearView (Scene scene ) {
117+ scene .getProperties ().remove (VIEW_KEY );
118+ }
119+
120+ /**
121+ * Associates the given {@link FxView} view with the specified JavaFX {@link Tab}.
122+ */
123+ public static void setView (Tab tab , FxView <?> root ) {
124+ tab .getProperties ().put (VIEW_KEY , root );
125+ }
126+
127+ /**
128+ * Returns the {@link FxView} view associated with the given {@link Tab}, or {@code null} if no view has been
129+ * associated with it.
130+ */
131+ public static @ Nullable FxView <?> getView (Tab tab ) {
132+ return (FxView <?>) tab .getProperties ().get (VIEW_KEY );
133+ }
134+
135+ /**
136+ * Removes the {@link FxView} associated with the specified {@link Tab}.
137+ */
138+ public static void clearView (Tab tab ) {
139+ tab .getProperties ().remove (VIEW_KEY );
140+ }
141+
83142 private FxViewUtils () {
84143 // empty
85144 }
0 commit comments