El padre tiene varias opciones para construir el contexto:
/**
* Vista que demuestra cómo crear dos hijos anidados
* con el contexto por omisión.
*/
public class DefaultContextView {
public DefaultContextView(Composite parent, IPartFactory
factory) throws CoreException {
// Crear un navegador de recursos
ContainerContext viewContext1
= new ContainerContext();
ISite view1 = factory.createView(
IPageLayout.ID_RES_NAV, parent, viewContext1, null);
// Crear vista de
propiedades
ContainerContext viewContext2
= new ContainerContext();
ISite view2 = factory.createView(IPageLayout.ID_PROP_SHEET,
parent, viewContext2, null);
parent.setLayout(new FillLayout());
}
}
public class RedirectContextView {
/**
* Constructor de componentes. No debe invocarse directamente.
*/
public RedirectContextView(Composite parent, IPartFactory
factory, ISelectionHandler selection, IActionBars actionBars) throws CoreException
{
// Crear un navegador de recursos.
Redirigir la selección del navegador directamente al padre.
ContainerContext viewContext1
= new ContainerContext()
.addInstance(ISelectionHandler.class,
selection);
ISite view1 = factory.createView(
IPageLayout.ID_RES_NAV,
parent, viewContext1, null);
// Crear vista de propiedades. Permitir que
la vista de propiedades utilice directamente las barras de acciones.
ContainerContext viewContext2
= new ContainerContext()
.addInstance(IActionBars.class,
actionBars);
ISite view2 = factory.createView(IPageLayout.ID_PROP_SHEET,
parent, viewContext2, null);
parent.setLayout(new FillLayout());
}
}
public class OverrideInstanceView {
/**
* Constructor de componentes. No debe invocarse directamente.
*/
public OverrideInstanceView(Composite parent, IPartFactory
factory, final INameable name) throws CoreException {
ContainerContext viewContext1 = new
ContainerContext();
// Añadir un ISelectionHandler al contexto
de vista. Siempre que la vista cambie de selección,
// visualizar el número de elementos
seleccionados en la descripción de contenido
viewContext1.addInstance(ISelectionHandler.class,
new ISelectionHandler() {
/* (no Javadoc)
* @see
org.eclipse.ui.part.services.ISelectionHandler#setSelection(org.eclipse.jface.viewers.ISelection)
*/
public void
setSelection(ISelection newSelection) {
if (newSelection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection)newSelection;
int selectionSize = sel.size();
name.setContentDescription(MessageFormat.format("{0} problems selected",
new String[] {Integer.toString(selectionSize)}));
}
}
});
// Crear una vista de problemas
ISite view1 = factory.createView(
IPageLayout.ID_PROBLEM_VIEW, parent, viewContext1, null);
// Crear vista de propiedades
ContainerContext viewContext2 = new
ContainerContext();
ISite view2 = factory.createView(IPageLayout.ID_PROP_SHEET,
parent, viewContext2, null);
parent.setLayout(new FillLayout());
}
}