1 package org.simantics.document.swt.core.widget;
5 import org.eclipse.swt.events.SelectionEvent;
6 import org.eclipse.swt.events.SelectionListener;
7 import org.simantics.document.server.client.WidgetData;
8 import org.simantics.document.server.io.CommandContext;
9 import org.simantics.document.server.io.CommandContextImpl;
10 import org.simantics.document.server.io.CommandContextMutable;
11 import org.simantics.document.server.io.ICommand;
12 import org.simantics.document.swt.core.SWTDocument;
13 import org.simantics.document.swt.core.base.PropertyWidgetManager;
14 import org.simantics.utils.datastructures.Pair;
16 public class ButtonSelectionListener implements SelectionListener {
18 private WidgetData wd;
19 private List<Pair<WidgetData, ICommand>> data;
21 public ButtonSelectionListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
27 public void widgetSelected(SelectionEvent e) {
28 widgetDefaultSelected(e);
32 public void widgetDefaultSelected(SelectionEvent e) {
33 // SWTDocument document = null;
34 // // Build a linked list of commands
35 // ArrayList<IEventCommand> commands = new ArrayList<IEventCommand>();
36 // for(WidgetData d : data.keySet()) {
37 // document = (SWTDocument)d.document; // assume that all widgets are from the same document
38 // IEventCommand p = d.eventCommand(data.get(d));
40 // if(!commands.isEmpty())
41 // commands.get(commands.size()-1).setNext(p);
45 CommandContextMutable context = new CommandContextImpl();
46 context.putValue("event", "onPress");
49 ((SWTDocument)wd.document).handleCommands(data, context, e.widget);
52 CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context);
57 // if(document != null)
58 // document.displayError("");
60 // Execute the first command, the linked list handles the rest of them
61 // if(!commands.isEmpty())
62 // commands.get(0).handleCommand();