2

我正在尝试将扩展栏添加到 Eclipse 视图部分。当我单击展开按钮时,我希望视图部分将展开栏下方的项目向下移动并显示展开的项目。当前发生的是扩展栏项目只是在扩展栏下方的项目下方消失。有什么想法吗?

final ExpandBar expandBar = new ExpandBar(parent, SWT.NONE);
expandBar.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
expandBar.setSpacing(0);
fd_toolBar.top = new FormAttachment(expandBar, 6);
FormData fd_expandBar = new FormData();
fd_expandBar.top = new FormAttachment(0, 62);
fd_expandBar.left = new FormAttachment(0, 3);
expandBar.setLayoutData(fd_expandBar);
formToolkit.paintBordersFor(expandBar);

final ExpandItem xpndtmWarningDetails = new ExpandItem(expandBar, SWT.NONE);
xpndtmWarningDetails.setExpanded(true);
xpndtmWarningDetails.setText("Warning Details");

final Composite composite_1 = new Composite(expandBar, SWT.NONE);
composite_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
xpndtmWarningDetails.setControl(composite_1);
formToolkit.paintBordersFor(composite_1);
xpndtmWarningDetails.setHeight(xpndtmWarningDetails.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);

Label lblTest = new Label(composite_1, SWT.NONE);
lblTest.setBounds(10, 10, 55, 15);
lblTest.setText("Test");

expandBar.addExpandListener(new ExpandListener(){

    @Override
    public void itemCollapsed(ExpandEvent e) {
        expandBar.setSize(expandBar.getSize().x, xpndtmWarningDetails.getHeaderHeight());
        parent.layout(true);
    }

    @Override
    public void itemExpanded(ExpandEvent e) {
        expandBar.setSize(expandBar.getSize().x, 300);
        expandBar.layout(true);
        parent.layout(true);
    }

});
4

1 回答 1

2

我认为 ExpandBar 像在这个例子中一样使用时效果最好......

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet343.java

...几个扩展条堆叠在一起,没有其他任何东西混合在一起。

我认为您正在寻找的功能可以通过 ExpandableComposite 对象来完成。这取决于您的 ViewPart 中还发生了什么。

这是 ExpandableComposite 的一个简单示例。

package com.amx.designsuite.rcp;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

public class ExpandableCompositeExample extends Composite {

/**
 * Create the composite.
 * @param parent
 * @param style
 */
public ExpandableCompositeExample(final Composite parent, int style) {
    super(parent, style);
    FormToolkit toolkit;

    toolkit = new FormToolkit(parent.getDisplay());
    final ScrolledForm form = toolkit.createScrolledForm(parent);
    form.setText("Title for Form holding Expandable Composite (optional)");
    TableWrapLayout layout = new TableWrapLayout();
    form.getBody().setLayout(layout);

    ExpandableComposite expandableCompsite = toolkit.createExpandableComposite(form.getBody(), ExpandableComposite.TREE_NODE | ExpandableComposite.SHORT_TITLE_BAR);
    toolkit.paintBordersFor(expandableCompsite);
    expandableCompsite.setText("Expandable Composite Title (Optional)");
    expandableCompsite.setExpanded(true);

    Text txtMyNewText = toolkit.createText(expandableCompsite, "Text to show when composite is expanded", SWT.NONE);
    expandableCompsite.setClient(txtMyNewText);
}

@Override
protected void checkSubclass() {
    // Disable the check that prevents subclassing of SWT components
}
}
于 2012-08-31T15:46:19.520 回答