]> gerrit.simantics Code Review - simantics/platform.git/blob
303460deab8fc6b1474887e4bc73c0453a08d7e5
[simantics/platform.git] /
1 package org.simantics.document.swt.core.widget;
2
3 import java.util.ArrayList;
4 import java.util.LinkedHashMap;
5
6 import org.eclipse.swt.events.SelectionEvent;
7 import org.eclipse.swt.events.SelectionListener;
8 import org.simantics.document.server.IEventCommand;
9 import org.simantics.document.server.client.WidgetData;
10 import org.simantics.document.swt.core.SWTDocument;
11
12 public class ButtonSelectionListener implements SelectionListener {
13     
14     private LinkedHashMap<WidgetData, String> data;
15     
16     public ButtonSelectionListener(LinkedHashMap<WidgetData, String> data) {
17         this.data = data;
18     }
19
20     @Override
21     public void widgetSelected(SelectionEvent e) {
22         widgetDefaultSelected(e);
23     }
24
25     @Override
26     public void widgetDefaultSelected(SelectionEvent e) {
27         SWTDocument document = null;
28         // Build a linked list of commands
29         ArrayList<IEventCommand> commands = new ArrayList<IEventCommand>();
30         for(WidgetData d : data.keySet()) {
31             document = (SWTDocument)d.document; // assume that all widgets are from the same document
32             IEventCommand p = d.eventCommand(data.get(d));
33             if(p != null) {
34                 if(!commands.isEmpty())
35                     commands.get(commands.size()-1).setNext(p);
36                 commands.add(p);
37             }
38         }
39
40         // empty errors
41 //        if(document != null)
42 //            document.displayError("");
43
44         // Execute the first command, the linked list handles the rest of them
45         if(!commands.isEmpty())
46             commands.get(0).handleCommand();
47     
48     }
49     
50 }