package org.simantics.document.swt.core.widget;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
+import java.util.List;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.simantics.document.server.IEventCommand;
import org.simantics.document.server.client.WidgetData;
+import org.simantics.document.server.io.CommandContext;
+import org.simantics.document.server.io.CommandContextImpl;
+import org.simantics.document.server.io.CommandContextMutable;
+import org.simantics.document.server.io.ICommand;
import org.simantics.document.swt.core.SWTDocument;
+import org.simantics.document.swt.core.base.PropertyWidgetManager;
+import org.simantics.utils.datastructures.Pair;
public class ButtonSelectionListener implements SelectionListener {
- private LinkedHashMap<WidgetData, String> data;
+ private WidgetData wd;
+ private List<Pair<WidgetData, ICommand>> data;
- public ButtonSelectionListener(LinkedHashMap<WidgetData, String> data) {
+ public ButtonSelectionListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
+ this.wd = wd;
this.data = data;
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
- SWTDocument document = null;
- // Build a linked list of commands
- ArrayList<IEventCommand> commands = new ArrayList<IEventCommand>();
- for(WidgetData d : data.keySet()) {
- document = (SWTDocument)d.document; // assume that all widgets are from the same document
- IEventCommand p = d.eventCommand(data.get(d));
- if(p != null) {
- if(!commands.isEmpty())
- commands.get(commands.size()-1).setNext(p);
- commands.add(p);
+// SWTDocument document = null;
+// // Build a linked list of commands
+// ArrayList<IEventCommand> commands = new ArrayList<IEventCommand>();
+// for(WidgetData d : data.keySet()) {
+// document = (SWTDocument)d.document; // assume that all widgets are from the same document
+// IEventCommand p = d.eventCommand(data.get(d));
+// if(p != null) {
+// if(!commands.isEmpty())
+// commands.get(commands.size()-1).setNext(p);
+// commands.add(p);
+// }
+
+ CommandContextMutable context = new CommandContextImpl();
+ context.putValue("event", "onPress");
+
+ if(!data.isEmpty()) {
+ ((SWTDocument)wd.document).handleCommands(data, context, e.widget);
}
- }
+
+ CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context);
+
+// }
// empty errors
// if(document != null)
// document.displayError("");
// Execute the first command, the linked list handles the rest of them
- if(!commands.isEmpty())
- commands.get(0).handleCommand();
-
+// if(!commands.isEmpty())
+// commands.get(0).handleCommand();
+//
}
}
\ No newline at end of file