如何仅为内部合成

时间:2016-07-25 09:41:21

标签: swt scrolledcomposite

enter image description here

我正在尝试为其中一个复合实现滚动复合(顶部复合,如图所示)。我的目的是仅为上部复合添加滚动条,因为当窗口调整大小时,保存按钮有时会变得不可见。

我尝试过使用上层复合的滚动复合实现。但是当我尝试调整它的大小时,即使我已经设置了scrolledComposite的最小大小,我也没有得到它的滚动条。

另外,当我指定scrolledComposite.setAlwaysShowScrollBars(true)时,我只能看到处于禁用模式的滚动条的占位符。

以下是我的代码段。

public void init() {
        setFocus();
        preInit();
        createCaseGroup(this);

        //Here "this" is the parent composite
        Composite childComp = new Composite(this, SWT.None);
        childComp.setLayout(new GridLayout(2, true));
        childComp.setLayoutData(new GridData(GridData.FILL_BOTH));

        final ScrolledComposite scrolledComposite = new ScrolledComposite(childComp,
                SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

        final Composite Comp = new Composite(scrolledComposite, SWT.NONE);
        Comp.setLayout(new GridLayout(2, true));
        Comp.setLayoutData(new GridData(GridData.FILL_BOTH));

        scrolledComposite.setContent(Comp);
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);

        // scrolledComposite.setMinSize(Comp.computeSize(400, 400) );
        scrolledComposite.setMinSize(400, 400);
        scrolledComposite.setAlwaysShowScrollBars(true);

        objectComposite = new GUIObjectComposite(Comp, SWT.NONE, true);
        objectComposite.setLayout(new GridLayout(3, false));
        objectComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        objectComposite.init();
        objectComposite.isNullSelectionAllowed(false);
        GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        gridData.heightHint = 130;
        gridData.horizontalSpan = 2;
        objectComposite.setLayoutData(gridData);
        GridLayout layout = new GridLayout(1, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.verticalSpacing = 0;
        objectComposite.setLayout(layout);

        // Group for Define interaction(s)
        Group defineInteractionGroup = new Group(childComp, SWT.NONE);
        GridData defineInteractionGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        defineInteractionGridData.horizontalSpan = 2;
        defineInteractionGroup.setLayoutData(defineInteractionGridData);
        GridLayout defineInteractionLayout = new GridLayout(1, true);
        defineInteractionLayout.marginHeight = 0;
        defineInteractionLayout.marginWidth = 0;
        defineInteractionLayout.verticalSpacing = 0;
        defineInteractionGroup.setLayout(defineInteractionLayout);
        defineInteractionGroup
                .setText(ResourceAssistant.getString(InteractionExpandedComposite.class, "defineInteraction")); //$NON-NLS-1$

        // Composite for Define interaction(s)
        Composite interactionComposite = new Composite(defineInteractionGroup, SWT.NONE);
        interactionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        GridLayout interactionCompositeLayout = new GridLayout(11, true);
        interactionCompositeLayout.marginHeight = 10;
        interactionCompositeLayout.verticalSpacing = 0;
        interactionComposite.setLayout(interactionCompositeLayout);

        Composite actionsComposite = new Composite(interactionComposite, SWT.NONE);
        GridData actionsCompositeGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        actionsCompositeGridData.horizontalSpan = 2;
        actionsComposite.setLayoutData(actionsCompositeGridData);
        ActionsFormProvider actionsFormProvider = new ActionsFormProvider();
        List<IFormItem> actionFormItems = actionsFormProvider.generateFormItems();
        for (IFormItem actionItem : actionFormItems) {
            actionItem.create(actionsComposite);
        }

        IWorkbenchWindow iWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPartSite activePartSite = iWorkbenchWindow.getActivePage().getActivePart().getSite();
        activePartSite.setSelectionProvider(objectComposite.getViewer());

        ISelectionService selectionService = iWorkbenchWindow.getSelectionService();
        if (selectionService instanceof AbstractSelectionService) {
            AbstractSelectionService abstractSelectionService = (AbstractSelectionService) selectionService;
            abstractSelectionService.setActivePart(null);
            abstractSelectionService.setActivePart(getExpandedView());
        }
    }

0 个答案:

没有答案
相关问题