-
Notifications
You must be signed in to change notification settings - Fork 155
/
SingleSelectionProperty.java
51 lines (44 loc) · 1.52 KB
/
SingleSelectionProperty.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
package org.eclipse.ui.internal.databinding;
import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
public class SingleSelectionProperty<S extends ISelectionService, T> extends SimpleValueProperty<S, T> {
private final String partId;
private final boolean post;
private final Object elementType;
public SingleSelectionProperty(String partId, boolean post, Object elementType) {
this.partId = partId;
this.post = post;
this.elementType = elementType;
}
@Override
public INativePropertyListener<S> adaptListener(ISimplePropertyListener<S, ValueDiff<? extends T>> listener) {
return new SelectionServiceListener<>(this, listener, partId, post);
}
@Override
protected T doGetValue(S source) {
ISelection selection;
if (partId != null) {
selection = source.getSelection(partId);
} else {
selection = source.getSelection();
}
if (selection instanceof IStructuredSelection) {
T elem = (T) ((IStructuredSelection) selection).getFirstElement();
return elem;
}
return null;
}
@Override
protected void doSetValue(S source, T value) {
throw new UnsupportedOperationException();
}
@Override
public Object getValueType() {
return elementType;
}
}