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.widget;
14 import java.util.List;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Event;
18 import org.eclipse.swt.widgets.Listener;
19 import org.eclipse.swt.widgets.TreeItem;
20 import org.simantics.browsing.ui.BuiltinKeys;
21 import org.simantics.browsing.ui.NodeContext;
22 import org.simantics.document.server.client.WidgetData;
23 import org.simantics.document.server.io.CommandContext;
24 import org.simantics.document.server.io.CommandContextImpl;
25 import org.simantics.document.server.io.CommandContextMutable;
26 import org.simantics.document.server.io.ICommand;
27 import org.simantics.document.swt.core.SWTDocument;
28 import org.simantics.document.swt.core.base.PropertyWidgetManager;
29 import org.simantics.utils.datastructures.Pair;
31 public class ExplorerListener implements Listener {
33 private WidgetData wd;
34 private List<Pair<WidgetData, ICommand>> data;
36 public ExplorerListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
42 public void handleEvent(Event event) {
45 if (event.detail == SWT.CHECK && event.item != null) {
46 TreeItem item = (TreeItem) event.item;
47 NodeContext ctx = (NodeContext)item.getData();
48 Object value = ctx.getConstant(BuiltinKeys.INPUT);
50 boolean checked = item.getChecked();
52 CommandContextMutable context = new CommandContextImpl();
53 context.putValue("event", "onCheck");
54 context.putValue("checked", checked);
55 context.putValue("item", value);
57 if (!data.isEmpty()) {
58 ((SWTDocument)wd.document).handleCommands(data, context, event.widget);
61 CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onCheck", event.widget, context);