eclipse - Eclipse View 部分中的 ExpandBar

标签 eclipse eclipse-plugin

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

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);
    }

});

最佳答案

我认为 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
}
}

关于eclipse - Eclipse View 部分中的 ExpandBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11993088/

相关文章:

java - 使用eclipse重建maven索引没有进展

jakarta-ee - Tomcat 服务器未在 X 秒内启动

eclipse - 是否可以将整个 eclipse 插件项目添加到 Eclipse RCP 应用程序中

eclipse - 在新项目的 Eclipse 中 Xdebug 中跳过断点

java - 将 Java SE 升级到 Java EE 以及 Eclipse

java - 如何在 Eclipse 项目(Java)中刷新外部 Jars?

eclipse-plugin - 如何让 PDE 目标定义编辑器显示所有插件?

java - 提高 Eclipse 性能的提示

java - 我正在使用 eclipse 扩展 newWizard,如何在 java 中设置向导对话框大小?

eclipse - Eclipse-如何固定编辑器选项卡?