]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Improvements to modelled SWT documents 40/3140/5
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 21 Aug 2019 12:46:28 +0000 (15:46 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 22 Aug 2019 07:15:41 +0000 (07:15 +0000)
gitlab #357

Change-Id: I281e90d871157775e1d9b789eb1a8886fb87bb17

20 files changed:
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java
bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph
bundles/org.simantics.document.server/scl/Document/All.scl
bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java
bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java
bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java
bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/CommandEventWidget.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/Explorer.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ExplorerListener.java [new file with mode: 0644]
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/FillComposite.java
bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/GridComposite.java

index 2f52153a1192b45e2a6c33e42afd2da58a86e1a1..d27eeaa79244a5785070cbb0da57b6bebe52ecda 100644 (file)
@@ -427,6 +427,10 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta
         ((Control)explorer.getControl()).addListener(eventType, listener);
     }
 
+    public void removeListenerFromControl(int eventType, Listener listener) {
+        ((Control)explorer.getControl()).removeListener(eventType, listener);
+    }
+
     public void finish() {
         created = true;
         createControls(site);
index 4845558ea2b21bb1a72545af5b2957f347f22496..230dc878614d4fa96b5e71950683fa7d45878a39 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
 L0 = <http://www.simantics.org/Layer0-1.1>
 STR = <http://www.simantics.org/Structural-1.2>
 SG = <http://www.simantics.org/Scenegraph-1.1>
@@ -100,6 +111,65 @@ Documentation.child10 : L0.Template
       Documentation.Relations.parent %connection
     %connection : STR.Connection
 
+Documentation.child1_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part1.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child2_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part2.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child3_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part3.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child4_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part4.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child5_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part5.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child6_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part6.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child7_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part7.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child8_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part8.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child9_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part9.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
+
+Documentation.child10_ : L0.Template
+  @template %parent %child
+    _ : STR.Connection
+     Documentation.Relations.part10.Inverse %parent
+     Documentation.Relations.parent.Inverse %child
 
 Documentation.singleData : L0.Template
   @template %commandEvent %defVar %dataSource %eventSource %eventRelation %sourceName %targetName %DataSourceConn %DataTargetConn %EventConn
index a90a24bcb62c30c55cad163eb3d242f869bec690..d676e2a3b2a296bacb86094ebec20bb6695ec510 100644 (file)
@@ -122,9 +122,9 @@ importJava "org.simantics.document.server.Functions" where
     readEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> <ReadGraph> String) -> <ReadGraph> AbstractEventHandler
     eventHandler :: ((String -> Maybe String) -> String) -> <ReadGraph> AbstractEventHandler
 
-    readEventHandler2 :: (CommandContext -> <ReadGraph> Maybe CommandResult) -> <ReadGraph> AbstractEventHandler
-    writeEventHandler2 :: (CommandContext -> <WriteGraph> Maybe CommandResult) -> <ReadGraph> AbstractEventHandler
-    eventHandler2 :: (CommandContext -> Maybe CommandResult) -> <ReadGraph> AbstractEventHandler
+    readEventHandler2 :: (CommandContext -> <ReadGraph,Proc> Maybe CommandResult) -> <ReadGraph> AbstractEventHandler
+    writeEventHandler2 :: (CommandContext -> <WriteGraph,Proc> Maybe CommandResult) -> <ReadGraph> AbstractEventHandler
+    eventHandler2 :: (CommandContext -> <Proc> Maybe CommandResult) -> <ReadGraph> AbstractEventHandler
     
     responseHandler :: Variable -> String -> <ReadGraph> AbstractEventHandler
 
@@ -147,6 +147,9 @@ importJava "org.simantics.document.server.Functions" where
     compileDocumentSCLHandlerValueExpression :: Variable -> <ReadGraph> String
 
     primitiveProperties :: <Proc> DocumentProperties
+
+contextVariable :: Variable -> <ReadGraph> Variable
+contextVariable var = propertyValue (variableParent var) "input"
     
 propertyValueCached :: Serializable a => Typeable a => Variable -> String -> <ReadGraph> a
 propertyValueCached var prop = propertyValueCached_ var prop binding
