blob: 2acbe4200b05f56d2b222255994ecc1b824739f9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*******************************************************************************
* Copyright (c) 2016 Obeo.
* 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:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.eef.ide.ui.internal.widgets;
import com.google.common.base.Objects;
import org.eclipse.eef.EEFWidgetAction;
import org.eclipse.eef.EefPackage;
import org.eclipse.eef.common.ui.api.EEFWidgetFactory;
import org.eclipse.eef.core.api.utils.Eval;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* Represents an action button widget.
*
* @author mbats
*/
public class ActionButton {
/**
* The button.
*/
private Button button;
/**
* The button listener.
*/
private SelectionAdapter selectionListener;
/**
* The widget action.
*/
private EEFWidgetAction action;
/**
* The constructor.
*
* @param action
* Widget action
* @param parent
* Parent composite
* @param widgetFactory
* Widget factory
* @param interpreter
* Interpreter
* @param variableManager
* Variable manager
*
*/
public ActionButton(EEFWidgetAction action, Composite parent, EEFWidgetFactory widgetFactory, IInterpreter interpreter,
IVariableManager variableManager) {
this.action = action;
this.button = widgetFactory.createButton(parent, "", SWT.NONE); //$NON-NLS-1$
String expression = action.getLabelExpression();
EAttribute eAttribute = EefPackage.Literals.EEF_WIDGET_ACTION__LABEL_EXPRESSION;
String buttonLabel = Objects.firstNonNull(new Eval(interpreter, variableManager).get(eAttribute, expression, String.class), "..."); //$NON-NLS-1$
button.setText(buttonLabel);
}
/**
* Add a selection listener to the button.
*
* @param listener
* Selection listener
*/
public void addSelectionListener(SelectionAdapter listener) {
if (!button.isDisposed()) {
this.selectionListener = listener;
button.addSelectionListener(selectionListener);
}
}
/**
* Remove the selection listener.
*/
public void removeSelectionListener() {
if (!button.isDisposed()) {
button.removeSelectionListener(selectionListener);
}
}
/**
* Get the action.
*
* @return the action.
*/
public EEFWidgetAction getAction() {
return action;
}
/**
* Get the button.
*
* @return The button
*/
public Control getButton() {
return button;
}
}
|