]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java
Playground for Antti.
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / ButtonSelectionListener.java
1 package org.simantics.document.swt.core.widget;
2
3 import java.util.List;
4
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;
15
16 public class ButtonSelectionListener implements SelectionListener {
17     
18     private WidgetData wd;
19     private List<Pair<WidgetData, ICommand>> data;
20     
21     public ButtonSelectionListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
22         this.wd = wd;
23         this.data = data;
24     }
25
26     @Override
27     public void widgetSelected(SelectionEvent e) {
28         widgetDefaultSelected(e);
29     }
30
31     @Override
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));
39 //            if(p != null) {
40 //                if(!commands.isEmpty())
41 //                    commands.get(commands.size()-1).setNext(p);
42 //                commands.add(p);
43 //            }
44             
45             CommandContextMutable context = new CommandContextImpl();
46             context.putValue("event", "onPress");
47             
48             if(!data.isEmpty()) {
49                 ((SWTDocument)wd.document).handleCommands(data, context, e.widget);
50             }
51             
52             CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context);
53
54 //        }
55
56         // empty errors
57 //        if(document != null)
58 //            document.displayError("");
59
60         // Execute the first command, the linked list handles the rest of them
61 //        if(!commands.isEmpty())
62 //            commands.get(0).handleCommand();
63 //    
64     }
65     
66 }