]> gerrit.simantics Code Review - simantics/platform.git/blob - swt/core/base/ScrolledCompositeContent.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / swt / core / base / ScrolledCompositeContent.java
1 package org.simantics.document.swt.core.base;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.custom.ScrolledComposite;
5 import org.eclipse.swt.graphics.Point;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.ScrollBar;
8 import org.simantics.utils.ui.SWTUtils;
9
10 public class ScrolledCompositeContent extends Composite implements Runnable {
11         
12         public ScrolledCompositeContent(Composite parent, int style) {
13                 super(parent, style);
14         }
15         
16         public void refreshSize() {
17                 SWTUtils.asyncExec(this, this);
18         }
19
20         public void run() {
21
22                 if(isDisposed()) return;
23
24                 ScrolledComposite sc = (ScrolledComposite)getParent();
25                 int scWidth = sc.getSize().x;
26                 
27                 ScrollBar bar = sc.getVerticalBar();
28                 if(bar != null && bar.isVisible())
29                         scWidth -= bar.getSize().x;
30                 
31                 Point current = getSize();
32                 Point target = computeSize(scWidth, SWT.DEFAULT, true);
33                 
34                 if(!current.equals(target)) {
35                         setSize(target);
36                         sc.getParent().layout(true, true);
37                 }
38                 
39         }
40         
41 }