Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2e89c1fde3a7dd0ff30beb3d75267eca0c141d9d (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
/*******************************************************************************
 * Copyright (c) 2008 Matthew Hall 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
 *
 * Contributors:
 *     Matthew Hall - initial API and implementation (bug 194734)
 *     Matthew Hall - bugs 256543, 262287
 ******************************************************************************/

package org.eclipse.jface.internal.databinding.swt;

import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;

/**
 * @since 3.3
 * 
 */
public class TextTextProperty extends WidgetStringValueProperty {
	/**
	 * 
	 */
	public TextTextProperty() {
		this(null);
	}

	/**
	 * @param events
	 */
	public TextTextProperty(int[] events) {
		super(checkEvents(events), staleEvents(events));
	}

	private static int[] checkEvents(int[] events) {
		if (events != null)
			for (int i = 0; i < events.length; i++)
				checkEvent(events[i]);
		return events;
	}

	private static void checkEvent(int event) {
		if (event != SWT.None && event != SWT.Modify && event != SWT.FocusOut
				&& event != SWT.DefaultSelection)
			throw new IllegalArgumentException("UpdateEventType [" //$NON-NLS-1$
					+ event + "] is not supported."); //$NON-NLS-1$
	}

	private static int[] staleEvents(int[] changeEvents) {
		if (changeEvents != null)
			for (int i = 0; i < changeEvents.length; i++)
				if (changeEvents[i] == SWT.Modify)
					return null;
		return new int[] { SWT.Modify };
	}

	String doGetStringValue(Object source) {
		return ((Text) source).getText();
	}

	void doSetStringValue(Object source, String value) {
		((Text) source).setText(value == null ? "" : value); //$NON-NLS-1$
	}

	public String toString() {
		return "Text.text <String>"; //$NON-NLS-1$
	}

	protected ISWTObservableValue wrapObservable(IObservableValue observable,
			Widget widget) {
		return new SWTVetoableValueDecorator(widget, this, observable);
	}
}

Back to the top