X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.swt.core%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fswt%2Fcore%2Fwidget%2FButtonSelectionListener.java;h=453d1d0a7261d1c80ba0688475490f25e65730cc;hp=303460deab8fc6b1474887e4bc73c0453a08d7e5;hb=e4ffdffae875e518a4eb070b8bda6ead1a9843d3;hpb=158d6269660a3b415504f1da5a0b8341e761a5be diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java index 303460dea..453d1d0a7 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java @@ -1,19 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2019 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ 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.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 data; - - public ButtonSelectionListener(LinkedHashMap data) { + + private WidgetData wd; + private List> data; + + public ButtonSelectionListener(WidgetData wd, List> data) { + this.wd = wd; this.data = data; } @@ -24,27 +40,16 @@ public class ButtonSelectionListener implements SelectionListener { @Override public void widgetDefaultSelected(SelectionEvent e) { - SWTDocument document = null; - // Build a linked list of commands - ArrayList commands = new ArrayList(); - 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); } - // empty errors -// if(document != null) -// document.displayError(""); + PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context); - // Execute the first command, the linked list handles the rest of them - if(!commands.isEmpty()) - commands.get(0).handleCommand(); - } - + } \ No newline at end of file