1 /*******************************************************************************
2 * Copyright (c) 2019 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.document.swt.core.base;
14 import java.util.Collection;
15 import java.util.List;
17 import org.simantics.document.server.IEventCommand;
18 import org.simantics.document.server.JSONObject;
19 import org.simantics.document.server.client.WidgetData;
20 import org.simantics.document.server.client.WidgetManager;
21 import org.simantics.document.server.io.CommandContext;
22 import org.simantics.document.server.io.CommandContextImpl;
23 import org.simantics.document.server.io.CommandContextMutable;
24 import org.simantics.document.server.io.ICommand;
25 import org.simantics.document.server.io.JSONObjectUtils;
26 import org.simantics.document.swt.core.SWTDocument;
27 import org.simantics.document.swt.core.SWTViews;
28 import org.simantics.utils.datastructures.Pair;
30 public abstract class PropertyWidgetManager<W> implements WidgetManager<SWTDocument, W> {
33 public String getProperty(SWTDocument document, JSONObject object, W widget, String property) {
38 public IEventCommand eventCommand(SWTDocument document, JSONObject object, W widget, ICommand command, CommandContext context) {
42 public static CommandContext sendEvent(SWTDocument document, WidgetData wd, String event, Object target, CommandContextMutable context) {
43 Collection<ICommand> commands = JSONObjectUtils.getCommands(wd.object);
45 if(context == null) context = new CommandContextImpl();
46 context.putValue("event", event);
48 List<Pair<WidgetData, ICommand>> data = SWTViews.getTriggeredCommands(document, commands, "eventOut");
50 return document.handleCommands(data, context, wd.widget);