203 oldValue.expandedProperty().removeListener(weakTreeItemExpandedInvalidationListener); 204 } 205 206 oldValue = get(); 207 208 if (oldValue != null) { 209 oldIsExpanded = oldValue.isExpanded(); 210 oldValue.expandedProperty().addListener(weakTreeItemExpandedInvalidationListener); 211 // fake an invalidation to ensure updated pseudo-class state 212 weakTreeItemExpandedInvalidationListener.invalidated(oldValue.expandedProperty()); 213 } 214 215 } 216 }; 217 private void setTreeItem(TreeItem<T> value) { 218 treeItem.set(value); 219 } 220 221 /** 222 * Returns the TreeItem currently set in this TreeCell. 223 */ 224 public final TreeItem<T> getTreeItem() { return treeItem.get(); } 225 226 /** 227 * Each TreeCell represents at most a single {@link TreeItem}, which is 228 * represented by this property. 229 */ 230 public final ReadOnlyObjectProperty<TreeItem<T>> treeItemProperty() { return treeItem.getReadOnlyProperty(); } 231 232 233 234 // --- Disclosure Node 235 private ObjectProperty<Node> disclosureNode = new SimpleObjectProperty<Node>(this, "disclosureNode"); 236 237 /** 238 * The node to use as the "disclosure" triangle, or toggle, used for 239 * expanding and collapsing items. This is only used in the case of 240 * an item in the tree which contains child items. If not specified, the 241 * TreeCell's Skin implementation is responsible for providing a default 242 * disclosure node. 243 */ 244 public final void setDisclosureNode(Node value) { disclosureNodeProperty().set(value); } 245 246 /** 247 * Returns the current disclosure node set in this TreeCell. 248 */ 249 public final Node getDisclosureNode() { return disclosureNode.get(); } 250 251 /** 252 * The disclosure node is commonly seen represented as a triangle that rotates 253 * on screen to indicate whether or not the TreeItem that it is placed 254 * beside is expanded or collapsed. 255 */ 256 public final ObjectProperty<Node> disclosureNodeProperty() { return disclosureNode; } 257 258 259 // --- TreeView 260 private ReadOnlyObjectWrapper<TreeView<T>> treeView = new ReadOnlyObjectWrapper<TreeView<T>>() { 261 private WeakReference<TreeView<T>> weakTreeViewRef; 262 @Override protected void invalidated() { 263 MultipleSelectionModel<TreeItem<T>> sm; 264 FocusModel<TreeItem<T>> fm; 265 266 if (weakTreeViewRef != null) { 267 TreeView<T> oldTreeView = weakTreeViewRef.get(); 268 if (oldTreeView != null) { 269 // remove old listeners 270 sm = oldTreeView.getSelectionModel(); 271 if (sm != null) { 272 sm.getSelectedIndices().removeListener(weakSelectedListener); 273 } 274 311 312 updateItem(-1); 313 requestLayout(); 314 } 315 316 @Override 317 public Object getBean() { 318 return TreeCell.this; 319 } 320 321 @Override 322 public String getName() { 323 return "treeView"; 324 } 325 }; 326 327 private void setTreeView(TreeView<T> value) { treeView.set(value); } 328 329 /** 330 * Returns the TreeView associated with this TreeCell. 331 */ 332 public final TreeView<T> getTreeView() { return treeView.get(); } 333 334 /** 335 * A TreeCell is explicitly linked to a single {@link TreeView} instance, 336 * which is represented by this property. 337 */ 338 public final ReadOnlyObjectProperty<TreeView<T>> treeViewProperty() { return treeView.getReadOnlyProperty(); } 339 340 341 342 /*************************************************************************** 343 * * 344 * Public API * 345 * * 346 **************************************************************************/ 347 348 /** {@inheritDoc} */ 349 @Override public void startEdit() { 350 if (isEditing()) return; 351 352 final TreeView<T> tree = getTreeView(); 353 if (! isEditable() || (tree != null && ! tree.isEditable())) { 354 // if (Logging.getControlsLogger().isLoggable(PlatformLogger.SEVERE)) { 355 // Logging.getControlsLogger().severe( 356 // "Can not call TreeCell.startEdit() on this TreeCell, as it " 583 updateEditingIndex = false; 584 cancelEdit(); 585 updateEditingIndex = true; 586 } 587 } 588 589 590 591 /*************************************************************************** 592 * * 593 * Expert API * 594 * * 595 **************************************************************************/ 596 597 598 599 /** 600 * Updates the TreeView associated with this TreeCell. 601 * 602 * @param tree The new TreeView that should be associated with this TreeCell. 603 * @expert This function is intended to be used by experts, primarily 604 * by those implementing new Skins. It is not common 605 * for developers or designers to access this function directly. 606 */ 607 public final void updateTreeView(TreeView<T> tree) { 608 setTreeView(tree); 609 } 610 611 /** 612 * Updates the TreeItem associated with this TreeCell. 613 * 614 * @param treeItem The new TreeItem that should be associated with this 615 * TreeCell. 616 * @expert This function is intended to be used by experts, primarily 617 * by those implementing new Skins. It is not common 618 * for developers or designers to access this function directly. 619 */ 620 public final void updateTreeItem(TreeItem<T> treeItem) { 621 TreeItem<T> _treeItem = getTreeItem(); 622 if (_treeItem != null) { 623 _treeItem.leafProperty().removeListener(weakLeafListener); 624 } 625 setTreeItem(treeItem); 626 if (treeItem != null) { 627 treeItem.leafProperty().addListener(weakLeafListener); 628 } 629 } 630 631 632 633 /*************************************************************************** 634 * * 635 * Stylesheet Handling * 636 * * | 203 oldValue.expandedProperty().removeListener(weakTreeItemExpandedInvalidationListener); 204 } 205 206 oldValue = get(); 207 208 if (oldValue != null) { 209 oldIsExpanded = oldValue.isExpanded(); 210 oldValue.expandedProperty().addListener(weakTreeItemExpandedInvalidationListener); 211 // fake an invalidation to ensure updated pseudo-class state 212 weakTreeItemExpandedInvalidationListener.invalidated(oldValue.expandedProperty()); 213 } 214 215 } 216 }; 217 private void setTreeItem(TreeItem<T> value) { 218 treeItem.set(value); 219 } 220 221 /** 222 * Returns the TreeItem currently set in this TreeCell. 223 * @return the TreeItem currently set in this TreeCell 224 */ 225 public final TreeItem<T> getTreeItem() { return treeItem.get(); } 226 227 /** 228 * Each TreeCell represents at most a single {@link TreeItem}, which is 229 * represented by this property. 230 * @return the TreeItem property representing this TreeCell 231 */ 232 public final ReadOnlyObjectProperty<TreeItem<T>> treeItemProperty() { return treeItem.getReadOnlyProperty(); } 233 234 235 236 // --- Disclosure Node 237 private ObjectProperty<Node> disclosureNode = new SimpleObjectProperty<Node>(this, "disclosureNode"); 238 239 /** 240 * The node to use as the "disclosure" triangle, or toggle, used for 241 * expanding and collapsing items. This is only used in the case of 242 * an item in the tree which contains child items. If not specified, the 243 * TreeCell's Skin implementation is responsible for providing a default 244 * disclosure node. 245 * @param value the disclosure node 246 */ 247 public final void setDisclosureNode(Node value) { disclosureNodeProperty().set(value); } 248 249 /** 250 * Returns the current disclosure node set in this TreeCell. 251 * @return the current disclosure node set in this TreeCell 252 */ 253 public final Node getDisclosureNode() { return disclosureNode.get(); } 254 255 /** 256 * The disclosure node is commonly seen represented as a triangle that rotates 257 * on screen to indicate whether or not the TreeItem that it is placed 258 * beside is expanded or collapsed. 259 * @return the disclosure node 260 */ 261 public final ObjectProperty<Node> disclosureNodeProperty() { return disclosureNode; } 262 263 264 // --- TreeView 265 private ReadOnlyObjectWrapper<TreeView<T>> treeView = new ReadOnlyObjectWrapper<TreeView<T>>() { 266 private WeakReference<TreeView<T>> weakTreeViewRef; 267 @Override protected void invalidated() { 268 MultipleSelectionModel<TreeItem<T>> sm; 269 FocusModel<TreeItem<T>> fm; 270 271 if (weakTreeViewRef != null) { 272 TreeView<T> oldTreeView = weakTreeViewRef.get(); 273 if (oldTreeView != null) { 274 // remove old listeners 275 sm = oldTreeView.getSelectionModel(); 276 if (sm != null) { 277 sm.getSelectedIndices().removeListener(weakSelectedListener); 278 } 279 316 317 updateItem(-1); 318 requestLayout(); 319 } 320 321 @Override 322 public Object getBean() { 323 return TreeCell.this; 324 } 325 326 @Override 327 public String getName() { 328 return "treeView"; 329 } 330 }; 331 332 private void setTreeView(TreeView<T> value) { treeView.set(value); } 333 334 /** 335 * Returns the TreeView associated with this TreeCell. 336 * @return the TreeView associated with this TreeCell 337 */ 338 public final TreeView<T> getTreeView() { return treeView.get(); } 339 340 /** 341 * A TreeCell is explicitly linked to a single {@link TreeView} instance, 342 * which is represented by this property. 343 * @return the TreeView property of this TreeCell 344 */ 345 public final ReadOnlyObjectProperty<TreeView<T>> treeViewProperty() { return treeView.getReadOnlyProperty(); } 346 347 348 349 /*************************************************************************** 350 * * 351 * Public API * 352 * * 353 **************************************************************************/ 354 355 /** {@inheritDoc} */ 356 @Override public void startEdit() { 357 if (isEditing()) return; 358 359 final TreeView<T> tree = getTreeView(); 360 if (! isEditable() || (tree != null && ! tree.isEditable())) { 361 // if (Logging.getControlsLogger().isLoggable(PlatformLogger.SEVERE)) { 362 // Logging.getControlsLogger().severe( 363 // "Can not call TreeCell.startEdit() on this TreeCell, as it " 590 updateEditingIndex = false; 591 cancelEdit(); 592 updateEditingIndex = true; 593 } 594 } 595 596 597 598 /*************************************************************************** 599 * * 600 * Expert API * 601 * * 602 **************************************************************************/ 603 604 605 606 /** 607 * Updates the TreeView associated with this TreeCell. 608 * 609 * @param tree The new TreeView that should be associated with this TreeCell. 610 * Note: This function is intended to be used by experts, primarily 611 * by those implementing new Skins. It is not common 612 * for developers or designers to access this function directly. 613 */ 614 public final void updateTreeView(TreeView<T> tree) { 615 setTreeView(tree); 616 } 617 618 /** 619 * Updates the TreeItem associated with this TreeCell. 620 * 621 * @param treeItem The new TreeItem that should be associated with this 622 * TreeCell. 623 * Note: This function is intended to be used by experts, primarily 624 * by those implementing new Skins. It is not common 625 * for developers or designers to access this function directly. 626 */ 627 public final void updateTreeItem(TreeItem<T> treeItem) { 628 TreeItem<T> _treeItem = getTreeItem(); 629 if (_treeItem != null) { 630 _treeItem.leafProperty().removeListener(weakLeafListener); 631 } 632 setTreeItem(treeItem); 633 if (treeItem != null) { 634 treeItem.leafProperty().addListener(weakLeafListener); 635 } 636 } 637 638 639 640 /*************************************************************************** 641 * * 642 * Stylesheet Handling * 643 * * |