Package com.gwesm.ui.temp

Source Code of com.gwesm.ui.temp.CascadeExpandBar2

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.Shell;

public class CascadeExpandBar2 {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final ExpandBar professionExpandBar = new ExpandBar(shell, SWT.V_SCROLL);

    // Début Profession 1

    final Composite p1ExpandBarComposite = new Composite(
        professionExpandBar, SWT.NONE);
    GridLayout p1ExpandBarCompositeLayout = new GridLayout(2, true);
    p1ExpandBarComposite.setLayout(p1ExpandBarCompositeLayout);

    final ExpandBar p1attributeExpandBar = new ExpandBar(
        p1ExpandBarComposite, SWT.NONE);
    p1attributeExpandBar.setLayoutData(new GridData(GridData.FILL,
        GridData.FILL, true, true, 2, 1));

    final Composite p1attributeExpandBarComposite = new Composite(
        p1attributeExpandBar, SWT.NONE);
    p1attributeExpandBarComposite.setLayout(new GridLayout(2, true));

    final Composite attributeExpandBarComposite2 = new Composite(
        p1attributeExpandBar, SWT.NONE);
    attributeExpandBarComposite2.setLayout(new GridLayout(2, true));

    final ExpandItem p1ExpandBarItem = new ExpandItem(professionExpandBar,
        SWT.NONE, 0);
    p1ExpandBarItem.setText("Profession 1");
    p1ExpandBarItem.setControl(p1ExpandBarComposite);

    final ExpandItem p1a1ExpandBarItem = new ExpandItem(
        p1attributeExpandBar, SWT.NONE, 0);
    p1a1ExpandBarItem.setText("Profession 1 Attribute 1");
    p1a1ExpandBarItem.setHeight(p1attributeExpandBarComposite.computeSize(
        SWT.DEFAULT, SWT.DEFAULT).y);
    p1a1ExpandBarItem.setControl(p1attributeExpandBarComposite);

    final ExpandItem attributeExpandBarItem2 = new ExpandItem(
        p1attributeExpandBar, SWT.NONE, 0);
    attributeExpandBarItem2.setText("Profession 1 Attribute 2");
    attributeExpandBarItem2.setHeight(attributeExpandBarComposite2
        .computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    attributeExpandBarItem2.setControl(attributeExpandBarComposite2);

    p1ExpandBarItem.setHeight(p1ExpandBarComposite.computeSize(SWT.DEFAULT,
        SWT.DEFAULT).y);

    p1attributeExpandBar.addExpandListener(new ExpandListener() {
      public void itemCollapsed(ExpandEvent event) {
        System.out.println(event.item);
        p1ExpandBarItem.setHeight(p1ExpandBarItem.getHeight()
            - p1attributeExpandBarComposite.computeSize(
                SWT.DEFAULT, SWT.DEFAULT).y);
        System.out.println("itemCollapsed "
            + p1ExpandBarItem.getHeight());

      }

      public void itemExpanded(ExpandEvent event) {
        System.out.println(event.item);
        p1ExpandBarItem.setHeight(p1ExpandBarComposite.computeSize(
            SWT.DEFAULT, SWT.DEFAULT).y
            + p1attributeExpandBarComposite.computeSize(
                SWT.DEFAULT, SWT.DEFAULT).y);
        System.out.println("itemExpanded "
            + p1ExpandBarItem.getHeight());
      }
    });

    // Fin profession 1

    // Début Profession 2

    final Composite p2ExpandBarComposite = new Composite(
        professionExpandBar, SWT.NONE);
    GridLayout p2ExpandBarCompositeLayout1 = new GridLayout(2, true);
    p2ExpandBarComposite.setLayout(p2ExpandBarCompositeLayout1);

    final ExpandBar attributeExpandBar1 = new ExpandBar(
        p2ExpandBarComposite, SWT.NONE);
    attributeExpandBar1.setLayoutData(new GridData(GridData.FILL,
        GridData.FILL, true, true, 2, 1));

    final Composite p2attributeExpandBarComposite = new Composite(
        attributeExpandBar1, SWT.NONE);
    p2attributeExpandBarComposite.setLayout(new GridLayout(2, true));

    final Composite attributeExpandBarComposite21 = new Composite(
        attributeExpandBar1, SWT.NONE);
    attributeExpandBarComposite21.setLayout(new GridLayout(2, true));

    final ExpandItem professionExpandBarItem1 = new ExpandItem(
        professionExpandBar, SWT.NONE, 0);
    professionExpandBarItem1.setText("Profession 2");
    professionExpandBarItem1.setControl(p2ExpandBarComposite);

    final ExpandItem p1a1ExpandBarItem1 = new ExpandItem(
        attributeExpandBar1, SWT.NONE, 0);
    p1a1ExpandBarItem1.setText("Profession 2 Attribute 1");
    p1a1ExpandBarItem1.setHeight(p2attributeExpandBarComposite.computeSize(
        SWT.DEFAULT, SWT.DEFAULT).y);
    p1a1ExpandBarItem1.setControl(p2attributeExpandBarComposite);

    final ExpandItem attributeExpandBarItem21 = new ExpandItem(
        attributeExpandBar1, SWT.NONE, 0);
    attributeExpandBarItem21.setText("Profession 2 Attribute 2");
    attributeExpandBarItem21.setHeight(attributeExpandBarComposite21
        .computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    attributeExpandBarItem21.setControl(attributeExpandBarComposite21);

    professionExpandBarItem1.setHeight(p2ExpandBarComposite.computeSize(
        SWT.DEFAULT, SWT.DEFAULT).y);

    attributeExpandBar1.addExpandListener(new ExpandListener() {
      public void itemCollapsed(ExpandEvent event) {
        System.out.println(event.item);
        professionExpandBarItem1.setHeight(professionExpandBarItem1
            .getHeight()
            - p2attributeExpandBarComposite.computeSize(
                SWT.DEFAULT, SWT.DEFAULT).y);
        System.out.println("itemCollapsed "
            + professionExpandBarItem1.getHeight());

      }

      public void itemExpanded(ExpandEvent event) {
        System.out.println(event.item);
        professionExpandBarItem1.setHeight(p2ExpandBarComposite
            .computeSize(SWT.DEFAULT, SWT.DEFAULT).y
            + p1attributeExpandBarComposite.computeSize(
                SWT.DEFAULT, SWT.DEFAULT).y);
        System.out.println("itemExpanded "
            + professionExpandBarItem1.getHeight());
      }
    });

    // Fin profession 2

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}
TOP

Related Classes of com.gwesm.ui.temp.CascadeExpandBar2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.