package com.gwesm.ui.temp;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ExpandEvent;
import org.eclipse.swt.events.ExpandListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class CascadeExpandBar {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
// Création de l'ExpandBar principale
final ExpandBar mainExpandBar = new ExpandBar(shell, SWT.NONE);
// Crée un composite qui sera stocké dans l'expandBar principale
final Composite mainComposite = new Composite(mainExpandBar, SWT.NONE);
GridLayout mainCompositeLayout = new GridLayout(2, true);
mainComposite.setLayout(mainCompositeLayout);
// Label label = new Label(mainComposite, SWT.NONE);
// label.setImage(display.getSystemImage(SWT.ICON_WARNING));
// label = new Label(mainComposite, SWT.NONE);
// label.setText("SWT.ICON_WARNING");
// Création des ExpandBar secondaires stockées dans le composite de
// l'ExpandBar principale
/**
* ExpandBar secondaire dans le composite principal
*/
final ExpandBar secondaryExpandBar = new ExpandBar(mainComposite,
SWT.NONE);
secondaryExpandBar.setLayoutData(new GridData(GridData.FILL,
GridData.FILL, true, true, 2, 1));
final Composite secondaryComposite = new Composite(secondaryExpandBar,
SWT.NONE);
secondaryComposite.setLayout(new GridLayout(2, true));
final Composite secondaryComposite2 = new Composite(secondaryExpandBar,
SWT.NONE);
secondaryComposite2.setLayout(new GridLayout(2, true));
final Composite secondaryComposite3 = new Composite(secondaryExpandBar,
SWT.NONE);
secondaryComposite3.setLayout(new GridLayout(2, true));
Label labelSec = new Label(secondaryComposite, SWT.NONE);
labelSec.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
labelSec = new Label(secondaryComposite, SWT.NONE);
labelSec.setText("SWT.ICON_INFORMATION");
Label labelSec2 = new Label(secondaryComposite2, SWT.NONE);
labelSec2.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
labelSec2 = new Label(secondaryComposite2, SWT.NONE);
labelSec2.setText("SWT.ICON_INFORMATION");
Label labelSec3 = new Label(secondaryComposite3, SWT.NONE);
labelSec3.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
labelSec3 = new Label(secondaryComposite3, SWT.NONE);
labelSec3.setText("SWT.ICON_INFORMATION");
final ExpandItem mainItem = new ExpandItem(mainExpandBar, SWT.NONE, 0);
mainItem.setText("Main Item");
mainItem.setControl(mainComposite);
final ExpandItem secondaryItem = new ExpandItem(secondaryExpandBar,
SWT.NONE, 0);
secondaryItem.setText("Secondary item 1");
secondaryItem.setHeight(secondaryComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
secondaryItem.setControl(secondaryComposite);
final ExpandItem secondaryItem2 = new ExpandItem(secondaryExpandBar,
SWT.NONE, 0);
secondaryItem2.setText("Secondary item 2");
secondaryItem2.setHeight(secondaryComposite2.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
secondaryItem2.setControl(secondaryComposite2);
final ExpandItem secondaryItem3 = new ExpandItem(secondaryExpandBar,
SWT.NONE, 0);
secondaryItem3.setText("Secondary item 3");
secondaryItem3.setHeight(secondaryComposite3.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
secondaryItem3.setControl(secondaryComposite3);
/**
* Fin ExpandBar secondaire
*/
// label = new Label(mainComposite, SWT.NONE);
// label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
// label = new Label(mainComposite, SWT.NONE);
// label.setText("SWT.ICON_QUESTION");
mainItem
.setHeight(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
secondaryExpandBar.addExpandListener(new ExpandListener() {
public void itemCollapsed(ExpandEvent event) {
System.out.println(event.item);
mainItem.setHeight(mainItem.getHeight()
- secondaryComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
System.out.println("itemCollapsed " + mainItem.getHeight());
}
public void itemExpanded(ExpandEvent event) {
System.out.println(event.item);
mainItem.setHeight(mainComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y
+ secondaryComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
System.out.println("itemExpanded " + mainItem.getHeight());
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}