인수를 파트에 전달

상위는 ContainerContext를 사용하여 인수를 하위에 전달합니다. 컨텍스트는 파트 인수를 생성자에 전달하거나 팩토리를 지정하여 해당 인수를 구성할 수 있습니다. 예를 들어 특정 ContainerContext는 다음과 같은 규칙을 지정할 수도 있습니다.
컨텍스트가 특정 종속성을 제공하지 않으면 하위는 org.eclipse.core.component.types 확장점의 기본 구현을 사용합니다. 컨텍스트는 파트가 생성자에 가져오는 모든 인수를 재정의할 수 있으므로 상위는 파트가 대개 해당 사이트에서 얻는 모든 인터페이스를 재정의할 수 있습니다. 예를 들어 상위는 컨텍스트에 IActionBars를 제공하여 하위가 IActionBars의 다른 구현을 사용하도록 강제 실행할 수 있습니다.

상위에는 컨텍스트를 구성하는 다음과 같은 여러 가지 옵션이 있습니다.

다음 DefaultContextView, RedirectContextViewOverrideInstanceView 예제에서는 각 가능성을 보여 줍니다.

기본 컨텍스트

다음 예제에서는 기본 컨텍스트에 두 개의 중첩된 하위를 작성하는 보기의 소스를 표시합니다. 하위가 기본 컨텍스트에서 작성된다는 사실은 상위가 하위의 이름, 도구 모음, 선택 등에 관심을 갖지 않고 이러한 요소를 처리할 준비를 하지 않음을 의미합니다. 상위가 예를 들어 하위 중 하나의 현재 선택에 대한 작업을 수행하려고 하면 상위는 해당 하위에 SelectionHandler를 전달해야 합니다. 최종 결과는 예제 아래에 표시됩니다.

/**
 * View that demonstrates how to create two nested children
 * with the default context.
 */
public class DefaultContextView {
    public DefaultContextView(Composite parent, IPartFactory factory) throws CoreException {
        // Create a resource navigator
        ContainerContext viewContext1 = new ContainerContext();  
        ISite view1 = factory.createView(
                IPageLayout.ID_RES_NAV, parent, viewContext1, null);
   
        // Create property view
        ContainerContext viewContext2 = new ContainerContext();
        ISite view2 = factory.createView(IPageLayout.ID_PROP_SHEET, parent, viewContext2, null);
   
        parent.setLayout(new FillLayout());       
    }
}

DefaultContextView의 스크린 샷

종속성을 상위에서 하위로 경로 재지정

이 예제에서는 상위에서 하위로 사이트 인터페이스를 경로 재지정하는 방법을 보여 줍니다. 이 컴포지트 보기에는 자원 네비게이터와 특성 보기가 포함됩니다. 컴포지트 보기는 선택 핸들러를 자원 네비게이터로 경로 재지정하고 조치 표시줄을 특성 보기로 경로 재지정합니다. 이를 통해 자원 선택을 제공하고 특성 보기의 메뉴와 도구 표시줄이 포함된 아래와 같은 보기가 생성됩니다.

public class RedirectContextView {
    /**
     * Component constructor. Do not invoke directly.
     */
    public RedirectContextView(Composite parent, IPartFactory factory, ISelectionHandler selection, IActionBars actionBars) throws CoreException {
        // Create a resource navigator. Redirect the navigator's selection directly to our parent.
        ContainerContext viewContext1 = new ContainerContext()
            .addInstance(ISelectionHandler.class, selection);
        ISite view1 = factory.createView(
                IPageLayout.ID_RES_NAV,
                parent, viewContext1, null);
   
        // Create property view. Allow the property view to use our action bars directly.
        ContainerContext viewContext2 = new ContainerContext()
            .addInstance(IActionBars.class, actionBars);
        ISite view2 = factory.createView(IPageLayout.ID_PROP_SHEET, parent, viewContext2, null);
   
        parent.setLayout(new FillLayout());       
    }
}


RedirectContextView의 스크린 샷

종속성을 직접 제공

이 예제에서는 상위의 종속성 중 하나를 하위에 직접 제공하는 방법을 보여 줍니다. 이 예제에서 문제점 보기 및 특성 보기가 포함된 컴포지트 보기를 작성합니다. 문제점 보기에 ISelectionHandler를 제공하여 컨텐츠 설명에 선택된 문제점 수를 표시합니다. 최종 결과는 아래에 표시됩니다.

public class OverrideInstanceView {
   
    /**
     * Component constructor. Do not invoke directly.
     */
    public OverrideInstanceView(Composite parent, IPartFactory factory, final INameable name) throws CoreException {
        ContainerContext viewContext1 = new ContainerContext();
       
        // Add an ISelectionHandler to the view's context. Whenever the view changes its selection,
        // display the number of selected items in the content description
        viewContext1.addInstance(ISelectionHandler.class, new ISelectionHandler() {
            /* (non-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)}));
                }
            }
        });

        // Create a problem view
        ISite view1 = factory.createView(
                IPageLayout.ID_PROBLEM_VIEW, parent, viewContext1, null);
   
        // Create property view
        ContainerContext viewContext2 = new ContainerContext();
        ISite view2 = factory.createView(IPageLayout.ID_PROP_SHEET, parent, viewContext2, null);
   
        parent.setLayout(new FillLayout());
    }
}



OverrideInstanceView의 스크린 샷