blob: ba8ab1b4318eae084f862f02c90f5299675e1ffa (
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
|
package org.eclipse.fx.ecp.ui.controls;
import javafx.scene.control.Control;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
public abstract class ECPControlBase extends Control {
protected final EObject modelElement;
protected final EStructuralFeature feature;
protected final EditingDomain editingDomain;
protected final IItemPropertyDescriptor propertyDescriptor;
protected final Adapter modelElementAdapter;
public ECPControlBase(IItemPropertyDescriptor propertyDescriptor, EObject modelElement, EditingDomain editingDomain) {
this.modelElement = modelElement;
this.feature = (EStructuralFeature) propertyDescriptor.getFeature(modelElement);
this.editingDomain = editingDomain;
this.propertyDescriptor = propertyDescriptor;
modelElementAdapter = createModelElementAdapter();
modelElement.eAdapters().add(modelElementAdapter);
}
protected Adapter createModelElementAdapter() {
return new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
if (msg.getFeature() == feature)
update();
}
};
}
protected abstract void update();
public void dispose() {
modelElement.eAdapters().remove(modelElementAdapter);
}
}
|