嵌套

对于外部世界,每个部件都是一个黑匣。部件可以使用 IPartFactory 来创建嵌套的子代,虽然它觉得这是适宜的,但它不会将这些子代直接暴露给外部世界。以下示例演示一个具有两个嵌套子代的视图。

/**
 * Example view containing a nested error log on the left and a nested property
 * view on the right.
 *
 * @since 3.1
 */
public class TestCompositeView {
   
    public TestCompositeView(Composite parent, IPartFactory factory) throws CoreException {       
        // Create PDE error log view
        ContainerContext logViewContext = new ContainerContext();   
        ISite logView = factory.createView(
                "org.eclipse.pde.runtime.LogView",
                parent, logViewContext, null);

        // Create Property view
        ContainerContext emptyContext = new ContainerContext();
        ISite propertiesView = factory.createView(IPageLayout.ID_PROP_SHEET, parent, emptyContext, null);

        // Construct layout
        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        parent.setLayout(layout);

        // Arrange error log view
        GridData data1 = new GridData(GridData.FILL_BOTH);
        logView.getControl().setLayoutData(data1);
       
        // Arrange properties view
        GridData data2 = new GridData(GridData.FILL_BOTH);
        propertiesView.getControl().setLayoutData(data2);

    }
}