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