]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/base/SWTRoot.java
36f874d787a4d5486bd14f45977535169ad19e1b
[simantics/platform.git] / bundles / org.simantics.views.swt.client / src / org / simantics / views / swt / client / base / SWTRoot.java
1 package org.simantics.views.swt.client.base;
2
3 import org.eclipse.jface.resource.JFaceResources;
4 import org.eclipse.jface.resource.LocalResourceManager;
5 import org.eclipse.jface.resource.ResourceManager;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.Control;
8 import org.eclipse.ui.IWorkbenchSite;
9
10 public class SWTRoot extends SWTParentNode implements ISWTViewNode {
11
12         private static final long serialVersionUID = -3208359073385767918L;
13
14         private final IWorkbenchSite site;
15
16         private LocalResourceManager resourceManager;
17
18         private Composite body;
19
20         public SWTRoot(IWorkbenchSite site) {
21                 this.site = site;
22         }
23
24         @Override
25         public void reset() {
26         }
27         
28         @Override
29         public SWTRoot getRootNode() {
30                 // This is a root node!
31                 return this;
32         }
33
34         public ResourceManager getResourceManager() {
35                 if (resourceManager == null)
36                         throw new IllegalStateException("resource manager is null");
37                 return resourceManager;
38         }
39
40         public ResourceManager peekResourceManager() {
41                 return resourceManager;
42         }
43
44         @Override
45         public Control getControl() {
46                 return body;
47         }
48
49         @Override
50         public IWorkbenchSite getSite() {
51                 return site;
52         }
53         
54         public void setFocus() {
55                 body.setFocus();
56         }
57         
58         public void setVisible(boolean value) {
59                 body.setVisible(value);
60         }
61         
62         public void createControls(Composite parent) {
63                 body = parent;
64                 resourceManager = new LocalResourceManager(JFaceResources.getResources(), body);
65                 for(ISWTViewNode child : children.values()) child.createControls(body);
66         }
67         
68         public Control getSingleChild() {
69                 if(children.size() != 1) throw new IllegalStateException("SWTRoot should have exactly one child (has " + children.size() + ").");
70                 return children.values().iterator().next().getControl();
71         }
72         
73 }