blob: 353173db0cbdf9118abfe8ff04e383db9b79eefe (
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
|
/*****************************************************************************
* 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.providers;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.ui.emf.providers.strategy.SemanticEMFContentProvider;
public class ContainerContentProvider extends SemanticEMFContentProvider {
protected EClass type;
protected Object input;
public ContainerContentProvider(EObject source, EReference reference) {
super(source.eResource().getResourceSet());
type = (EClass) reference.getEType();
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
super.inputChanged(viewer, oldInput, newInput);
this.input = newInput;
if (newInput instanceof EObject) {
this.type = ((EObject) newInput).eClass();
}
}
@Override
public boolean isValidValue(Object value) {
Object adaptedValue = getAdaptedValue(value);
if (adaptedValue instanceof EObject) {
// We cannot create objects in a read-only object
if (EMFHelper.isReadOnly((EObject) adaptedValue)) {
return false;
}
// We need at least one valid containment reference to store this
// type of object
for (EReference reference : ((EObject) adaptedValue).eClass().getEAllReferences()) {
if (reference.isContainment() && EMFHelper.isSubclass(this.type, reference.getEReferenceType())) {
return true;
}
}
}
return false;
}
}
|