blob: 7a6eb78f70672c8462aced501105f7ea7299ac34 (
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
114
115
116
117
118
119
120
121
|
/*****************************************************************************
* Copyright (c) 2013 CEA LIST.
*
*
* 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:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.databinding;
import java.util.List;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.papyrus.infra.widgets.util.IPapyrusConverter;
import org.eclipse.papyrus.infra.widgets.util.ISetPapyrusConverter;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Event;
public class CompletionStyledTextObservableValue extends StyledTextObservableValue implements ISetPapyrusConverter {
/**
* The name resolution helper shared with the widget
*/
protected IPapyrusConverter parser;
/**
*
* Constructor.
*
* @param text
* @param modelProperty
* @param eventType
*/
public CompletionStyledTextObservableValue(StyledText text, IObservableValue modelProperty, int eventType) {
super(text, modelProperty, eventType);
}
/**
*
* @see org.eclipse.papyrus.infra.widgets.databinding.StyledTextObservableValue#doSetValue(java.lang.Object)
*
* @param value
*/
@Override
protected void doSetValue(Object value) {
String editValue = parser.canonicalToEditValue(value, 0);
if (editValue instanceof String) {
super.doSetValue(editValue);
} else {
super.doSetValue(value);
}
}
/**
*
* @see org.eclipse.papyrus.infra.widgets.databinding.StyledTextObservableValue#doGetValue()
*
* @return²
*/
@Override
protected Object doGetValue() {
Object newValue = super.doGetValue();
if (newValue instanceof String) {
if (IPapyrusConverter.UNDEFINED_VALUE.equals(newValue)) {
return null;
}
Object result = this.parser.editToCanonicalValue((String) newValue, 0);
return result;
}
return null;
}
/**
* @see org.eclipse.papyrus.infra.widgets.util.ISetPapyrusConverter#setPapyrusConverter(org.eclipse.papyrus.infra.widgets.util.IPapyrusConverter)
*
* @param parser
*/
@Override
public void setPapyrusConverter(IPapyrusConverter parser) {
this.parser = parser;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
@Override
public void handleEvent(final Event event) {
final Object oldValue = currentValue;
final Object newValue = getValue();
// if (newValue == null) {
// return;
// }
currentValue = newValue;
if ((eventType & event.type) != 0) {
fireValueChange(new ValueDiff() {
@Override
public Object getOldValue() {
return oldValue;
}
@Override
public Object getNewValue() {
return newValue;
}
});
}
}
}
|