Module org.snapfx

Interface DockNodeFactory


public interface DockNodeFactory
Factory interface for creating DockNode instances during deserialization.

When loading a saved layout, the framework needs to recreate the DockNodes that were part of the original layout. Since only the node IDs are stored in the JSON (not the actual JavaFX content), the application must provide a way to recreate nodes from their IDs.

Usage Example:


 DockNodeFactory factory = nodeId -> {
     return switch (nodeId) {
         case "projectExplorer" -> createProjectExplorer();
         case "mainEditor" -> createMainEditor();
         case "console" -> createConsole();
         default -> null;
     };
 };

 snapFX.setNodeFactory(factory);
 try {
     snapFX.loadLayout(json);
 } catch (DockLayoutLoadException e) {
     // Handle invalid/corrupt layout JSON.
 }
 

Important: The factory must create DockNodes with the same ID that was used when the layout was saved. Use the DockNode(String, Node, String) constructor with the provided nodeId.

  • Method Details

    • createNode

      DockNode createNode(String nodeId)
      Creates a DockNode for the given ID.

      This method is called during layout deserialization for each node ID found in the saved layout. The implementation must create and return a DockNode with the given ID and appropriate content.

      Parameters:
      nodeId - The unique identifier of the node to create (same ID as used when saving)
      Returns:
      A DockNode with the specified ID and recreated content, or null if the ID is unknown
    • createUnknownNode

      default DockNode createUnknownNode(DockNodeFactory.UnknownElementContext context)
      Optional hook for unsupported serialized element types.

      The serializer invokes this callback when it encounters an unknown element type in the saved layout (for example "DockNode!!!"). Returning null keeps the framework default behavior and inserts the built-in placeholder node.

      Parameters:
      context - Details about the unsupported element and its JSON location
      Returns:
      Custom replacement node, or null to use the framework placeholder