1 package org.simantics.views.swt.client.impl;
3 import org.eclipse.jface.layout.GridDataFactory;
4 import org.eclipse.jface.layout.GridLayoutFactory;
5 import org.eclipse.jface.resource.ColorDescriptor;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.custom.ScrolledComposite;
8 import org.eclipse.swt.graphics.Color;
9 import org.eclipse.swt.graphics.Point;
10 import org.eclipse.swt.graphics.RGB;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13 import org.eclipse.swt.widgets.Display;
14 import org.eclipse.swt.widgets.Event;
15 import org.eclipse.swt.widgets.Listener;
16 import org.simantics.views.ViewUtils.LayoutBean;
17 import org.simantics.views.swt.client.base.SWTViewUtils;
18 import org.simantics.views.swt.client.base.SingleSWTViewNode;
20 public class SWTScrolledComposite extends SingleSWTViewNode<ScrolledComposite> {
22 private Composite explorers;
24 private static final long serialVersionUID = 7932335224632082902L;
26 public LayoutBean layout;
28 private int minSize = 100;
30 protected ScrollListener listener;
32 public class ScrollListener implements Listener {
34 public Control[] composites;
36 final public int minSize;
38 private boolean pending = false;
40 public ScrollListener(int minSize) {
41 this.minSize = minSize;
45 public void handleEvent(Event event) {
49 public void handleEvent() {
55 Display.getCurrent().asyncExec(new Runnable() {
66 public void doHandleEvent() {
68 if(isDisposed()) return;
72 Point c = control.getSize();
73 Point o = explorers.getSize();
74 Point p = explorers.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
76 explorers.setSize(c.x-25, p.y);
84 public Control getControl() {
89 public void createControls(org.eclipse.swt.widgets.Composite parent) {
91 control = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
95 listener = new ScrollListener(minSize);
97 control.setBackground( (Color) getResourceManager().get( ColorDescriptor.createFrom(new RGB(245, 245, 245)) ) );
98 control.setLayout(GridLayoutFactory.fillDefaults()
99 .margins(0, 0).spacing(0, 0).create());
100 control.setExpandVertical(false);
101 control.setExpandHorizontal(false);
102 GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(control);
104 explorers = new Composite(control, SWT.NONE);
105 explorers.setBackground(Display.getCurrent().getSystemColor(
107 // Make sure that exploders are visible
108 explorers.setSize(1300, 1300);
109 explorers.setLayout(GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1)
110 .spacing(0, 0).create());
112 control.setMinSize(100, 100);
113 control.setContent(explorers);
115 createChildComposites(explorers);
117 listener.composites = explorers.getChildren();
119 control.addListener(SWT.Resize, listener);
121 for (Control composite : listener.composites) {
122 composite.addListener(SWT.Resize, listener);
127 final public void synchronizeLayout(LayoutBean layout) {
128 if(layout != null) control.setLayout(SWTViewUtils.toLayout(layout));
131 public static void propagate(Control control) {
133 Control parent = control.getParent();
134 if(parent == null) return;
136 if(parent instanceof ScrolledComposite) {
138 Point c = parent.getSize();
139 Point o = control.getSize();
140 Point p = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
142 control.setSize(c.x-25, p.y);