index b971fef4c6b6ca8540d8cc257c7166db1d0c7f04..c10dafc2dc075ef1e4c5b340d396650878e93811 100644 (file)
@@ -1,11 +1,25 @@
+/*******************************************************************************
+ * 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.server;
 
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandContextMutable;
+
 public interface IEventCommand {
     
     public void setNext(IEventCommand command);
     public IEventCommand getNext();    
-    public void handleCommand();
-    public void commandSuccess();
+    public CommandContext handleCommand(CommandContextMutable context);
+    public CommandContext commandSuccess(CommandContextMutable context);
     public void commandError(String errorMessage);
 
 }
index f47c0c5c38ff53eade8eaa9834d641aa4e0cba06..eabb2afdd3110f90db2504719e889ffde59dc890 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * 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.server.bean;
 
 import org.simantics.document.server.io.CommandContext;
@@ -12,6 +23,10 @@ public class Command implements ICommand {
 
     public Command() {}
     
+    public Command(String command) {
+        this.command = command;
+    }
+
     public Command(String targetId, String trigger, String command, CommandContext constants) {
         this.targetId = targetId;
         this.trigger = trigger;
index 1235d527c4fdac3e2b2dea298734780bd49e1124..2fb138fdea5c104368612166f6f6d0c538e2149a 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * 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.server.client;
 
 import java.util.HashSet;
@@ -5,6 +16,8 @@ import java.util.TreeMap;
 
 import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.JSONObject;
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.ICommand;
 
 public class WidgetData {
        
@@ -67,12 +80,12 @@ public class WidgetData {
     }
     
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    public IEventCommand eventCommand(String command) {
+    public IEventCommand eventCommand(ICommand command, CommandContext c) {
         if(object == null)
             return null;
         WidgetManager manager = document.getManager(object);
         if(manager != null)
-            return manager.eventCommand(document, object, widget, command); 
+            return manager.eventCommand(document, object, widget, command, c); 
         else
             return null;
     }
index 8474bfd15b1b14e3dcbda4f74c38fdc2d8955662..ab0b8cf87503437c38f16f2e9f19cd98dafcd7e0 100644 (file)
@@ -1,20 +1,33 @@
+/*******************************************************************************
+ * 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.server.client;
 
 import java.util.TreeMap;
 
 import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.JSONObject;
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.ICommand;
 
 public interface WidgetManager<D extends Document, W> {
 
        public W createWidget(JSONObject object);
 
        public void updateProperties(D document, JSONObject object, W widget);
-       
+
        public void updateChildren(D document, JSONObject object, W widget, TreeMap<String, WidgetData> childMap);
-       
-    public IEventCommand eventCommand(D document, JSONObject object, W widget, String command);
-       
+
+       public IEventCommand eventCommand(D document, JSONObject object, W widget, ICommand command, CommandContext context);
+
        public String getProperty(D document, JSONObject object, W widget, String property);
-       
+
 }
\ No newline at end of file
index 41183050f2c969c4833994eddc4509a508afdaaa..1e97e22771ced6815a4b55cfadc1d8be1722196f 100644 (file)
@@ -1,6 +1,18 @@
+/*******************************************************************************
+ * 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;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 import org.eclipse.jface.viewers.ISelectionProvider;
@@ -8,20 +20,25 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Font;
 import org.eclipse.ui.IWorkbenchSite;
 import org.simantics.document.server.client.Document;
-import org.simantics.document.server.handler.AbstractEventHandler;
+import org.simantics.document.server.client.WidgetData;
+import org.simantics.document.server.io.AbstractEventHandler;
 import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandContextMutable;
+import org.simantics.document.server.io.ICommand;
+import org.simantics.utils.datastructures.Pair;
 
 public interface SWTDocument extends Document {
 
     public static final Map<String,String> NO_PARAMETERS = Collections.emptyMap();
-    
+
     IWorkbenchSite getSite();
        ISelectionProvider getSelectionProvider();
        Color getColor(org.simantics.datatypes.literal.RGB.Integer bean);
        Font getFont(org.simantics.datatypes.literal.Font bean);
-       void post(AbstractEventHandler handler, CommandContext parameters);
+       void post(AbstractEventHandler handler, CommandContextMutable context);
+       CommandContext handleCommands(List<Pair<WidgetData, ICommand>> data, CommandContextMutable context, Object component);
        void layout();
-       
+
     void displayError(String error);
-       
+
 }
index 58c280595b0ac8fd31de57ca3d5cd6a45fdbaebd..e2a64ee1d445bc69c7025b3bfca4b71a9326e537 100644 (file)
@@ -1,8 +1,21 @@
+/*******************************************************************************
+ * 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;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 
 import org.eclipse.jface.layout.GridDataFactory;
@@ -15,16 +28,20 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.IWorkbenchSite;
 import org.simantics.db.common.utils.Logger;
+import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.JSONObject;
 import org.simantics.document.server.client.DocumentClient;
 import org.simantics.document.server.client.WidgetData;
 import org.simantics.document.server.client.WidgetMapping;
-import org.simantics.document.server.handler.AbstractEventHandler;
+import org.simantics.document.server.io.AbstractEventHandler;
 import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandContextMutable;
+import org.simantics.document.server.io.ICommand;
 import org.simantics.document.swt.core.base.WidgetContainer;
 import org.simantics.document.swt.core.widget.FillComposite;
 import org.simantics.ui.colors.Colors;
 import org.simantics.ui.fonts.Fonts;
+import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.threads.IThreadWorkQueue;
 import org.simantics.utils.threads.SWTThread;
 
@@ -41,9 +58,9 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
        private boolean requireLayout=false;
 
        public SWTDocumentClient(WidgetMapping mapping, ISelectionProvider selectionProvider, IWorkbenchSite site, Composite container) {
-               
+
                super(mapping, SWTViews.getCommandMapping());
-               
+
                this.container = container;
                this.site = site;
                this.selectionProvider = selectionProvider;
@@ -55,19 +72,19 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
                FillComposite mgr = new FillComposite();
                WidgetContainer<?> wc = mgr.createWidget(rootObject); 
                wc.createControl(this, container, rootObject);
-               
+
                GridDataFactory.fillDefaults().grab(true, true).minSize(1, 1).applyTo((Control)wc.getControl());
                GridLayoutFactory.fillDefaults().applyTo((Composite)wc.getControl());
-               
+
                widgetData.put("root", new WidgetData(this, wc, rootObject));
-               
+
        }
-       
+
        @Override
        public IThreadWorkQueue thread() {
                return thread;
        }
-       
+
        @Override
        public Color getColor(org.simantics.datatypes.literal.RGB.Integer descriptor) {
                Color color = colors.get(descriptor);
@@ -77,7 +94,7 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
                }
                return color;
        }
-       
+
        @Override
        public Font getFont(org.simantics.datatypes.literal.Font descriptor) {
                Font font = fonts.get(descriptor);
@@ -87,22 +104,23 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
                }
                return font;
        }
-       
+
        @Override
        public ISelectionProvider getSelectionProvider() {
                return selectionProvider;
        }
-       
+
        @Override
        public IWorkbenchSite getSite() {
                return site;
        }
-       
+
        @Override
-       public void post(final AbstractEventHandler handler, CommandContext parameters) {
+       public void post(AbstractEventHandler handler, CommandContextMutable parameters) {
                handler.handle(parameters);
        }
 
+
        @Override
        protected void updateDocument(Collection<JSONObject> objects) {
                assert thread.currentThreadAccess();
@@ -115,9 +133,9 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
 
        @Override
        protected void updateTree(HashSet<WidgetData> updates) {
-               
+
                if(updates.isEmpty()) return;
-               
+
                for(WidgetData data : updates) {
                        WidgetContainer<?> container = (WidgetContainer<?>)data.widget;
                        Control ctrl = container.getControl();
@@ -130,29 +148,59 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
                                }
                        }
                }
-               
+
                super.updateTree(updates);
-               
+
                for(WidgetData data : widgetData.values()) {
                        WidgetContainer<?> container = (WidgetContainer<?>)data.widget;
                        if(container != null)
                            container.getOrCreateControl(this, data.object);
                }
-               
+
+       }
+
+       @Override
+       public CommandContext handleCommands(List<Pair<WidgetData, ICommand>> data, CommandContextMutable context, Object component) {
+
+               // Build a linked list of commands
+
+               ArrayList<IEventCommand> commands = new ArrayList<>();
+               for(Pair<WidgetData, ICommand> pair : data) {
+                       WidgetData d = pair.first;
+
+                       ICommand c = pair.second;
+                       IEventCommand p = d.eventCommand(c, null);
+//                     if(component != null && p != null)
+//                             p.setTrigger(component);
+                       if(p != null) {
+                               if(!commands.isEmpty())
+                                       commands.get(commands.size()-1).setNext(p);
+                               commands.add(p);
+                       }
+               }
+
+               // Execute the first command, the linked list handles the rest of them
+               if(!commands.isEmpty()) {
+                       try {
+                               commands.get(0).handleCommand(context);
+                       } finally {
+                       }
+               }
+               return context;
        }
-       
+
        @Override
        public void layout() {
                requireLayout = true;
        }
-       
+
     @Override
     public HashMap<String, WidgetData> getWidgetData() {
         return widgetData;
     }
-    
+
     public void displayError(String error) {
         Logger.defaultLogError(error);
     }
-       
+
 }
index 468bf7bdaec4295d561e25b2f32e1212dcc06eef..3ea5da8a6d76ecfd3762a3133eb4d8e7c2d087b4 100644 (file)
@@ -1,6 +1,20 @@
+/*******************************************************************************
+ * 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;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.eclipse.swt.widgets.Composite;
@@ -8,8 +22,11 @@ import org.eclipse.swt.widgets.Control;
 import org.simantics.document.server.JSONObject;
 import org.simantics.document.server.client.CommandMapping;
 import org.simantics.document.server.client.CommandMappingImpl;
+import org.simantics.document.server.client.Document;
+import org.simantics.document.server.client.WidgetData;
 import org.simantics.document.server.client.WidgetMapping;
 import org.simantics.document.server.client.WidgetMappingImpl;
+import org.simantics.document.server.io.ICommand;
 import org.simantics.document.swt.core.base.ScrolledCompositeContent;
 import org.simantics.document.swt.core.widget.BrowserWidget;
 import org.simantics.document.swt.core.widget.ButtonWidget;
@@ -23,13 +40,14 @@ import org.simantics.document.swt.core.widget.LabelWidget;
 import org.simantics.document.swt.core.widget.SCLTextEditor;
 import org.simantics.document.swt.core.widget.ScrolledCompositeWidget;
 import org.simantics.document.swt.core.widget.TrackedTextWidget;
+import org.simantics.utils.datastructures.Pair;
 
 public class SWTViews {
 
        private static WidgetMappingImpl mapping = null;
-       
+
        public static WidgetMapping getMapping() {
-               
+
                if(mapping == null) {
                        mapping = new WidgetMappingImpl();
                        mapping.register("Root", new FillComposite());
@@ -45,25 +63,40 @@ public class SWTViews {
                        mapping.register("Browser", new BrowserWidget());
                        mapping.register("SCLTextEditor", new SCLTextEditor());
                }
-               
+
                return mapping;
-               
+
+       }
+
+       private static CommandMappingImpl commandMapping = null;
+
+       public static CommandMapping getCommandMapping() {
+
+               if(commandMapping == null) {
+                       commandMapping = new CommandMappingImpl();
+                       commandMapping.register("Button", new ButtonWidget.ButtonCommandManager());
+                       commandMapping.register("Explorer", new Explorer.ExplorerCommandManager());
+               }
+
+               return commandMapping;
+
+       }
+
+       public static List<Pair<WidgetData, ICommand>> getTriggeredCommands(Document document, Collection<ICommand> commands, String trigger) {
+               // Nulls should not get this far
+               assert(commands != null);
+               List<Pair<WidgetData, ICommand>> data = new ArrayList<>();
+               for(ICommand c : commands) {
+                       if(c.getCommand() == null || c.getTargetId() == null || c.getTrigger() == null)
+                               continue;
+                       if(trigger.equals(c.getTrigger())) {
+                               WidgetData wd = document.getWidgetData().get(c.getTargetId());
+                               if(wd != null)
+                                       data.add(new Pair<WidgetData, ICommand>(wd, c));
+                       }
+               }
+               return data;
        }
-       
-    private static CommandMappingImpl commandMapping = null;
-    
-    public static CommandMapping getCommandMapping() {
-        
-        if(commandMapping == null) {
-            
-            commandMapping = new CommandMappingImpl();
-            commandMapping.register("Button", new ButtonWidget.ButtonCommandManager());
-            
-        }
-        
-        return commandMapping;
-        
-    }
 
        public static void notifyScrolledComposite(Control c) {
                if(c instanceof ScrolledCompositeContent) {
@@ -75,17 +108,17 @@ public class SWTViews {
                if(parent == null) return;
                notifyScrolledComposite(parent);
        }
-       
+
        public static Map<String, Object> encoded = new HashMap<String, Object>();
-       
+
        public static String encode(JSONObject object, String property, Object data) {
            String key = object.getId() + "#" + property;
            encoded.put(key, data);
            return key;
        }
-       
+
        public static Object decode(String key) {
            return encoded.get(key);
        }
-       
+
 }
index 3bd0364e7e7c19a27e7661b4bf299d9797a6c47a..57a2fbbe8312e0e3bb397b194d7f2248172e10b6 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.document.swt.core.base;
 
 import org.simantics.document.server.IEventCommand;
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandContextMutable;
 import org.simantics.document.swt.core.SWTDocument;
 
 public abstract class AbstractEventCommand implements IEventCommand {
@@ -23,9 +25,10 @@ public abstract class AbstractEventCommand implements IEventCommand {
     }
     
     @Override
-    public void commandSuccess() {
+    public CommandContext commandSuccess(CommandContextMutable context) {
         if(next != null)
-            next.handleCommand();
+            return next.handleCommand(context);
+        return context;
     }
 
     @Override
index ff6d4fd13d5aa6d20e0894339c02bee95fc68569..7214bdd1f1691057c25a304621b4112339c9ada9 100644 (file)
@@ -1,40 +1,48 @@
+/*******************************************************************************
+ * 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.base;
 
-import java.util.Map;
-
-import org.simantics.document.server.handler.AbstractEventHandler;
+import org.simantics.document.server.io.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.swt.core.SWTDocument;
 
 public class PostEventCommand extends AbstractEventCommand {
     
     private AbstractEventHandler handler;
-    private CommandContextImpl parameters;
+    private CommandContextMutable context;
     
-    public PostEventCommand(SWTDocument document, AbstractEventHandler handler, Map<String, String> parameters) {
-        this(document, handler, parameters, null);
+    public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context) {
+        this(document, handler, context, null);
     }
     
-    public PostEventCommand(SWTDocument document, AbstractEventHandler handler, Map<String, String> parameters, PostEventCommand next) {
+    public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context, PostEventCommand next) {
         super(document);
         this.handler = handler;
-        this.parameters = new CommandContextImpl();
-        for(Map.Entry<String, String> entry : parameters.entrySet()) {
-               this.parameters.putString(entry.getKey(), entry.getValue());
-        }
+        this.context = context;
         this.next = next;
     }
 
     @Override
-    public void handleCommand() {
-        document.post(handler, parameters);
+    public CommandContext handleCommand(CommandContextMutable context) {
+        document.post(handler, context);
+        return context;
     }
 
     @Override
-    public void commandSuccess() {
+    public CommandContext commandSuccess(CommandContextMutable context) {
         if(next != null)
-            next.handleCommand();
+            return next.handleCommand(context);
+        return context;
     }
 
     @Override
index 1c329706107d98a4eada3e872ebb116c340541da..f48111671e1ec47927ece48ee7cfda2b1c1643d2 100644 (file)
@@ -1,20 +1,53 @@
+/*******************************************************************************
+ * 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.base;
 
+import java.util.Collection;
+import java.util.List;
+
 import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.JSONObject;
+import org.simantics.document.server.client.WidgetData;
 import org.simantics.document.server.client.WidgetManager;
+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.server.io.JSONObjectUtils;
 import org.simantics.document.swt.core.SWTDocument;
+import org.simantics.document.swt.core.SWTViews;
+import org.simantics.utils.datastructures.Pair;
 
 public abstract class PropertyWidgetManager<W> implements WidgetManager<SWTDocument, W> {
-       
+
        @Override
        public String getProperty(SWTDocument document, JSONObject object, W widget, String property) {
                return null;
        }
-       
+
        @Override
-       public IEventCommand eventCommand(SWTDocument document, JSONObject object, W widget, String command) {
-           return null;
+       public IEventCommand eventCommand(SWTDocument document, JSONObject object, W widget, ICommand command, CommandContext context) {
+               return null;
+       }
+
+       public static CommandContext sendEvent(SWTDocument document, WidgetData wd, String event, Object target, CommandContextMutable context) {
+               Collection<ICommand> commands = JSONObjectUtils.getCommands(wd.object);
+
+               if(context == null) context = new CommandContextImpl();
+               context.putValue("event", event);
+
+               List<Pair<WidgetData, ICommand>> data = SWTViews.getTriggeredCommands(document, commands, "eventOut");
+
+               return document.handleCommands(data, context, wd.widget);
        }
 
-}
+}
\ No newline at end of file
index 303460deab8fc6b1474887e4bc73c0453a08d7e5..453d1d0a7261d1c80ba0688475490f25e65730cc 100644 (file)
@@ -1,19 +1,35 @@
+/*******************************************************************************
+ * 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.ArrayList;
-import java.util.LinkedHashMap;
+import java.util.List;
 
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
-import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.client.WidgetData;
+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.PropertyWidgetManager;
+import org.simantics.utils.datastructures.Pair;
 
 public class ButtonSelectionListener implements SelectionListener {
-    
-    private LinkedHashMap<WidgetData, String> data;
-    
-    public ButtonSelectionListener(LinkedHashMap<WidgetData, String> data) {
+
+    private WidgetData wd;
+    private List<Pair<WidgetData, ICommand>> data;
+
+    public ButtonSelectionListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
+        this.wd = wd;
         this.data = data;
     }
 
@@ -24,27 +40,16 @@ public class ButtonSelectionListener implements SelectionListener {
 
     @Override
     public void widgetDefaultSelected(SelectionEvent e) {
-        SWTDocument document = null;
-        // Build a linked list of commands
-        ArrayList<IEventCommand> commands = new ArrayList<IEventCommand>();
-        for(WidgetData d : data.keySet()) {
-            document = (SWTDocument)d.document; // assume that all widgets are from the same document
-            IEventCommand p = d.eventCommand(data.get(d));
-            if(p != null) {
-                if(!commands.isEmpty())
-                    commands.get(commands.size()-1).setNext(p);
-                commands.add(p);
-            }
+
+        CommandContextMutable context = new CommandContextImpl();
+        context.putValue("event", "onPress");
+
+        if(!data.isEmpty()) {
+            ((SWTDocument)wd.document).handleCommands(data, context, e.widget);
         }
 
-        // empty errors
-//        if(document != null)
-//            document.displayError("");
+        PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context);
 
-        // Execute the first command, the linked list handles the rest of them
-        if(!commands.isEmpty())
-            commands.get(0).handleCommand();
-    
     }
-    
+
 }
\ No newline at end of file
index 384ef88cd8638f23e0f17dec7005cedc52b7ca49..72c7c360b0566529d0941f58557ed9cd93d4c4eb 100644 (file)
@@ -1,11 +1,20 @@
+/*******************************************************************************
+ * 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.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionListener;
@@ -17,11 +26,18 @@ import org.simantics.document.server.bean.Command;
 import org.simantics.document.server.client.CommandManager;
 import org.simantics.document.server.client.WidgetData;
 import org.simantics.document.server.handler.AbstractEventHandler;
-import org.simantics.document.server.handler.EventHandler;
+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.server.io.JSONObjectUtils;
 import org.simantics.document.swt.core.SWTDocument;
+import org.simantics.document.swt.core.SWTViews;
 import org.simantics.document.swt.core.base.LeafWidgetManager;
 import org.simantics.document.swt.core.base.PostEventCommand;
 import org.simantics.document.swt.core.base.WidgetContainer;
+import org.simantics.utils.datastructures.Pair;
+import org.simantics.utils.ui.SWTUtils;
 
 public class ButtonWidget extends LeafWidgetManager<Button> {
 
@@ -55,23 +71,13 @@ public class ButtonWidget extends LeafWidgetManager<Button> {
         public Collection<Object> updateCommandListeners(final SWTDocument document, final JSONObject object,
                 WidgetContainer<Button> container) {
             
-            List<Command> commands = object.getJSONField("commands");
+            WidgetData wd = document.getWidget(JSONObjectUtils.getId(object));
+            List<ICommand> commands = object.getJSONField("commands");
             HashSet<Object> listeners = new HashSet<Object>();
-            LinkedHashMap<WidgetData, String> data = new LinkedHashMap<WidgetData, String>();
-            if(commands != null) {
-                   for(Command c : commands) {
-                       if(c.getCommand() == null || c.getTargetId() == null || c.getTrigger() == null)
-                           continue;
-                       String trigger = c.getTrigger();
-                       if("click".equals(trigger)) {
-                           WidgetData wd = document.getWidgetData().get(c.getTargetId());
-                           if(wd != null)
-                               data.put(wd, c.getCommand());
-                       }
-                   }
-            }
-            data.put(document.getWidgetData().get(object.getId()), "onPress");
-            SelectionListener listener = new ButtonSelectionListener(data);
+            List<Pair<WidgetData, ICommand>> data = new ArrayList<>();
+            data.addAll(SWTViews.getTriggeredCommands(document, commands, "eventOut"));
+            data.add(new Pair<WidgetData, ICommand>(wd, new Command("onPress")));
+            SelectionListener listener = new ButtonSelectionListener(wd, data);
             Button button = container.getControl();
             if(!button.isDisposed()) {
                button.addSelectionListener(listener);
@@ -92,11 +98,11 @@ public class ButtonWidget extends LeafWidgetManager<Button> {
     }
 
     @Override
-    public IEventCommand eventCommand(SWTDocument document, JSONObject object, WidgetContainer widget, String command) {
-        if("onPress".equals(command)) {
+    public IEventCommand eventCommand(SWTDocument document, JSONObject object, WidgetContainer widget, ICommand command, CommandContext p) {
+        if("onPress".equals(command.getCommand())) {
+            CommandContextMutable context = new CommandContextImpl().merge(p);
             AbstractEventHandler onPress = object.getJSONField("onPress");
-            Map<String, String> data = Collections.emptyMap();
-            return new PostEventCommand(document, onPress, data);
+            return new PostEventCommand(document, onPress, context);
         }
         return null;
     }  
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;
         }
index deabd7573d3196eb9a0cd2a059f1c1bb20c64ae4..99f5cbd241272728f49de64a7290d7b333d245bb 100644 (file)
@@ -1,7 +1,22 @@
+/*******************************************************************************
+ * 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.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 
 import org.eclipse.jface.viewers.ISelection;
@@ -11,6 +26,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
 import org.eclipse.ui.IWorkbenchSite;
 import org.simantics.Simantics;
 import org.simantics.browsing.ui.Column;
@@ -22,15 +38,28 @@ import org.simantics.browsing.ui.swt.widgets.ModelBrowser;
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;
 import org.simantics.db.layer0.variable.VariableBean;
 import org.simantics.db.management.ISessionContext;
+import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.JSONObject;
+import org.simantics.document.server.bean.Command;
+import org.simantics.document.server.client.CommandManager;
+import org.simantics.document.server.client.WidgetData;
+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.server.io.JSONObjectUtils;
 import org.simantics.document.swt.core.SWTDocument;
 import org.simantics.document.swt.core.SWTViews;
 import org.simantics.document.swt.core.base.LeafWidgetManager;
+import org.simantics.document.swt.core.base.PostEventCommand;
 import org.simantics.document.swt.core.base.WidgetContainer;
 import org.simantics.document.swt.core.bean.ColumnBean;
 import org.simantics.document.swt.core.bean.ColumnsBean;
 import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.function.Function2;
 import org.simantics.ui.selection.WorkbenchSelectionUtils;
+import org.simantics.utils.datastructures.Pair;
 
 public class Explorer extends LeafWidgetManager<ModelBrowser> {
 
@@ -48,24 +77,24 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
                }
                return result;
        }
-       
+
        @Override
        protected ModelBrowser doCreateControl(SWTDocument document, Composite parent, JSONObject object) {
-               
+
                String browseContext = object.getJSONField("browseContext");
                if(browseContext == null) return null;
 
                String contextMenuId = object.getJSONField("contextMenuId");
-               
+
                Boolean displayFilter = object.getJSONField("displayFilter");
                Boolean displayHeader = object.getJSONField("displayHeader");
                Integer style = object.getJSONField("style");
                if(style == null) style = SWT.FULL_SELECTION;
-               
+
         Boolean vscroll = object.getJSONFieldDefault("VScroll", false);
         if(Boolean.TRUE.equals(vscroll))
             style |= SWT.V_SCROLL;
-        
+
         Boolean hscroll = object.getJSONFieldDefault("HScroll", false);
         if(Boolean.TRUE.equals(hscroll))
             style |= SWT.H_SCROLL;
@@ -73,12 +102,18 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
         Boolean noscroll = object.getJSONFieldDefault("NoScroll", false);
         if(Boolean.TRUE.equals(noscroll))
             style |= SWT.NO_SCROLL;
-               
+
+        Boolean check = object.getJSONFieldDefault("Check", false);
+        if(Boolean.TRUE.equals(check))
+            style |= SWT.CHECK;
+
                StatePersistor persistor = object.getJSONField("persistor");
                final Function1<Object, Boolean> selectionListener = object.getJSONField("selectionListener");
 
+               final Function2<Object, Boolean, Boolean> checkStateListener = object.getJSONField("checkStateListener");
+
                DragSourceListenerFactory dragSourceListenerFactory = object.getJSONField("dragSourceListenerFactory");
-               
+
                final IWorkbenchSite site = document.getSite();
                final ISelectionProvider selectionProvider = document.getSelectionProvider();
 
@@ -90,27 +125,27 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
 
                ColumnsBean columns = object.getBeanJSONFieldDefault("columns", ColumnsBean.BINDING, null);
                String editingColumn = object.getJSONFieldDefault("editingColumn", null);
-               
+
 //             Column[] COLUMNS = new Column[] {
 //                             new Column("HasDisplayProperty", "Parameter description", Align.LEFT, 80, "Input parameter name", true),
 //                             new Column("HasDisplayValue", "Value", Align.RIGHT, 65, "Value"),
 //                             new Column("HasDisplayUnit", "Unit", Align.RIGHT, 100, "Unit") 
 //             };
-               
+
 //             parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
-               
+
                final ModelBrowser control = new ModelBrowser(Collections.singleton(browseContext), args, site, parent, new WidgetSupportImpl(), style);
 
                Tree tree = control.getExplorerControl();
                tree.addListener(SWT.SetData, new Listener() {
-                       
+
                        @Override
                        public void handleEvent(Event event) {
                                SWTViews.notifyScrolledComposite(control);
                        }
-                       
+
                });
-               
+
                if(columns != null)
                        control.setColumns(getColumns(columns));
                if(editingColumn != null)
@@ -121,11 +156,11 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
                        control.setDragSourceListenerFactory(dragSourceListenerFactory);
                if(displayHeader != null)
                        tree.setHeaderVisible(displayHeader);
-               
+
                control.setStatePersistor(persistor);
 
                control.finish();
-               
+
                control.setInputSource(new InputSourceImpl<Object>() {
 
                        @Override
@@ -134,7 +169,7 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
                        }
 
                });
-               
+
                // TODO: fixme!
                Object i = object.getJSONField("explorerInput");
                if(i instanceof VariableBean) {
@@ -142,23 +177,34 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
                } else {
                        control.setInput(Simantics.getSessionContext(), i);
                }
-               
+
                control.addListenerToControl(SWT.Selection, new Listener() {
 
                        @Override
                        public void handleEvent(Event event) {
 
+                               switch (event.type) {
+                               case SWT.Selection:
+                                       if (event.detail == SWT.CHECK && event.item != null) {
+                                               TreeItem item = (TreeItem) event.item;
+                                               boolean checked = item.getChecked();
+                                               if(checkStateListener != null)
+                                                       selectionListener.apply(event);
+                                       }
+                                       break;
+                               }
+
                                if(selectionListener != null)
                                        selectionListener.apply(event);
-                               
+
                                ISelection selection = (ISelection)control.getExplorer().getWidgetSelection();
-                               
+
                                // TODO: refactor this!
 
                                if(selectionProvider != null) {
                                        selectionProvider.setSelection(selection);
                                }
-                               
+
 //                             if (site != null) {
 //                                     ISelectionProvider sp = site.getSelectionProvider();
 //                                     if (sp != null) {
@@ -168,12 +214,12 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
 
                        }
 
-               });     
+               });
 
                return control;
 
        }
-       
+
        @Override
        public String getProperty(SWTDocument document, JSONObject object, WidgetContainer<ModelBrowser> widget, String property) {
            if("selection".equals(property)) {
@@ -183,4 +229,46 @@ public class Explorer extends LeafWidgetManager<ModelBrowser> {
            return null;
        }
 
+    public static class ExplorerCommandManager implements CommandManager<SWTDocument, WidgetContainer<ModelBrowser>> {
+
+        @Override
+        public Collection<Object> updateCommandListeners(final SWTDocument document, final JSONObject object,
+                WidgetContainer<ModelBrowser> container) {
+
+            WidgetData wd = document.getWidget(JSONObjectUtils.getId(object));
+            List<ICommand> commands = object.getJSONField("commands");
+            HashSet<Object> listeners = new HashSet<Object>();
+            List<Pair<WidgetData, ICommand>> data = new ArrayList<>();
+            data.addAll(SWTViews.getTriggeredCommands(document, commands, "eventOut"));
+            data.add(new Pair<WidgetData, ICommand>(wd, new Command("onCheck")));
+            Listener listener = new ExplorerListener(wd, data);
+            ModelBrowser browser = container.getControl();
+            if(!browser.isDisposed()) {
+                browser.addListenerToControl(SWT.Selection, listener);
+                listeners.add(listener);
+            }
+
+            return listeners;
+
+        }
+
+        @Override
+        public void removeListener(WidgetContainer<ModelBrowser> container, Object listener) {
+            if(container.getControl().isDisposed()) return;
+            if(listener instanceof ExplorerListener)
+                container.getControl().removeListenerFromControl(SWT.Selection, (Listener)listener);
+        }
+
+    }
+
+    @Override
+    public IEventCommand eventCommand(SWTDocument document, JSONObject object, WidgetContainer widget, ICommand command, CommandContext p) {
+        if("onCheck".equals(command.getCommand())) {
+            CommandContextMutable context = new CommandContextImpl().merge(p);
+            AbstractEventHandler onCheck = object.getJSONField("onCheck");
+            return new PostEventCommand(document, onCheck, context);
+        }
+        return null;
+    }
+
 }
diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ExplorerListener.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ExplorerListener.java
new file mode 100644 (file)
index 0000000..0c63957
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.TreeItem;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.document.server.client.WidgetData;
+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.PropertyWidgetManager;
+import org.simantics.utils.datastructures.Pair;
+
+public class ExplorerListener implements Listener {
+
+    private WidgetData wd;
+    private List<Pair<WidgetData, ICommand>> data;
+
+    public ExplorerListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
+        this.wd = wd;
+        this.data = data;
+    }
+
+    @Override
+    public void handleEvent(Event event) {
+        switch (event.type) {
+        case SWT.Selection:
+            if (event.detail == SWT.CHECK && event.item != null) {
+                TreeItem item = (TreeItem) event.item;
+                NodeContext ctx = (NodeContext)item.getData();
+                Object value = ctx.getConstant(BuiltinKeys.INPUT);
+
+                boolean checked = item.getChecked();
+
+                CommandContextMutable context = new CommandContextImpl();
+                context.putValue("event", "onCheck");
+                context.putValue("checked", checked);
+                context.putValue("item", value);
+
+                if (!data.isEmpty()) {
+                    ((SWTDocument)wd.document).handleCommands(data, context, event.widget);
+                }
+
+                CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onCheck", event.widget, context);
+            }
+            break;
+        }
+    }
+
+}
\ No newline at end of file
index 998be35727487003ea3ca1036557d0aa4b64a1f5..2a92068c77baf0eabf5aa2aecbe81a06941fbb48 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * 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.TreeMap;
@@ -7,7 +18,6 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.simantics.document.server.IEventCommand;
 import org.simantics.document.server.JSONObject;
 import org.simantics.document.server.client.WidgetData;
 import org.simantics.document.swt.core.SWTDocument;
@@ -29,23 +39,18 @@ public class FillComposite extends HasWidgetsWidgetManager<Composite> {
 //             result.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
                return result;
        }
-       
+
        @SuppressWarnings("unchecked")
        @Override
        public void updateChildren(SWTDocument document, JSONObject object, WidgetContainer widget, TreeMap<String, WidgetData> childMap) {
-               
+
                super.updateChildren(document, object, widget, childMap);
 
                WidgetData child = childMap.values().iterator().next();
                WidgetContainer container = (WidgetContainer)child.widget;
                if(container.getControl() == null) return;
                GridDataFactory.fillDefaults().grab(true, true).minSize(1, 1).applyTo((Control)container.getControl());
-               
-       }
-       
-       @Override
-       public IEventCommand eventCommand(SWTDocument document, JSONObject object, WidgetContainer widget, String command) {
-           return null;
+
        }
-       
+
 }
index ce2538c03e9eefb82aa9645c523a7cd6ec36c14b..199fc0f488b2087a20c7e092b063ae2e4490547e 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * 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 org.eclipse.jface.layout.GridLayoutFactory;
@@ -17,11 +28,11 @@ public class GridComposite extends HasWidgetsWidgetManager<Composite> {
 
        @Override
        protected Composite doCreateControl(SWTDocument document, Composite parent, JSONObject object) {
-               
+
                MarginsBean extendedMargins = object.getBeanJSONFieldDefault("extendedMargins", MarginsBean.BINDING, new MarginsBean(0, 0, 0, 0));
-               RGB.Integer background = object.getBeanJSONFieldDefault("background", RGB.Integer.BINDING, new RGB.Integer(255,0, 0));
+               RGB.Integer background = object.getBeanJSONFieldDefault("background", RGB.Integer.BINDING, new RGB.Integer(255, 255, 255));
                Integer numColumns = object.getJSONFieldDefault("numColumns", 1);
-               
+
                Composite result = new Composite(parent, SWT.NONE);
                GridLayoutFactory.fillDefaults().
                        numColumns(numColumns).
@@ -30,7 +41,7 @@ public class GridComposite extends HasWidgetsWidgetManager<Composite> {
                        applyTo(result);
                result.setBackground(document.getColor(background));
                return result;
-               
+
        }
-       
+
 }