]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/CommandEventWidget.java
Playground for Antti.
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / CommandEventWidget.java
1 package org.simantics.document.swt.core.widget;
2
3 import java.util.List;
4 import java.util.TreeMap;
5
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;
19
20 public class CommandEventWidget  extends PropertyWidgetManager<Object> {
21
22     @Override
23     public Object createWidget(JSONObject object) {
24         return null;
25     }
26
27     @Override
28     public void updateProperties(SWTDocument document, JSONObject object, Object widget) {
29         // No properties
30     }
31
32     @Override
33     public void updateChildren(SWTDocument document, JSONObject object, Object widget,
34             TreeMap<String, WidgetData> childMap) {
35         // No children
36     }
37
38     @Override
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();
43             context.merge(p);
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);
49                     if(manager != null) {
50                         @SuppressWarnings("unchecked")
51                         String result = manager.getProperty(document, wd.object, wd.widget, dd.getProperty());
52                         context.putValue(dd.getTarget(), result);
53                     }
54                 }
55             }
56             AbstractEventHandler handler = object.getJSONField("SCLFunction");
57             return new PostEventCommand(document, handler, context);
58         } else {
59             return null;
60         }
61     }
62     
63 }