Hi,
i’m using the core part of “docking frames” to build my application.
I’m trying to register a listener to each of my dockables that should get triggered when the close action, which is added using an action guard, is invoked.
So far i found out that a dockable-hierarchy-listener gets triggered when the close-action is invoked, but it might also get triggered when a dockable is temporarily removed from a dock-station. so this doesn’t seem to be the best approach.
Another possibility would be to register an action-listener directly to the close-action, but there is only one such action per action-guard, so every listener would be called when any of my dockable is closed. furthermore it’s difficult to directly access the action as it is and should remain to be hidden inside the action guard.
A more direct approach without DockFrontend: visibility equals registration. A Dockable which is known to a DockController must be visible, and a Dockable wich is not known cannot be visible. So adding a “DockRegisterListener” to the “DockRegister” (which is available through “DockController.getRegister”) would also do the trick.
isn’t there a solution that doesn’t require state-changes / registration in any controller instances? Ideally one should only have to register listeners to the dockable itself.
You wrote that a visible dockable is always known to a dock-controller. so if i register a hierarchy-listener to the dockable, i would be able to recognize the moment when a dockable is unregistered and thus not visible anymore by examining the hierarchy-event.
The problem remains that only the consequence (the dockable’s dock-controller gets disconnected) can be observed and not the original cause, i.e. the execution of a close action. So if the framework’s behaviour changes in the future, my code might not work anymore. For all i know it might not even work now because the framework might disconnect the dock-controller without my clicking some close button.
The logical solution would be to be able to register a listener to a dockable that gets called when a specific action is executed on it.
Since this close-action is more an addon than part of Core, there will (almost certainly) never be a listener in the form that you want (in Common the “CDockableStateListener” would do almost exactly what is missing here…).
I can hovewer guarantee that the formula “known to controller = visible” will never change. The framework was designed that way since the very first version. If you are only interested in visibility then the hierarchy-listener is enough.
You are also right, that a Dockable can be removed without clicking on the close-action. That happens i.e. when loading a layout through DockFronted.load or DockFrontend.read.
There is a way to know when the button is clicked, but it requires you to write a subclass of DockFronted, that could look like this:
@Override
protected Hider createHider() {
// Hider = the action that closes the Dockable
return new Hider(){
@Override
public void action( Dockable dockable ) {
System.out.println( "now hiding: " + dockable.getTitleText() );
super.action( dockable );
}
};
}
};```
Or write your own action and call "DockFrontend.hide" when clicked.
I'll write an additional listener for DockFrontend, this listener will be notified before and after the action is executed, with the opportunity to cancel the operation. It will also be notified if a Dockable is closed not through the action, and it will distinguish the two events. This will be in version 1.0.7p5 (which I hope to release before this weekend).
Not **exactly** what you want, but the design does not allow to modify Dockable or one of its listeners for this task.