| A ProxyControl is an invisible control whose size and position are linked
with some target control. That is, when the dummy control is asked for its
preferred size it returns the preferred size of the target. Changing the
bounds of the dummy control also changes the bounds of the target. This allows
any Composite to lay out a control that isn't one of its children.
For example, imagine you have a ViewForm and a ToolBar that share the same parent
and you want the ToolBar to be located in the upper-right corner of the ViewForm.
If the ToolBar were a child of the ViewForm, this could be done easily by calling
viewForm.setTopRight(toolBar). However, this is impossible since ViewForm.setTopRight
will only accept a child control. Instead, we create a ProxyControl as a child
of the viewForm, and set the toolbar as its target. The ViewForm will treat
the ProxyControl just like any other child, but it will actually be arranging the
ToolBar.
For example:
// Create a ViewForm and a ToolBar that are siblings
ViewForm viewForm = new ViewForm(parent, SWT.NONE);
ToolBar toolBar = new ToolBar(parent, SWT.NONE);
// Allow the ViewForm to control the position of the ToolBar by creating
// a ProxyControl in the ViewForm that targets the ToolBar.
ProxyControl toolBarProxy = new ProxyControl(viewForm);
toolBarProxy.setTarget(toolBar);
viewForm.setTopRight(toolBarProxy.getControl());
This is intended to simplify management of view toolbars in the presentation API.
Presentation objects have no control over where the view toolbars are created in
the widget hierarchy, but they may wish to control the position of the view toolbars
using traditional SWT layouts and composites.
|