blob: c5d0a8f1628a5f2c80284df40d1d62effa8efe7d (
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
122
123
|
/*****************************************************************************
* Copyright (c) 2011 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.views.properties.modelelement;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.views.properties.creation.PropertyEditorFactory;
/**
* Provides a default implementation for ModelElement methods applied on the
* modelElement's properties.
*
* @author Camille Letavernier
*/
public abstract class AbstractModelElement implements ModelElement {
/**
* The DataSource owning this ModelElement
*/
protected DataSource dataSource;
private final Map<String, IObservable> observables = new HashMap<String, IObservable>();
/**
* Constructor.
*/
protected AbstractModelElement() {
}
public IStaticContentProvider getContentProvider(String propertyPath) {
return EmptyContentProvider.instance;
}
public ILabelProvider getLabelProvider(String propertyPath) {
return null;
}
public boolean isOrdered(String propertyPath) {
return true;
}
public boolean isUnique(String propertyPath) {
return false;
}
public boolean isMandatory(String propertyPath) {
return false;
}
public boolean isEditable(String propertyPath) {
return true;
}
public boolean forceRefresh(String propertyPath) {
return false;
}
public void setDataSource(DataSource source) {
this.dataSource = source;
}
/**
* @see org.eclipse.papyrus.views.properties.modelelement.ModelElement#getValueFactory(java.lang.String)
*
* @param propertyPath
* @return a default factory based on the property view configuration to
* edit objects, as if they were selected in an editor
*/
public ReferenceValueFactory getValueFactory(String propertyPath) {
return new PropertyEditorFactory();
}
public Object getDefaultValue(String propertyPath) {
return null;
}
public boolean getDirectCreation(String propertyPath) {
return false;
}
public final IObservable getObservable(String propertyPath) {
if(!observables.containsKey(propertyPath)) {
IObservable observable = doGetObservable(propertyPath);
if(observable != null) {
observables.put(propertyPath, observable);
}
}
return observables.get(propertyPath);
}
/**
* Creates the IObservable for the given propertyPath
*
* @param propertyPath
* The path of the property we want to observe
* @return
* The new IObservable
*/
protected abstract IObservable doGetObservable(String propertyPath);
public void dispose() {
for(IObservable observable : observables.values()) {
observable.dispose();
}
observables.clear();
}
}
|