1 package org.simantics.document.swt.core.base;
3 import org.eclipse.swt.widgets.Composite;
4 import org.eclipse.swt.widgets.Control;
5 import org.simantics.document.server.JSONObject;
6 import org.simantics.document.server.client.WidgetData;
7 import org.simantics.document.swt.core.SWTDocument;
9 public abstract class WidgetContainer<C extends Control> {
13 abstract protected Control doCreateControl(SWTDocument document, Composite parent, JSONObject object);
14 abstract protected void doUpdateProperties(SWTDocument document, Control control, JSONObject object);
16 @SuppressWarnings("unchecked")
17 public void createControl(SWTDocument document, Composite parent, final JSONObject object) {
18 control = (C)doCreateControl(document, parent, object);
20 new Exception().printStackTrace();
23 doUpdateProperties(document, control, object);
26 public C getControl() {
30 @SuppressWarnings("unchecked")
31 public <T> T getOrCreateControl(SWTDocument document, JSONObject object) {
32 if(control == null || control.isDisposed()) {
33 String parentId = object.getJSONField("parent");
34 WidgetData parent = document.getWidget(parentId);
36 WidgetContainer<?> parentContainer = (WidgetContainer<?>)parent.widget;
37 Composite pc = (Composite)parentContainer.getOrCreateControl(document, parent.object);
38 // TODO: pc may be disposed, how to handle this and why is it happening?
39 if(pc != null && !pc.isDisposed())
40 createControl(document, pc, object);
46 public void updateProperties(SWTDocument document, JSONObject object) {
48 doUpdateProperties(document, control, object);