]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/GridCell.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / GridCell.java
1 package org.simantics.document.swt.core.widget;
2
3 import java.util.TreeMap;
4
5 import org.eclipse.jface.layout.GridDataFactory;
6 import org.eclipse.jface.layout.GridLayoutFactory;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Control;
10 import org.simantics.datatypes.literal.RGB;
11 import org.simantics.document.server.JSONObject;
12 import org.simantics.document.server.client.WidgetData;
13 import org.simantics.document.swt.core.SWTDocument;
14 import org.simantics.document.swt.core.base.HasWidgetsWidgetManager;
15 import org.simantics.document.swt.core.base.WidgetContainer;
16
17 public class GridCell extends HasWidgetsWidgetManager<Composite> {
18
19         @Override
20         protected void doUpdateProperties(SWTDocument document, Composite control, JSONObject object) {
21         }
22
23         @Override
24         protected Composite doCreateControl(SWTDocument document, Composite parent, JSONObject object) {
25                 
26                 Boolean grabVertical = object.getJSONFieldDefault("grabVertical", false);
27                 Boolean grabHorizontal = object.getJSONFieldDefault("grabHorizontal", false);
28                 Integer span = object.getJSONFieldDefault("span", 1);
29
30                 RGB.Integer background = object.getBeanJSONFieldDefault("background", RGB.Integer.BINDING, new RGB.Integer(0,255, 0));
31                 
32                 Composite result = new Composite(parent, SWT.NONE);
33                 GridDataFactory.fillDefaults().grab(grabHorizontal, grabVertical).span(span, 1).applyTo(result);
34                 GridLayoutFactory.fillDefaults().applyTo(result);
35                 result.setBackground(document.getColor(background));
36                 return result;
37                 
38         }
39         
40         @Override
41         public void updateChildren(SWTDocument document, JSONObject object, WidgetContainer widget, TreeMap<String, WidgetData> childMap) {
42                 
43                 super.updateChildren(document, object, widget, childMap);
44
45                 WidgetData child = childMap.values().iterator().next();
46                 WidgetContainer container = (WidgetContainer)child.widget;
47                 Control c = container.getControl();
48                 if(c == null || c.isDisposed()) return;
49                 GridDataFactory.fillDefaults().grab(true, true).minSize(1, 1).applyTo(c);
50                 
51         }       
52 }