From: Antti Villberg Date: Wed, 21 Aug 2019 12:46:28 +0000 (+0300) Subject: Improvements to modelled SWT documents X-Git-Tag: v1.43.0~136^2~101 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=e4ffdffae875e518a4eb070b8bda6ead1a9843d3;p=simantics%2Fplatform.git Improvements to modelled SWT documents gitlab #357 Change-Id: I281e90d871157775e1d9b789eb1a8886fb87bb17 --- diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java index 2f52153a1..d27eeaa79 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java @@ -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); diff --git a/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph b/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph index 4845558ea..230dc8786 100644 --- a/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph +++ b/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph @@ -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 = STR = SG = @@ -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 diff --git a/bundles/org.simantics.document.server/scl/Document/All.scl b/bundles/org.simantics.document.server/scl/Document/All.scl index a90a24bcb..d676e2a3b 100644 --- a/bundles/org.simantics.document.server/scl/Document/All.scl +++ b/bundles/org.simantics.document.server/scl/Document/All.scl @@ -122,9 +122,9 @@ importJava "org.simantics.document.server.Functions" where readEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> String) -> AbstractEventHandler eventHandler :: ((String -> Maybe String) -> String) -> AbstractEventHandler - readEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler - writeEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler - eventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler + readEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler + writeEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler + eventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler responseHandler :: Variable -> String -> AbstractEventHandler @@ -147,6 +147,9 @@ importJava "org.simantics.document.server.Functions" where compileDocumentSCLHandlerValueExpression :: Variable -> String primitiveProperties :: DocumentProperties + +contextVariable :: Variable -> Variable +contextVariable var = propertyValue (variableParent var) "input" propertyValueCached :: Serializable a => Typeable a => Variable -> String -> a propertyValueCached var prop = propertyValueCached_ var prop binding diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java index b971fef4c..c10dafc2d 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java @@ -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); } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java index f47c0c5c3..eabb2afdd 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java @@ -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; diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java index 1235d527c..2fb138fde 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java @@ -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; } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java index 8474bfd15..ab0b8cf87 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java @@ -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 { public W createWidget(JSONObject object); public void updateProperties(D document, JSONObject object, W widget); - + public void updateChildren(D document, JSONObject object, W widget, TreeMap 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 diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java index 41183050f..1e97e2277 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java @@ -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 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> data, CommandContextMutable context, Object component); void layout(); - + void displayError(String error); - + } diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java index 58c280595..e2a64ee1d 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java @@ -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 objects) { assert thread.currentThreadAccess(); @@ -115,9 +133,9 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument { @Override protected void updateTree(HashSet 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> data, CommandContextMutable context, Object component) { + + // Build a linked list of commands + + ArrayList commands = new ArrayList<>(); + for(Pair 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 getWidgetData() { return widgetData; } - + public void displayError(String error) { Logger.defaultLogError(error); } - + } diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java index 468bf7bda..3ea5da8a6 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java @@ -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> getTriggeredCommands(Document document, Collection commands, String trigger) { + // Nulls should not get this far + assert(commands != null); + List> 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(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 encoded = new HashMap(); - + 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); } - + } diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java index 3bd0364e7..57a2fbbe8 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java @@ -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 diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java index ff6d4fd13..7214bdd1f 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java @@ -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 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 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 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 diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java index 1c3297061..f48111671 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java @@ -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 implements WidgetManager { - + @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 commands = JSONObjectUtils.getCommands(wd.object); + + if(context == null) context = new CommandContextImpl(); + context.putValue("event", event); + + List> data = SWTViews.getTriggeredCommands(document, commands, "eventOut"); + + return document.handleCommands(data, context, wd.widget); } -} +} \ No newline at end of file diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java index 303460dea..453d1d0a7 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java @@ -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 data; - - public ButtonSelectionListener(LinkedHashMap data) { + + private WidgetData wd; + private List> data; + + public ButtonSelectionListener(WidgetData wd, List> 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 commands = new ArrayList(); - 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 diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java index 384ef88cd..72c7c360b 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java @@ -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