X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.swt.core%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fswt%2Fcore%2FSWTViews.java;h=3ea5da8a6d76ecfd3762a3133eb4d8e7c2d087b4;hb=refs%2Fchanges%2F40%2F3140%2F5;hp=468bf7bdaec4295d561e25b2f32e1212dcc06eef;hpb=158d6269660a3b415504f1da5a0b8341e761a5be;p=simantics%2Fplatform.git 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); } - + }