]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java
Playground for Antti.
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / base / PropertyWidgetManager.java
1 package org.simantics.document.swt.core.base;
2
3 import java.awt.Component;
4 import java.util.Collection;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.simantics.document.server.IEventCommand;
9 import org.simantics.document.server.JSONObject;
10 import org.simantics.document.server.client.Document;
11 import org.simantics.document.server.client.WidgetData;
12 import org.simantics.document.server.client.WidgetManager;
13 import org.simantics.document.server.io.CommandContext;
14 import org.simantics.document.server.io.CommandContextImpl;
15 import org.simantics.document.server.io.CommandContextMutable;
16 import org.simantics.document.server.io.ICommand;
17 import org.simantics.document.server.io.JSONObjectUtils;
18 import org.simantics.document.swt.core.SWTDocument;
19 import org.simantics.document.swt.core.SWTViews;
20 import org.simantics.utils.datastructures.Pair;
21
22 public abstract class PropertyWidgetManager<W> implements WidgetManager<SWTDocument, W> {
23         
24         @Override
25         public String getProperty(SWTDocument document, JSONObject object, W widget, String property) {
26                 return null;
27         }
28         
29         @Override
30         public IEventCommand eventCommand(SWTDocument document, JSONObject object, W widget, ICommand command, CommandContext context) {
31             return null;
32         }
33
34 //    public static CommandContext sendEvent(SWTDocument document, Object source, String event, Object target, CommandContextMutable context) {
35 //        return sendEvent(document, document.find(source), event, target, context);
36 //    }
37     
38     public static CommandContext sendEvent(SWTDocument document, WidgetData wd, String event, Object target, CommandContextMutable context) {
39         Collection<ICommand> commands = JSONObjectUtils.getCommands(wd.object);
40
41         if(context == null) context = new CommandContextImpl();
42         context.putValue("event", event);
43         
44         List<Pair<WidgetData, ICommand>> data = SWTViews.getTriggeredCommands(document, commands, "eventOut");
45     
46         return document.handleCommands(data, context, wd.widget);
47
48     }
49         
50 }