]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java
Improvements to modelled SWT documents
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / ButtonSelectionListener.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.document.swt.core.widget;
13
14 import java.util.List;
15
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.events.SelectionListener;
18 import org.simantics.document.server.client.WidgetData;
19 import org.simantics.document.server.io.CommandContextImpl;
20 import org.simantics.document.server.io.CommandContextMutable;
21 import org.simantics.document.server.io.ICommand;
22 import org.simantics.document.swt.core.SWTDocument;
23 import org.simantics.document.swt.core.base.PropertyWidgetManager;
24 import org.simantics.utils.datastructures.Pair;
25
26 public class ButtonSelectionListener implements SelectionListener {
27
28     private WidgetData wd;
29     private List<Pair<WidgetData, ICommand>> data;
30
31     public ButtonSelectionListener(WidgetData wd, List<Pair<WidgetData, ICommand>> data) {
32         this.wd = wd;
33         this.data = data;
34     }
35
36     @Override
37     public void widgetSelected(SelectionEvent e) {
38         widgetDefaultSelected(e);
39     }
40
41     @Override
42     public void widgetDefaultSelected(SelectionEvent e) {
43
44         CommandContextMutable context = new CommandContextImpl();
45         context.putValue("event", "onPress");
46
47         if(!data.isEmpty()) {
48             ((SWTDocument)wd.document).handleCommands(data, context, e.widget);
49         }
50
51         PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context);
52
53     }
54
55 }