78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Brad Reynolds - bug 164653
|
|
11 * Matt Carter - bug 170668
|
|
12 * Brad Reynolds - bug 170848
|
|
13 *******************************************************************************/
|
|
14 module org.eclipse.jface.internal.databinding.swt.ControlObservableValue;
|
85
|
15 import org.eclipse.jface.internal.databinding.swt.SWTProperties;
|
78
|
16
|
|
17 import java.lang.all;
|
|
18
|
|
19 import java.util.HashMap;
|
|
20 import java.util.Map;
|
|
21
|
|
22 import org.eclipse.core.databinding.observable.Diffs;
|
|
23 import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue;
|
|
24 import org.eclipse.swt.graphics.Color;
|
|
25 import org.eclipse.swt.graphics.Font;
|
|
26 import org.eclipse.swt.widgets.Control;
|
|
27
|
|
28 /**
|
|
29 * @since 1.0
|
|
30 *
|
|
31 */
|
|
32 public class ControlObservableValue : AbstractSWTObservableValue {
|
|
33
|
|
34 private final Control control;
|
|
35
|
|
36 private final String attribute;
|
|
37
|
|
38 private Object valueType;
|
|
39
|
|
40 private static Map SUPPORTED_ATTRIBUTES;
|
|
41 static this() {
|
|
42 SUPPORTED_ATTRIBUTES = new HashMap();
|
|
43 SUPPORTED_ATTRIBUTES.put(SWTProperties.ENABLED, Boolean.TYPE);
|
|
44 SUPPORTED_ATTRIBUTES.put(SWTProperties.VISIBLE, Boolean.TYPE);
|
85
|
45 SUPPORTED_ATTRIBUTES.put(SWTProperties.TOOLTIP_TEXT, Class.fromType!(String));
|
|
46 SUPPORTED_ATTRIBUTES.put(SWTProperties.FOREGROUND, Class.fromType!(Color));
|
|
47 SUPPORTED_ATTRIBUTES.put(SWTProperties.BACKGROUND, Class.fromType!(Color));
|
|
48 SUPPORTED_ATTRIBUTES.put(SWTProperties.FONT, Class.fromType!(Font));
|
78
|
49 }
|
|
50
|
|
51 /**
|
|
52 * @param control
|
|
53 * @param attribute
|
|
54 */
|
|
55 public this(Control control, String attribute) {
|
|
56 super(control);
|
|
57 this.control = control;
|
|
58 this.attribute = attribute;
|
|
59 if (SUPPORTED_ATTRIBUTES.keySet().contains(attribute)) {
|
|
60 this.valueType = SUPPORTED_ATTRIBUTES.get(attribute);
|
|
61 } else {
|
85
|
62 throw new IllegalArgumentException(null);
|
78
|
63 }
|
|
64 }
|
|
65
|
|
66 public void doSetValue(Object value) {
|
|
67 Object oldValue = doGetValue();
|
|
68 if (attribute.equals(SWTProperties.ENABLED)) {
|
|
69 control.setEnabled((cast(Boolean) value).booleanValue());
|
|
70 } else if (attribute.equals(SWTProperties.VISIBLE)) {
|
|
71 control.setVisible((cast(Boolean) value).booleanValue());
|
|
72 } else if (attribute.equals(SWTProperties.TOOLTIP_TEXT)) {
|
85
|
73 control.setToolTipText(stringcast(value));
|
78
|
74 } else if (attribute.equals(SWTProperties.FOREGROUND)) {
|
|
75 control.setForeground(cast(Color) value);
|
|
76 } else if (attribute.equals(SWTProperties.BACKGROUND)) {
|
|
77 control.setBackground(cast(Color) value);
|
|
78 } else if (attribute.equals(SWTProperties.FONT)) {
|
|
79 control.setFont(cast(Font) value);
|
|
80 }
|
|
81 fireValueChange(Diffs.createValueDiff(oldValue, value));
|
|
82 }
|
|
83
|
|
84 public Object doGetValue() {
|
|
85 if (attribute.equals(SWTProperties.ENABLED)) {
|
|
86 return control.getEnabled() ? Boolean.TRUE : Boolean.FALSE;
|
|
87 }
|
|
88 if (attribute.equals(SWTProperties.VISIBLE)) {
|
|
89 return control.getVisible() ? Boolean.TRUE : Boolean.FALSE;
|
|
90 }
|
|
91 if (attribute.equals(SWTProperties.TOOLTIP_TEXT)) {
|
85
|
92 return stringcast(control.getToolTipText());
|
78
|
93 }
|
|
94 if (attribute.equals(SWTProperties.FOREGROUND)) {
|
|
95 return control.getForeground();
|
|
96 }
|
|
97 if (attribute.equals(SWTProperties.BACKGROUND)) {
|
|
98 return control.getBackground();
|
|
99 }
|
|
100 if (attribute.equals(SWTProperties.FONT)) {
|
|
101 return control.getFont();
|
|
102 }
|
|
103
|
|
104 return null;
|
|
105 }
|
|
106
|
|
107 public Object getValueType() {
|
|
108 return valueType;
|
|
109 }
|
|
110 }
|