]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/CommandEventWidget.java
Improvements to modelled SWT documents
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / CommandEventWidget.java
index 23311d93c18a00757af97dfea980ea379c513fcc..efded8810e0bb738e4e6ed93d7b18490bf882f93 100644 (file)
@@ -1,6 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
 package org.simantics.document.swt.core.widget;
 
-import java.util.HashMap;
 import java.util.List;
 import java.util.TreeMap;
 
@@ -10,6 +20,10 @@ import org.simantics.document.server.bean.DataDefinition;
 import org.simantics.document.server.client.WidgetData;
 import org.simantics.document.server.client.WidgetManager;
 import org.simantics.document.server.handler.AbstractEventHandler;
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandContextImpl;
+import org.simantics.document.server.io.CommandContextMutable;
+import org.simantics.document.server.io.ICommand;
 import org.simantics.document.swt.core.SWTDocument;
 import org.simantics.document.swt.core.base.PostEventCommand;
 import org.simantics.document.swt.core.base.PropertyWidgetManager;
@@ -33,10 +47,11 @@ public class CommandEventWidget  extends PropertyWidgetManager<Object> {
     }
 
     @Override
-    public IEventCommand eventCommand(SWTDocument document, JSONObject object, Object component, String command) {
-        if("event".equals(command)) {
+    public IEventCommand eventCommand(SWTDocument document, JSONObject object, Object component, ICommand command, CommandContext p) {
+        if("event".equals(command.getCommand())) {
             List<DataDefinition> dataDefinitions = object.getJSONField("dataDefinitions");
-            HashMap<String, String> data = new HashMap<String, String>();
+            CommandContextMutable context = new CommandContextImpl();
+            context.merge(p);
             for(DataDefinition dd : dataDefinitions) {
                 WidgetData wd = document.getWidgetData().get(dd.getElementId());
                 if(wd != null && wd.object != null) {
@@ -45,12 +60,12 @@ public class CommandEventWidget  extends PropertyWidgetManager<Object> {
                     if(manager != null) {
                         @SuppressWarnings("unchecked")
                         String result = manager.getProperty(document, wd.object, wd.widget, dd.getProperty());
-                        data.put(dd.getTarget(), result);
+                        context.putValue(dd.getTarget(), result);
                     }
                 }
             }
             AbstractEventHandler handler = object.getJSONField("SCLFunction");
-            return new PostEventCommand(document, handler, data);
+            return new PostEventCommand(document, handler, context);
         } else {
             return null;
         }