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