Class DockingContext

java.lang.Object
com.dlsc.gemsfx.docking.DockingContext

public class DockingContext extends Object
Owns the factories and the pane membership of a docking setup and enforces dockable ID uniqueness across all of its panes. All model changes must happen on the JavaFX application thread. Docking decisions are logged at FINE level using this class's logger.

Floating windows are tied to the stage hosting the pane they were floated from. When that host stage is hidden, its floating windows are closed and their dockables are removed and disposed without consulting close permissions, because the host is already gone at that point. Applications whose dockables can veto closing, e.g. because of unsaved changes, should call requestCloseAll() from the host stage's close request handler and consume the event when it returns false.

  • Property Details

    • dockingEnabled

      public final javafx.beans.property.BooleanProperty dockingEnabledProperty
      Controls whether users can rearrange existing dockables through docking gestures and built-in docking actions. Disabling this property does not restrict programmatic move operations.
      See Also:
    • floatingEnabled

      public final javafx.beans.property.BooleanProperty floatingEnabledProperty
      Controls whether dragging a dockable or tab group outside all panes creates a floating window. When disabled, the drop leaves the layout unchanged and the default tab group menu hides its float action. The default is true. This setting does not restrict explicit programmatic floating operations or layout restoration.
      See Also:
    • paneFactory

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<DockingContext, DockingPane>> paneFactoryProperty
      Factory used to create panes for this context, including floating and restored panes. The default creates a DockingPane. Each invocation must return a fresh, unparented, non-null pane belonging to the supplied context. The factory itself must not be null. It is invoked on the JavaFX application thread. Changes apply only to subsequently created panes. A primary pane already in use is retained when restoring a layout.
      See Also:
    • tabFactory

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<Dockable, javafx.scene.Node>> tabFactoryProperty
      Factory creating the entire tab header for each dockable. The default creates a DockingTab, including its title, graphic, optional toolbar, actions menu and help button, and close button. A null factory also uses this default.

      The factory is invoked on the JavaFX application thread whenever tabs are rebuilt and must return a fresh, unparented, non-null node on every invocation. Changing the factory refreshes existing tabs in all panes of this context, including floating panes.

      The workspace applies the docking-tab style class, the selected pseudo-class, accessibility, keyboard actions, and docking drag handlers to the returned node. A custom header supplies its own close button, if desired, invoking requestCloseDockable(Dockable).

      See Also:
    • tabPaneHeaderFactory

      public final javafx.beans.property.ObjectProperty<BiFunction<DockingPane, List<Dockable>, javafx.scene.Node>> tabPaneHeaderFactoryProperty
      Factory for an optional node at the right edge of each tab group's header strip. It receives the owning pane and an immutable snapshot of the group's dockables in tab order. The returned node is wrapped in a stack pane styled as an unselected tab. The factory or its result may be null; otherwise each invocation must return a fresh, unparented node. The default creates a DockingTabPaneHeader for closing, floating internally or in a window, docking internally floating groups back into their pane, and maximizing docked groups.

      The factory is invoked on the JavaFX application thread when groups are rebuilt, including when their membership changes. Changing it refreshes existing groups in all panes.

      See Also:
  • Constructor Details

    • DockingContext

      public DockingContext(DockableFactory dockableFactory, DockingStageFactory stageFactory)
      Creates a context. The stage factory is only stored for later floating-window support.
      Parameters:
      dockableFactory - resolves dockables on explicit open requests
      stageFactory - creates stages hosting panes
  • Method Details

    • getSelectionModel

      public final DockingSelectionModel getSelectionModel()
      Returns the selection model spanning all panes in this context.
      Returns:
      the docking selection model
    • addEventHandler

      public final <E extends javafx.event.Event> void addEventHandler(javafx.event.EventType<E> eventType, javafx.event.EventHandler<? super E> handler)
      Registers a handler for a docking event type and its subtypes. Handlers are called synchronously on the JavaFX application thread. They may perform nested docking operations; handler exceptions are logged and do not interrupt other handlers or required cleanup. Layout restoration does not emit docking events.
      Type Parameters:
      E - the event class
      Parameters:
      eventType - the event type
      handler - the handler
      Throws:
      IllegalStateException - if called off the JavaFX application thread
    • removeEventHandler

      public final <E extends javafx.event.Event> void removeEventHandler(javafx.event.EventType<E> eventType, javafx.event.EventHandler<? super E> handler)
      Removes a previously registered event handler.
      Type Parameters:
      E - the event class
      Parameters:
      eventType - the event type
      handler - the handler
      Throws:
      IllegalStateException - if called off the JavaFX application thread
    • getDockableFactory

      public final DockableFactory getDockableFactory()
      Returns the factory used to resolve dockables by ID.
      Returns:
      the dockable factory
    • getStageFactory

      public final DockingStageFactory getStageFactory()
      Returns the factory used to create floating stages.
      Returns:
      the stage factory
    • dockingEnabledProperty

      public final javafx.beans.property.BooleanProperty dockingEnabledProperty()
      Controls whether users can rearrange existing dockables through docking gestures and built-in docking actions. Disabling this property does not restrict programmatic move operations.
      Returns:
      the docking-enabled property
      See Also:
    • isDockingEnabled

      public final boolean isDockingEnabled()
      Gets the value of the dockingEnabled property.
      Property description:
      Controls whether users can rearrange existing dockables through docking gestures and built-in docking actions. Disabling this property does not restrict programmatic move operations.
      Returns:
      the value of the dockingEnabled property
      See Also:
    • setDockingEnabled

      public final void setDockingEnabled(boolean enabled)
      Sets the value of the dockingEnabled property.
      Property description:
      Controls whether users can rearrange existing dockables through docking gestures and built-in docking actions. Disabling this property does not restrict programmatic move operations.
      Parameters:
      enabled - the value for the dockingEnabled property
      See Also:
    • floatingEnabledProperty

      public final javafx.beans.property.BooleanProperty floatingEnabledProperty()
      Controls whether dragging a dockable or tab group outside all panes creates a floating window. When disabled, the drop leaves the layout unchanged and the default tab group menu hides its float action. The default is true. This setting does not restrict explicit programmatic floating operations or layout restoration.
      Returns:
      the floating-enabled property
      See Also:
    • isFloatingEnabled

      public final boolean isFloatingEnabled()
      Gets the value of the floatingEnabled property.
      Property description:
      Controls whether dragging a dockable or tab group outside all panes creates a floating window. When disabled, the drop leaves the layout unchanged and the default tab group menu hides its float action. The default is true. This setting does not restrict explicit programmatic floating operations or layout restoration.
      Returns:
      the value of the floatingEnabled property
      See Also:
    • setFloatingEnabled

      public final void setFloatingEnabled(boolean enabled)
      Sets the value of the floatingEnabled property.
      Property description:
      Controls whether dragging a dockable or tab group outside all panes creates a floating window. When disabled, the drop leaves the layout unchanged and the default tab group menu hides its float action. The default is true. This setting does not restrict explicit programmatic floating operations or layout restoration.
      Parameters:
      enabled - the value for the floatingEnabled property
      See Also:
    • paneFactoryProperty

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<DockingContext, DockingPane>> paneFactoryProperty()
      Factory used to create panes for this context, including floating and restored panes. The default creates a DockingPane. Each invocation must return a fresh, unparented, non-null pane belonging to the supplied context. The factory itself must not be null. It is invoked on the JavaFX application thread. Changes apply only to subsequently created panes. A primary pane already in use is retained when restoring a layout.
      Returns:
      the pane factory property
      See Also:
    • getPaneFactory

      public final javafx.util.Callback<DockingContext, DockingPane> getPaneFactory()
      Gets the value of the paneFactory property.
      Property description:
      Factory used to create panes for this context, including floating and restored panes. The default creates a DockingPane. Each invocation must return a fresh, unparented, non-null pane belonging to the supplied context. The factory itself must not be null. It is invoked on the JavaFX application thread. Changes apply only to subsequently created panes. A primary pane already in use is retained when restoring a layout.
      Returns:
      the value of the paneFactory property
      See Also:
    • setPaneFactory

      public final void setPaneFactory(javafx.util.Callback<DockingContext, DockingPane> factory)
      Sets the value of the paneFactory property.
      Property description:
      Factory used to create panes for this context, including floating and restored panes. The default creates a DockingPane. Each invocation must return a fresh, unparented, non-null pane belonging to the supplied context. The factory itself must not be null. It is invoked on the JavaFX application thread. Changes apply only to subsequently created panes. A primary pane already in use is retained when restoring a layout.
      Parameters:
      factory - the value for the paneFactory property
      See Also:
    • tabFactoryProperty

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<Dockable, javafx.scene.Node>> tabFactoryProperty()
      Factory creating the entire tab header for each dockable. The default creates a DockingTab, including its title, graphic, optional toolbar, actions menu and help button, and close button. A null factory also uses this default.

      The factory is invoked on the JavaFX application thread whenever tabs are rebuilt and must return a fresh, unparented, non-null node on every invocation. Changing the factory refreshes existing tabs in all panes of this context, including floating panes.

      The workspace applies the docking-tab style class, the selected pseudo-class, accessibility, keyboard actions, and docking drag handlers to the returned node. A custom header supplies its own close button, if desired, invoking requestCloseDockable(Dockable).

      Returns:
      the tab factory property
      See Also:
    • getTabFactory

      public final javafx.util.Callback<Dockable, javafx.scene.Node> getTabFactory()
      Gets the value of the tabFactory property.
      Property description:
      Factory creating the entire tab header for each dockable. The default creates a DockingTab, including its title, graphic, optional toolbar, actions menu and help button, and close button. A null factory also uses this default.

      The factory is invoked on the JavaFX application thread whenever tabs are rebuilt and must return a fresh, unparented, non-null node on every invocation. Changing the factory refreshes existing tabs in all panes of this context, including floating panes.

      The workspace applies the docking-tab style class, the selected pseudo-class, accessibility, keyboard actions, and docking drag handlers to the returned node. A custom header supplies its own close button, if desired, invoking requestCloseDockable(Dockable).

      Returns:
      the value of the tabFactory property
      See Also:
    • setTabFactory

      public final void setTabFactory(javafx.util.Callback<Dockable, javafx.scene.Node> factory)
      Sets the value of the tabFactory property.
      Property description:
      Factory creating the entire tab header for each dockable. The default creates a DockingTab, including its title, graphic, optional toolbar, actions menu and help button, and close button. A null factory also uses this default.

      The factory is invoked on the JavaFX application thread whenever tabs are rebuilt and must return a fresh, unparented, non-null node on every invocation. Changing the factory refreshes existing tabs in all panes of this context, including floating panes.

      The workspace applies the docking-tab style class, the selected pseudo-class, accessibility, keyboard actions, and docking drag handlers to the returned node. A custom header supplies its own close button, if desired, invoking requestCloseDockable(Dockable).

      Parameters:
      factory - the value for the tabFactory property
      See Also:
    • tabPaneHeaderFactoryProperty

      public final javafx.beans.property.ObjectProperty<BiFunction<DockingPane, List<Dockable>, javafx.scene.Node>> tabPaneHeaderFactoryProperty()
      Factory for an optional node at the right edge of each tab group's header strip. It receives the owning pane and an immutable snapshot of the group's dockables in tab order. The returned node is wrapped in a stack pane styled as an unselected tab. The factory or its result may be null; otherwise each invocation must return a fresh, unparented node. The default creates a DockingTabPaneHeader for closing, floating internally or in a window, docking internally floating groups back into their pane, and maximizing docked groups.

      The factory is invoked on the JavaFX application thread when groups are rebuilt, including when their membership changes. Changing it refreshes existing groups in all panes.

      Returns:
      the tab pane header factory property
      See Also:
    • getTabPaneHeaderFactory

      public final BiFunction<DockingPane, List<Dockable>, javafx.scene.Node> getTabPaneHeaderFactory()
      Gets the value of the tabPaneHeaderFactory property.
      Property description:
      Factory for an optional node at the right edge of each tab group's header strip. It receives the owning pane and an immutable snapshot of the group's dockables in tab order. The returned node is wrapped in a stack pane styled as an unselected tab. The factory or its result may be null; otherwise each invocation must return a fresh, unparented node. The default creates a DockingTabPaneHeader for closing, floating internally or in a window, docking internally floating groups back into their pane, and maximizing docked groups.

      The factory is invoked on the JavaFX application thread when groups are rebuilt, including when their membership changes. Changing it refreshes existing groups in all panes.

      Returns:
      the value of the tabPaneHeaderFactory property
      See Also:
    • setTabPaneHeaderFactory

      public final void setTabPaneHeaderFactory(BiFunction<DockingPane, List<Dockable>, javafx.scene.Node> factory)
      Sets the value of the tabPaneHeaderFactory property.
      Property description:
      Factory for an optional node at the right edge of each tab group's header strip. It receives the owning pane and an immutable snapshot of the group's dockables in tab order. The returned node is wrapped in a stack pane styled as an unselected tab. The factory or its result may be null; otherwise each invocation must return a fresh, unparented node. The default creates a DockingTabPaneHeader for closing, floating internally or in a window, docking internally floating groups back into their pane, and maximizing docked groups.

      The factory is invoked on the JavaFX application thread when groups are rebuilt, including when their membership changes. Changing it refreshes existing groups in all panes.

      Parameters:
      factory - the value for the tabPaneHeaderFactory property
      See Also:
    • getDockableDropPredicate

      public final Predicate<javafx.scene.input.DragEvent> getDockableDropPredicate()
      Returns the predicate recognizing external drags that should create dockables.
      Returns:
      the acceptance predicate, initially rejecting all events
    • setDockableDropPredicate

      public final void setDockableDropPredicate(Predicate<javafx.scene.input.DragEvent> predicate)
      Sets the lightweight predicate evaluated during drag-over and drop. It must not create dockables or mutate the layout. Reject unrelated content drags so their events remain available to dockable content.
      Parameters:
      predicate - the non-null acceptance predicate
    • getDockableDropFactory

      public final javafx.util.Callback<javafx.scene.input.DragEvent, Dockable> getDockableDropFactory()
      Returns the factory invoked only when an accepted external drag is dropped at a valid docking location.
      Returns:
      the drop factory, or null if external docking is disabled
    • setDockableDropFactory

      public final void setDockableDropFactory(javafx.util.Callback<javafx.scene.input.DragEvent, Dockable> factory)
      Sets the factory creating a new dockable from the drop event. The dockable must have a unique ID in this context. Returning null declines the drop without changing the layout.
      Parameters:
      factory - the drop factory, or null to disable external docking
    • canAcceptDockableDrop

      public final boolean canAcceptDockableDrop(javafx.scene.input.DragEvent event)
      Tests whether an external drag may create a dockable without invoking the drop factory.
      Parameters:
      event - the drag event
      Returns:
      true if a factory is configured and the predicate accepts the event
    • dropDockable

      public final Optional<Dockable> dropDockable(DockingPane pane, javafx.scene.input.DragEvent event, String targetId, DockingPosition position)
      Creates and opens a dockable from an accepted drop, selecting it at the requested location. The factory is called once, after validating the target. Existing dockables are never replaced.
      Parameters:
      pane - the destination pane belonging to this context
      event - the drop event passed to the factory
      targetId - the target dockable ID, or null for an outer edge or an empty pane
      position - the requested docking position; CENTER with a null target requires an empty pane
      Returns:
      the new dockable, or empty if the target or event is rejected or the factory declines
      Throws:
      IllegalStateException - if called off the FX thread or the factory returns an already-open ID
    • createPane

      public DockingPane createPane()
      Creates a pane attached to this context.
      Returns:
      the new pane
    • openDockable

      public Optional<Dockable> openDockable(DockingPane pane, String id, DockingPosition position)
      Opens the dockable with the given ID in the pane. If the ID is already open, the existing dockable is activated instead. The dockable factory is only consulted for IDs that are not yet open.
      Parameters:
      pane - a pane created by this context
      id - the dockable ID
      position - the requested position
      Returns:
      the opened or activated dockable, or empty if the factory cannot resolve the ID
      Throws:
      IllegalArgumentException - if the pane belongs to another context
      IllegalStateException - if called off the FX thread, the factory returns a dockable with another ID, or the returned instance is currently being closed
    • floatDockable

      public DockingPane floatDockable(String id, double screenX, double screenY)
      Creates a new floating pane containing only the given dockable and positions its stage at the screen coordinates from the drag/drop event.
      Parameters:
      id - the dockable ID
      screenX - target screen x coordinate
      screenY - target screen y coordinate
      Returns:
      the floating pane, or null if the source pane has a maximized group
    • floatTabGroup

      public final DockingPane floatTabGroup(String id, double screenX, double screenY)
      Floats the entire tab group containing the given dockable in one window. Tab order and the group's selected tab are preserved.
      Parameters:
      id - a dockable in the group to float
      screenX - target screen x coordinate
      screenY - target screen y coordinate
      Returns:
      the floating pane, or null if the source pane has a maximized group
      Throws:
      IllegalArgumentException - if the dockable is not open in this context
    • floatDockableInternally

      public final void floatDockableInternally(String id, javafx.geometry.Rectangle2D bounds)
      Moves one open dockable into an internal floating frame in its current pane. Does not create a window and is independent of floatingEnabledProperty(). Does nothing while the pane has a maximized group.
      Parameters:
      id - the open dockable ID
      bounds - requested bounds relative to the pane's content area
      Throws:
      IllegalArgumentException - if the ID or geometry is invalid
    • floatTabGroupInternally

      public final void floatTabGroupInternally(String id, javafx.geometry.Rectangle2D bounds)
      Moves an open dockable's entire tab group into an internal floating frame, preserving tab order and selection. Does nothing while the pane has a maximized group.
      Parameters:
      id - any open dockable in the group
      bounds - requested bounds relative to the pane's content area
      Throws:
      IllegalArgumentException - if the ID or geometry is invalid
    • getLayout

      public DockingLayout getLayout()
      Captures the complete context-wide docking layout.
      Returns:
      immutable layout snapshot
    • restoreLayout

      public DockingRestoreResult restoreLayout(DockingLayout layout)
      Restores a complete context-wide docking layout. Restore replaces the current layout regardless of close permissions and disposes dockable instances that are not reused in the restored layout.
      Parameters:
      layout - the layout to restore
      Returns:
      restore result containing unresolved dockable IDs
    • requestCloseDockable

      public boolean requestCloseDockable(Dockable dockable)
      Closes the dockable if its closeable property, close policy, and close request callback permit it. A veto leaves the panes and this context unchanged. A successfully removed dockable is disposed.
      Parameters:
      dockable - the dockable to close
      Returns:
      true only if the dockable was open and has been removed
      Throws:
      IllegalStateException - if called off the FX thread
    • requestCloseAll

      public final boolean requestCloseAll()
      Closes every open dockable of this context, docked and floating, if all of them permit it. Each dockable's closeable property, the close policy, and its close request callback are consulted first; a single veto leaves the context unchanged. Approved dockables are removed and disposed, and emptied floating windows are closed.

      Call this from the close request handler of the host stage and consume the event when it returns false; see the class documentation.

      Returns:
      true if all dockables have been closed, false if one of them vetoed
      Throws:
      IllegalStateException - if called off the FX thread
    • getDockables

      public final javafx.collections.ObservableList<Dockable> getDockables()
      Returns an unmodifiable view of all open dockables of this context.
      Returns:
      the open dockables
    • setCanCloseDockable

      public final void setCanCloseDockable(Predicate<Dockable> policy)
      Sets the policy deciding whether a dockable may close; true means it may close.
      Parameters:
      policy - the close policy
    • canCloseDockable

      public final boolean canCloseDockable(Dockable dockable)
      Evaluates the dockable's close permission and the context's close policy without invoking the dockable's close request callback.
      Parameters:
      dockable - the dockable
      Returns:
      true if the dockable may close
    • canMoveTabGroup

      public final boolean canMoveTabGroup(DockingPane targetPane, String id, String targetId, DockingPosition position)
      Tests whether a dockable's entire tab group can move to the given target. A null target ID addresses a pane-wide edge, or an empty pane for a center drop. Drops back onto the source group are rejected, as are moves involving a pane with a maximized group.
      Parameters:
      targetPane - the destination pane in this context
      id - a dockable in the source group
      targetId - a dockable in the target group, or null for the whole pane
      position - the docking position
      Returns:
      whether the move is valid
    • moveTabGroup

      public final boolean moveTabGroup(DockingPane targetPane, String id, String targetId, DockingPosition position)
      Moves a dockable's entire tab group, preserving its order and selected tab. Center drops append the tabs to the target group; edge drops create one new group. The selected tab's preferred docking size is used for the new group.
      Parameters:
      targetPane - the destination pane in this context
      id - a dockable in the source group
      targetId - a dockable in the target group, or null for a pane-wide edge or empty pane
      position - the docking position
      Returns:
      true if the move completed, or false without changes for an invalid target