-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabindingUtil.java
103 lines (95 loc) · 3.52 KB
/
DatabindingUtil.java
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
/*******************************************************************************
* Copyright (c) 2015, 2022 Lorenzo Bettini and others.
* 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
*
* Lorenzo Bettini - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.parsley.util;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;
/**
* A utility class with methods for databinding that have the same signatures of
* the deprecated ones and use the new {@link WidgetProperties} methods.
*
* This is useful in the DSL since it will be easier to implement target
* observable specifications.
*
* @author Lorenzo Bettini - initial API and implementation
*
*/
public class DatabindingUtil {
protected DatabindingUtil() {
}
/**
* Returns an observable observing the text attribute of the provided
* <code>control</code>. The supported types are:
* <ul>
* <li>org.eclipse.swt.widgets.Text</li>
* <li>org.eclipse.swt.custom.StyledText (as of 1.3)</li>
* </ul>
*
* @param control
* @param event
* event type to register for change events
* @return observable value
* @throws IllegalArgumentException
* if <code>control</code> type is unsupported
*/
@SuppressWarnings({ "rawtypes" })
public static ISWTObservableValue observeText(Control control, int event) {
return WidgetProperties.text(event).observe(control);
}
/**
* Returns an observable observing the text attribute of the provided
* <code>widget</code>. The supported types are:
* <ul>
* <li>org.eclipse.swt.widgets.Button (as of 1.3)</li>
* <li>org.eclipse.swt.custom.CCombo</li>
* <li>org.eclipse.swt.custom.CLabel</li>
* <li>org.eclipse.swt.widgets.Combo</li>
* <li>org.eclipse.swt.widgets.Group (as of 1.7)</li>
* <li>org.eclipse.swt.widgets.Item</li>
* <li>org.eclipse.swt.widgets.Label</li>
* <li>org.eclipse.swt.widgets.Link (as of 1.2)</li>
* <li>org.eclipse.swt.widgets.Shell</li>
* <li>org.eclipse.swt.widgets.StyledText (as of 1.3)</li>
* <li>org.eclipse.swt.widgets.Text (as of 1.3)</li>
* </ul>
*
* @param widget
* @return observable value
* @throws IllegalArgumentException
* if the type of <code>widget</code> is unsupported
*/
@SuppressWarnings({ "rawtypes" })
public static ISWTObservableValue observeText(Widget widget) {
return WidgetProperties.text().observe(widget);
}
/**
* Returns an observable observing the selection attribute of the provided
* <code>control</code>. The supported types are:
* <ul>
* <li>org.eclipse.swt.widgets.Spinner</li>
* <li>org.eclipse.swt.widgets.Button</li>
* <li>org.eclipse.swt.widgets.Combo</li>
* <li>org.eclipse.swt.custom.CCombo</li>
* <li>org.eclipse.swt.widgets.List</li>
* <li>org.eclipse.swt.widgets.MenuItem (since 1.5)</li>
* <li>org.eclipse.swt.widgets.Scale</li>
* </ul>
*
* @param widget
* @return observable value
* @throws IllegalArgumentException
* if <code>control</code> type is unsupported
*/
@SuppressWarnings({ "rawtypes" })
public static ISWTObservableValue observeSelection(Widget widget) {
return WidgetProperties.widgetSelection().observe(widget);
}
}