((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);
+/*******************************************************************************
+ * 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>
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
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
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
+/*******************************************************************************
+ * 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);
}
+/*******************************************************************************
+ * 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;
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;
+/*******************************************************************************
+ * 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;
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 {
}
@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;
}
+/*******************************************************************************
+ * 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
+/*******************************************************************************
+ * 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;
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);
-
+
}
+/*******************************************************************************
+ * 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;
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;
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;
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);
}
return color;
}
-
+
@Override
public Font getFont(org.simantics.datatypes.literal.Font descriptor) {
Font font = fonts.get(descriptor);
}
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();
@Override
protected void updateTree(HashSet<WidgetData> updates) {
-
+
if(updates.isEmpty()) return;
-
+
for(WidgetData data : updates) {
WidgetContainer<?> container = (WidgetContainer<?>)data.widget;
Control ctrl = container.getControl();
}
}
}
-
+
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);
}
-
+
}
+/*******************************************************************************
+ * 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;
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;
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());
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) {
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);
}
-
+
}
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 {
}
@Override
- public void commandSuccess() {
+ public CommandContext commandSuccess(CommandContextMutable context) {
if(next != null)
- next.handleCommand();
+ return next.handleCommand(context);
+ return context;
}
@Override
+/*******************************************************************************
+ * 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
+/*******************************************************************************
+ * 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
+/*******************************************************************************
+ * 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;
}
@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
+/*******************************************************************************
+ * 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;
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> {
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);
}
@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;
}
+/*******************************************************************************
+ * 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;
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;
}
@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) {
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;
}
+/*******************************************************************************
+ * 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;
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;
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> {
}
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;
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();
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)
control.setDragSourceListenerFactory(dragSourceListenerFactory);
if(displayHeader != null)
tree.setHeaderVisible(displayHeader);
-
+
control.setStatePersistor(persistor);
control.finish();
-
+
control.setInputSource(new InputSourceImpl<Object>() {
@Override
}
});
-
+
// TODO: fixme!
Object i = object.getJSONField("explorerInput");
if(i instanceof VariableBean) {
} 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) {
}
- });
+ });
return control;
}
-
+
@Override
public String getProperty(SWTDocument document, JSONObject object, WidgetContainer<ModelBrowser> widget, String property) {
if("selection".equals(property)) {
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;
+ }
+
}
--- /dev/null
+/*******************************************************************************
+ * 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
+/*******************************************************************************
+ * 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;
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;
// 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;
+
}
-
+
}
+/*******************************************************************************
+ * 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;
@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).
applyTo(result);
result.setBackground(document.getColor(background));
return result;
-
+
}
-
+
}