]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java
Improvements to modelled SWT documents
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / base / PropertyWidgetManager.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.document.swt.core.base;
13
14 import java.util.Collection;
15 import java.util.List;
16
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;
29
30 public abstract class PropertyWidgetManager<W> implements WidgetManager<SWTDocument, W> {
31
32         @Override
33         public String getProperty(SWTDocument document, JSONObject object, W widget, String property) {
34                 return null;
35         }
36
37         @Override
38         public IEventCommand eventCommand(SWTDocument document, JSONObject object, W widget, ICommand command, CommandContext context) {
39                 return null;
40         }
41
42         public static CommandContext sendEvent(SWTDocument document, WidgetData wd, String event, Object target, CommandContextMutable context) {
43                 Collection<ICommand> commands = JSONObjectUtils.getCommands(wd.object);
44
45                 if(context == null) context = new CommandContextImpl();
46                 context.putValue("event", event);
47
48                 List<Pair<WidgetData, ICommand>> data = SWTViews.getTriggeredCommands(document, commands, "eventOut");
49
50                 return document.handleCommands(data, context, wd.widget);
51         }
52
53 }