blob: 97969594261882a27beffb3f42a7356d97b1c5ec (
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
|
/*****************************************************************************
* Copyright (c) 2010, 2016 CEA LIST, Christian W. Damus, and others.
*
* 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
* Christian W. Damus - bug 485220
*
*****************************************************************************/
package org.eclipse.papyrus.customization.properties.providers;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.customization.properties.Activator;
import org.eclipse.papyrus.infra.properties.contexts.Context;
import org.eclipse.papyrus.infra.properties.ui.util.PropertiesUtil;
import org.eclipse.papyrus.infra.tools.util.ListHelper;
import org.eclipse.papyrus.infra.ui.emf.providers.strategy.SemanticEMFContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
/**
* An abstract implementation of {@link IStaticContentProvider} for
* content providers which rely on the available {@link Context}s
* to retrieve their elements.
*
* @author Camille Letavernier
*
*/
public abstract class AbstractContextualContentProvider extends SemanticEMFContentProvider implements IStaticContentProvider {
/**
* The list of available contexts in the current model
*/
protected Collection<Context> contexts;
/**
*
* Constructor.
*
* @param source
* The EObject used to retrieve the available contexts
*/
protected AbstractContextualContentProvider(EObject source) {
super(findContexts(source).toArray(new Context[0]), Activator.getDefault().getCustomizationManager());
contexts = ListHelper.asList((Context[]) roots);
}
private static List<Context> findContexts(EObject source) {
List<Context> contexts = new LinkedList<>();
Context rootContext = null;
if (source.eResource() != null) {
for (Resource resource : source.eResource().getResourceSet().getResources()) {
if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof Context) {
rootContext = (Context) resource.getContents().get(0);
contexts.add(rootContext);
break;
}
}
}
return PropertiesUtil.getDependencies(rootContext);
}
}
|