]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTAlternative.java
Merge "Documented difference of RuntimeEnvironmentRequest and Runti...quest2"
[simantics/platform.git] / bundles / org.simantics.views.swt.client / src / org / simantics / views / swt / client / impl / SWTAlternative.java
1 package org.simantics.views.swt.client.impl;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5
6 import org.eclipse.jface.layout.GridDataFactory;
7 import org.eclipse.jface.layout.GridLayoutFactory;
8 import org.eclipse.swt.widgets.Composite;
9 import org.simantics.views.swt.client.base.ISWTViewNode;
10 import org.simantics.views.swt.client.base.SWTParentNode;
11 import org.simantics.views.swt.client.base.SingleSWTViewNode;
12
13 public class SWTAlternative extends SingleSWTViewNode<Composite> {
14         
15         private static final long serialVersionUID = -3427445018396850285L;
16
17         private org.eclipse.swt.widgets.Composite parent;
18         
19         public Boolean condition = false;
20         
21         @Override
22         public void createControls(org.eclipse.swt.widgets.Composite parent) {
23                 
24                 this.parent = parent;
25                 
26         control = new Composite(parent, style);
27         
28         GridLayoutFactory.fillDefaults().applyTo(control);
29         GridDataFactory.fillDefaults().grab(true, true).applyTo(control);
30         
31         Collection<ISWTViewNode> nodes = getNodes();
32         if(nodes.size() > 0) {
33                 Iterator<ISWTViewNode> it = nodes.iterator();
34                 if(condition == null || !condition) {
35                         if(nodes.size() > 1) {
36                                 it.next();
37                                 it.next().createControls(control);
38                         }
39                 } else {
40                         it.next().createControls(control);
41                 }
42         }
43         
44         // TODO: can not use generic setProperties since if forms a loop through synchronizeCondition
45                 synchronizeForeground(foreground);
46                 synchronizeBackground(background);
47                 synchronizeFont(font);
48                 synchronizeLayoutData(layoutData);
49         
50         }
51         
52         final private void reset(ISWTViewNode node) {
53
54                 node.reset();
55                 if(node instanceof SWTParentNode) {
56                         SWTParentNode parentNode = (SWTParentNode)node;
57                         for(ISWTViewNode child : parentNode.getChildComposites()) reset(child);
58                 }
59                 
60         }
61         
62         final public void synchronizeCondition(Boolean condition) {
63                 
64                 if(condition == null) return;
65                 
66                 Composite currentControl = control;
67                 
68                 reset(this);
69                 
70                 currentControl.dispose();
71                 
72                 createControls(parent);
73                 
74                 parent.layout(true);
75                 
76         }
77         
78 }