ScottJ
ScottJ

Reputation: 155

ExpandBar in Eclipse View Part

I am trying to add an expand bar to an Eclipse viewpart. When I click the expand button I would like the viewpart to move items below the expand bar down and show the expanded items. What currently happens is the expand bar items just disappear below the items below the expand bar. Any thoughts?

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

});

Upvotes: 2

Views: 2979

Answers (1)

twindham
twindham

Reputation: 960

I think the ExpandBar works best when used like it is in this example...

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

... with several expand bars stacked on top of each other, and nothing else mixed in.

I think the functionality your looking for can be accomplished with an ExpandableComposite object. It depends on what else is going on in your ViewPart.

Here's a quick example of an 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
}
}

Upvotes: 2

Related Questions