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.server.client;
14 import java.util.HashSet;
15 import java.util.TreeMap;
17 import org.simantics.document.server.IEventCommand;
18 import org.simantics.document.server.JSONObject;
19 import org.simantics.document.server.io.CommandContext;
20 import org.simantics.document.server.io.ICommand;
22 public class WidgetData {
25 public JSONObject object;
26 public Document document;
27 public TreeMap<String, WidgetData> childmap = new TreeMap<String, WidgetData>(new AlphanumericComparator());
28 public HashSet<Object> listenerRegistrations = new HashSet<Object>();
30 public WidgetData(Document document, Object widget, JSONObject object) {
33 this.document = document;
36 @SuppressWarnings({ "rawtypes" })
37 public Object createElement() {
40 WidgetManager manager = document.getManager(object);
41 return manager == null ? null : manager.createWidget(object);
44 @SuppressWarnings({ "unchecked", "rawtypes" })
45 public void updateChildren() {
46 if(object != null && widget != null && childmap != null) {
47 WidgetManager manager = document.getManager(object);
49 manager.updateChildren(document, object, widget, childmap);
53 @SuppressWarnings({ "unchecked", "rawtypes" })
54 public void updateProperties() {
57 WidgetManager manager = document.getManager(object);
59 manager.updateProperties(document, object, widget);
62 @SuppressWarnings({ "rawtypes", "unchecked" })
63 public void updateCommands() {
67 // Then create the updated registrations
68 CommandManager manager = document.getCommandManager(object);
70 // First remove all handler registrations
72 for(Object listener : listenerRegistrations) {
73 manager.removeListener(widget, listener);
76 listenerRegistrations.clear();
78 listenerRegistrations.addAll(manager.updateCommandListeners(document, object, widget));
82 @SuppressWarnings({ "unchecked", "rawtypes" })
83 public IEventCommand eventCommand(ICommand command, CommandContext c) {
86 WidgetManager manager = document.getManager(object);
88 return manager.eventCommand(document, object, widget, command, c);