1 package org.simantics.document.swt.core.widget;
4 import java.util.TreeMap;
6 import org.simantics.document.server.IEventCommand;
7 import org.simantics.document.server.JSONObject;
8 import org.simantics.document.server.bean.DataDefinition;
9 import org.simantics.document.server.client.WidgetData;
10 import org.simantics.document.server.client.WidgetManager;
11 import org.simantics.document.server.handler.AbstractEventHandler;
12 import org.simantics.document.server.io.CommandContext;
13 import org.simantics.document.server.io.CommandContextImpl;
14 import org.simantics.document.server.io.CommandContextMutable;
15 import org.simantics.document.server.io.ICommand;
16 import org.simantics.document.swt.core.SWTDocument;
17 import org.simantics.document.swt.core.base.PostEventCommand;
18 import org.simantics.document.swt.core.base.PropertyWidgetManager;
20 public class CommandEventWidget extends PropertyWidgetManager<Object> {
23 public Object createWidget(JSONObject object) {
28 public void updateProperties(SWTDocument document, JSONObject object, Object widget) {
33 public void updateChildren(SWTDocument document, JSONObject object, Object widget,
34 TreeMap<String, WidgetData> childMap) {
39 public IEventCommand eventCommand(SWTDocument document, JSONObject object, Object component, ICommand command, CommandContext p) {
40 if("event".equals(command.getCommand())) {
41 List<DataDefinition> dataDefinitions = object.getJSONField("dataDefinitions");
42 CommandContextMutable context = new CommandContextImpl();
44 for(DataDefinition dd : dataDefinitions) {
45 WidgetData wd = document.getWidgetData().get(dd.getElementId());
46 if(wd != null && wd.object != null) {
47 @SuppressWarnings("rawtypes")
48 WidgetManager manager = document.getManager(wd.object);
50 @SuppressWarnings("unchecked")
51 String result = manager.getProperty(document, wd.object, wd.widget, dd.getProperty());
52 context.putValue(dd.getTarget(), result);
56 AbstractEventHandler handler = object.getJSONField("SCLFunction");
57 return new PostEventCommand(document, handler, context);