-package org.simantics.views.swt.client.impl;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.resource.ColorDescriptor;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.ScrolledComposite;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.graphics.RGB;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.simantics.views.ViewUtils.LayoutBean;\r
-import org.simantics.views.swt.client.base.SWTViewUtils;\r
-import org.simantics.views.swt.client.base.SingleSWTViewNode;\r
-\r
-public class SWTScrolledComposite extends SingleSWTViewNode<ScrolledComposite> {\r
- \r
- private Composite explorers;\r
-\r
- private static final long serialVersionUID = 7932335224632082902L;\r
- \r
- public LayoutBean layout;\r
- \r
- private int minSize = 100;\r
- \r
- protected ScrollListener listener;\r
- \r
- public class ScrollListener implements Listener {\r
-\r
- public Control[] composites;\r
-\r
- final public int minSize;\r
- \r
- private boolean pending = false;\r
-\r
- public ScrollListener(int minSize) {\r
- this.minSize = minSize;\r
- }\r
-\r
- @Override\r
- public void handleEvent(Event event) {\r
- handleEvent();\r
- }\r
-\r
- public void handleEvent() {\r
- \r
- if(pending) return;\r
- \r
- pending = true;\r
- \r
- Display.getCurrent().asyncExec(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- doHandleEvent();\r
- }\r
- \r
- });\r
- \r
- }\r
-\r
- public void doHandleEvent() {\r
-\r
- if(isDisposed()) return;\r
- \r
- pending = false;\r
-\r
- Point c = control.getSize();\r
- Point o = explorers.getSize();\r
- Point p = explorers.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);\r
- if(!o.equals(p)) {\r
- explorers.setSize(c.x-25, p.y);\r
- }\r
-\r
- }\r
-\r
- }\r
- \r
- @Override\r
- public Control getControl() {\r
- return explorers;\r
- }\r
- \r
- @Override\r
- public void createControls(org.eclipse.swt.widgets.Composite parent) {\r
- \r
- control = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);\r
- \r
- setProperties();\r
- \r
- listener = new ScrollListener(minSize);\r
-\r
- control.setBackground( (Color) getResourceManager().get( ColorDescriptor.createFrom(new RGB(245, 245, 245)) ) );\r
- control.setLayout(GridLayoutFactory.fillDefaults()\r
- .margins(0, 0).spacing(0, 0).create());\r
- control.setExpandVertical(false);\r
- control.setExpandHorizontal(false);\r
- GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(control);\r
-\r
- explorers = new Composite(control, SWT.NONE);\r
- explorers.setBackground(Display.getCurrent().getSystemColor(\r
- SWT.COLOR_WHITE));\r
- // Make sure that exploders are visible\r
- explorers.setSize(1300, 1300);\r
- explorers.setLayout(GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1)\r
- .spacing(0, 0).create());\r
-\r
- control.setMinSize(100, 100);\r
- control.setContent(explorers);\r
-\r
- createChildComposites(explorers);\r
- \r
- listener.composites = explorers.getChildren();\r
- \r
- control.addListener(SWT.Resize, listener);\r
- \r
- for (Control composite : listener.composites) {\r
- composite.addListener(SWT.Resize, listener);\r
- }\r
- \r
- }\r
-\r
- final public void synchronizeLayout(LayoutBean layout) {\r
- if(layout != null) control.setLayout(SWTViewUtils.toLayout(layout));\r
- }\r
- \r
- public static void propagate(Control control) {\r
- \r
- Control parent = control.getParent();\r
- if(parent == null) return;\r
- \r
- if(parent instanceof ScrolledComposite) {\r
- \r
- Point c = parent.getSize();\r
- Point o = control.getSize();\r
- Point p = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);\r
- if(!o.equals(p)) {\r
- control.setSize(c.x-25, p.y);\r
- }\r
- \r
- } else {\r
- \r
- propagate(parent);\r
- \r
- }\r
- \r
- }\r
- \r
-}\r
+package org.simantics.views.swt.client.impl;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.ColorDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.simantics.views.ViewUtils.LayoutBean;
+import org.simantics.views.swt.client.base.SWTViewUtils;
+import org.simantics.views.swt.client.base.SingleSWTViewNode;
+
+public class SWTScrolledComposite extends SingleSWTViewNode<ScrolledComposite> {
+
+ private Composite explorers;
+
+ private static final long serialVersionUID = 7932335224632082902L;
+
+ public LayoutBean layout;
+
+ private int minSize = 100;
+
+ protected ScrollListener listener;
+
+ public class ScrollListener implements Listener {
+
+ public Control[] composites;
+
+ final public int minSize;
+
+ private boolean pending = false;
+
+ public ScrollListener(int minSize) {
+ this.minSize = minSize;
+ }
+
+ @Override
+ public void handleEvent(Event event) {
+ handleEvent();
+ }
+
+ public void handleEvent() {
+
+ if(pending) return;
+
+ pending = true;
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ doHandleEvent();
+ }
+
+ });
+
+ }
+
+ public void doHandleEvent() {
+
+ if(isDisposed()) return;
+
+ pending = false;
+
+ Point c = control.getSize();
+ Point o = explorers.getSize();
+ Point p = explorers.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ if(!o.equals(p)) {
+ explorers.setSize(c.x-25, p.y);
+ }
+
+ }
+
+ }
+
+ @Override
+ public Control getControl() {
+ return explorers;
+ }
+
+ @Override
+ public void createControls(org.eclipse.swt.widgets.Composite parent) {
+
+ control = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+
+ setProperties();
+
+ listener = new ScrollListener(minSize);
+
+ control.setBackground( (Color) getResourceManager().get( ColorDescriptor.createFrom(new RGB(245, 245, 245)) ) );
+ control.setLayout(GridLayoutFactory.fillDefaults()
+ .margins(0, 0).spacing(0, 0).create());
+ control.setExpandVertical(false);
+ control.setExpandHorizontal(false);
+ GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(control);
+
+ explorers = new Composite(control, SWT.NONE);
+ explorers.setBackground(Display.getCurrent().getSystemColor(
+ SWT.COLOR_WHITE));
+ // Make sure that exploders are visible
+ explorers.setSize(1300, 1300);
+ explorers.setLayout(GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1)
+ .spacing(0, 0).create());
+
+ control.setMinSize(100, 100);
+ control.setContent(explorers);
+
+ createChildComposites(explorers);
+
+ listener.composites = explorers.getChildren();
+
+ control.addListener(SWT.Resize, listener);
+
+ for (Control composite : listener.composites) {
+ composite.addListener(SWT.Resize, listener);
+ }
+
+ }
+
+ final public void synchronizeLayout(LayoutBean layout) {
+ if(layout != null) control.setLayout(SWTViewUtils.toLayout(layout));
+ }
+
+ public static void propagate(Control control) {
+
+ Control parent = control.getParent();
+ if(parent == null) return;
+
+ if(parent instanceof ScrolledComposite) {
+
+ Point c = parent.getSize();
+ Point o = control.getSize();
+ Point p = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ if(!o.equals(p)) {
+ control.setSize(c.x-25, p.y);
+ }
+
+ } else {
+
+ propagate(parent);
+
+ }
+
+ }
+
+}