]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java
Playground for Antti.
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / SWTDocumentClient.java
index 58c280595b0ac8fd31de57ca3d5cd6a45fdbaebd..090448db5d6a1e43eaf606589a337ef174bb5c8c 100644 (file)
@@ -1,8 +1,10 @@
 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 +17,21 @@ 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.server.io.JSONObjectUtils;
 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;
 
@@ -99,9 +106,10 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
        }
        
        @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) {
@@ -141,6 +149,36 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument {
                
        }
        
+       @Override
+       public CommandContext handleCommands(List<Pair<WidgetData, ICommand>> data, CommandContextMutable context, Object component) {   
+
+           // Build a linked list of commands
+
+           ArrayList<IEventCommand> commands = new ArrayList<IEventCommand>();
+           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;