If you want to add, move or remove a dockable, you can use the methods from Dock, LeafDock, and CompositeDock:
The docking executor fires also a DockableEvent on the dockable. An event is fired before and after the docking change. Once there are listeners in your application that listen to dockable events, you should always use the methods from the docking executor.
With the docking executor you can combine a removal and an addition. If you use the method
changeDocking()
for a dockable that is already docked in a dock, the dockable is removed from
its old dock, before adding it to the new dock. An event is fired before the removal of the dockable
and after the addition of the dockable.
The easiest way to close and restore a dockable is using a DockableStateAction. These actions are doing everything for you:
When a dockable is closed with a dockable state action, a DockingPath is created for the dockable. This docking path is added to the DockingPathModel of the docking manager. When the dockable is restored, the docking path is used to restore the dockable as good as possible where the dockable was docked before.... closeAction = new DockableStateAction(dockable, DockableState.CLOSED); restoreAction = new DockableStateAction(dockable, DockableState.NORMAL); ... public void itemStateChanged(ItemEvent itemEvent) { dockable.removeDockingListener(this); if (itemEvent.getStateChange() == ItemEvent.DESELECTED) { // Close the dockable. closeAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Close")); } else { // Restore the dockable. restoreAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Restore")); } dockable.addDockingListener(this); }
If you want to restore a dockable that was not already docked, you better add first a docking path for the dockable to the docking path model by your self (see How to Use Docking Paths).
CodecExample | Shows the usage, the encoding, and the decoding of dock models. |
WorkspaceExample | Shows the usage, the encoding, and the decoding of dock models. |