| Demonstrate how to open a part programmatically using the Site class.
This pattern can be used to instantiate views or editors without a workbench,
or to create parts that are neither views nor editors but can be used as
building blocks inside dialogs or other parts.
Clients should never call the constructor of a component class directly,
even if the component class is API -- otherwise, changing the class dependencies
would be a breaking change. Components need to be instantiated through a container.
For UI-related classes, the Site class is a quick way to instantiate the component.
It creates a container, a composite, instantiates the component, and provides concrete
access to several common adapters.
The Site class uses a dispose listener to clean up the container. This means that disposing
the top-level widget is enough to clean up after the part. This example creates the part
in a Shell. Since the shell is disposed automatically when it closes, we don't need
any explicit cleanup code.
Note: not all views and editors can be instantiated using this pattern. If
a view or editor permits creation in this manner, it will contain a class
comment saying so and identifying which scope it uses. Most such parts
will be in the global scope, so will have access to a more restricted
set of dependencies (some components like IPartFactory require an IWorkbenchPage,
so cannot exist in the global scope).
|