1 /*******************************************************************************
2 * Copyright (c) 2019 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.document.swt.core.widget;
14 import java.util.List;
15 import java.util.TreeMap;
17 import org.simantics.document.server.IEventCommand;
18 import org.simantics.document.server.JSONObject;
19 import org.simantics.document.server.bean.DataDefinition;
20 import org.simantics.document.server.client.WidgetData;
21 import org.simantics.document.server.client.WidgetManager;
22 import org.simantics.document.server.handler.AbstractEventHandler;
23 import org.simantics.document.server.io.CommandContext;
24 import org.simantics.document.server.io.CommandContextImpl;
25 import org.simantics.document.server.io.CommandContextMutable;
26 import org.simantics.document.server.io.ICommand;
27 import org.simantics.document.swt.core.SWTDocument;
28 import org.simantics.document.swt.core.base.PostEventCommand;
29 import org.simantics.document.swt.core.base.PropertyWidgetManager;
31 public class CommandEventWidget extends PropertyWidgetManager<Object> {
34 public Object createWidget(JSONObject object) {
39 public void updateProperties(SWTDocument document, JSONObject object, Object widget) {
44 public void updateChildren(SWTDocument document, JSONObject object, Object widget,
45 TreeMap<String, WidgetData> childMap) {
50 public IEventCommand eventCommand(SWTDocument document, JSONObject object, Object component, ICommand command, CommandContext p) {
51 if("event".equals(command.getCommand())) {
52 List<DataDefinition> dataDefinitions = object.getJSONField("dataDefinitions");
53 CommandContextMutable context = new CommandContextImpl();
55 for(DataDefinition dd : dataDefinitions) {
56 WidgetData wd = document.getWidgetData().get(dd.getElementId());
57 if(wd != null && wd.object != null) {
58 @SuppressWarnings("rawtypes")
59 WidgetManager manager = document.getManager(wd.object);
61 @SuppressWarnings("unchecked")
62 String result = manager.getProperty(document, wd.object, wd.widget, dd.getProperty());
63 context.putValue(dd.getTarget(), result);
67 AbstractEventHandler handler = object.getJSONField("SCLFunction");
68 return new PostEventCommand(document, handler, context);