I think what could make it simpler for me, without having to learn the underlying layout that CGrid does when I deploy it, is if I can somehow retrieve a CGrid initialized with the current layout. Sort of CControl.getCGrid(), which is the exact opposite of deploy. If I can do that, I will simply re-add my dockable to the grid. Is there such an API?
There is no such method. You could ask for the tree (CGridArea#getStation().createTree()) and somehow convert the tree back into a CGrid. But that would mean to learn the underlying mechanisms as well.
Ok, I used the other way to position the dockables, using CLocation.base().normal().rectangle(). This seems to work fine, most of the time. Occasionally, if there are lots of dockables stacked at the same area, it will split them into two different stacks.
I have another problem now - if I “externalize” a window (make it floating), then it’s nearly impossible to move the window and keep it externalized - it tends to dock back into the main frame each time I move it (I have the main frame maximized). I’d prefer it to move without docking back into the frame, and have a button to dock it back.
There are two solutions:
- press the key “shift” while you drag the mouse, this will make sure the dockable can only be dropped on the screen again (Guide to Core, chapter 8.4.1)
- Grab the dockable at its top border, even above the title. There is a small area to move it around. The cursor will change its format and become a cross of four arrows once you hit this spot.
Does this mean that I can’t configure this from my application? i.e. specify to the controller somehow that docking back into the frame must be done through an explicit action and not by dragging?
You can: install a DockAcceptance that checks that if the child is on a ScreenDockStation (directly or indirectly) the new parent must be a ScreenDockStation or a child of one as well (Guide for Core, Chapter 8.4.2).
You also need to override the method “setExtendedMode” in AbstractCDockable to temporarely disable the DockAcceptance.
Finally the standard actions have to be replaced. Call the method “putAction” of AbstractCDockable to do that, the keys for the method are “CDockable.ACTION_KEY_”. Use the actions from bibliothek.gui.dock.common.action.predefined as replacement. Their method “action( CDockable )” needs to be overritten with a method that temporarely disables the DockAcceptance. (Guire for Common, Chapter 6.7).