]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ExplorerListener.java
Playground for Antti.
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / ExplorerListener.java
1 package org.simantics.document.swt.core.widget;
2
3 import java.util.List;
4
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.Event;
7 import org.eclipse.swt.widgets.Listener;
8 import org.eclipse.swt.widgets.TreeItem;
9 import org.simantics.browsing.ui.BuiltinKeys;
10 import org.simantics.browsing.ui.NodeContext;
11 import org.simantics.document.server.client.WidgetData;
12 import org.simantics.document.server.io.CommandContext;
13 import org.simantics.document.server.io.CommandContextImpl;
14 import org.simantics.document.server.io.CommandContextMutable;
15 import org.simantics.document.server.io.ICommand;
16 import org.simantics.document.swt.core.SWTDocument;
17 import org.simantics.document.swt.core.base.PropertyWidgetManager;
18 import org.simantics.utils.datastructures.Pair;
19
20 public class ExplorerListener implements Listener {
21     
22     private WidgetData wd;
23     private List<Pair<WidgetData, ICommand>> data;
24     
25     public ExplorerListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
26         this.wd = wd;
27         this.data = data;
28     }
29
30     @Override
31     public void handleEvent(Event event) {
32         
33         switch (event.type) {
34         case SWT.Selection:
35             if (event.detail == SWT.CHECK && event.item != null) {
36
37                 TreeItem item = (TreeItem) event.item;
38                 NodeContext ctx = (NodeContext)item.getData();
39                 Object value = ctx.getConstant(BuiltinKeys.INPUT);
40                 
41                 boolean checked = item.getChecked();
42
43                 CommandContextMutable context = new CommandContextImpl();
44                 context.putValue("event", "onCheck");
45                 context.putValue("checked", checked);
46                 context.putValue("item", value);
47
48                 if(!data.isEmpty()) {
49                     ((SWTDocument)wd.document).handleCommands(data, context, event.widget);
50                 }
51                 
52                 CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onCheck", event.widget, context);
53
54             }
55             break;
56         }
57
58     }
59     
60 }