1 package org.simantics.document.swt.core.widget;
3 import java.util.ArrayList;
4 import java.util.LinkedHashMap;
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;
12 public class ButtonSelectionListener implements SelectionListener {
14 private LinkedHashMap<WidgetData, String> data;
16 public ButtonSelectionListener(LinkedHashMap<WidgetData, String> data) {
21 public void widgetSelected(SelectionEvent e) {
22 widgetDefaultSelected(e);
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));
34 if(!commands.isEmpty())
35 commands.get(commands.size()-1).setNext(p);
41 // if(document != null)
42 // document.displayError("");
44 // Execute the first command, the linked list handles the rest of them
45 if(!commands.isEmpty())
46 commands.get(0).handleCommand();