Class SwingEntityTreeModel

java.lang.Object
javax.swing.tree.DefaultTreeModel
is.codion.swing.framework.model.SwingEntityTreeModel
All Implemented Interfaces:
Serializable, TreeModel

public final class SwingEntityTreeModel extends DefaultTreeModel
A basic tree model for viewing self-referential entities, using a SwingEntityTableModel as a data source. For instances use the swingEntityTreeModel(SwingEntityTableModel, ForeignKey) or swingEntityTreeModel(SwingEntityTableModel, ForeignKey, Function) factory methods.
See Also:
  • Method Details

    • getRoot

      Specified by:
      getRoot in interface TreeModel
      Overrides:
      getRoot in class DefaultTreeModel
      Returns:
      the root node
    • treeSelectionModel

      public TreeSelectionModel treeSelectionModel()
      Returns:
      the selection model
    • refreshRoot

      public void refreshRoot()
      Refreshes the root node, that is, reloads its children.
    • select

      public void select(Collection<Entity> entities)
      Selects the given entities in this tree model.
      Parameters:
      entities - the entities to select, an empty collection to clear the selection
    • refreshSelect

      public void refreshSelect(Collection<Entity> entities)
      Refreshes this tree and selects the given entities
      Parameters:
      entities - the modified entities
    • remove

      public void remove(Collection<Entity> entities)
      Removes the given entities from this tree model
      Parameters:
      entities - the entities to remove
    • swingEntityTreeModel

      public static SwingEntityTreeModel swingEntityTreeModel(SwingEntityTableModel tableModel, ForeignKey parentForeignKey)
      Instantiates a new SwingEntityTreeModel instance.
      Parameters:
      tableModel - the table model data source
      parentForeignKey - the foreign key referencing parent nodes
      Returns:
      a new SwingEntityTreeModel instance.
    • swingEntityTreeModel

      public static SwingEntityTreeModel swingEntityTreeModel(SwingEntityTableModel tableModel, ForeignKey parentForeignKey, Function<Entity,String> stringFunction)
      Instantiates a new SwingEntityTreeModel instance.
      Parameters:
      tableModel - the table model data source
      parentForeignKey - the foreign key referencing parent nodes
      stringFunction - the function for creating String representations of the entities
      Returns:
      a new SwingEntityTreeModel instance.