Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7dd29503fb4efcb7f6540cc2677f8a3a7c62452e (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
/*****************************************************************************
 * Copyright (c) 2012 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.infra.table.properties.provider;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;


public class PasteElementContainmentFeatureContentProvider extends AbstractStaticContentProvider implements ITreeContentProvider {

	private PapyrusTableInstance contextTable;

	public PasteElementContainmentFeatureContentProvider(PapyrusTableInstance contextTable) {
		this.contextTable = contextTable;
	}

	public EClass[] getElements() {
		EObject context = contextTable.getTable().getContext();

		if(context == null) {
			return new EClass[0];
		}

		EClass contextMetaclass = context.eClass();
		return new EClass[]{ contextMetaclass };
	}

	public EReference[] getChildren(Object parentElement) {
		if(parentElement instanceof EClass) {
			EClass contextMetaclass = (EClass)parentElement;
			List<EReference> result = new LinkedList<EReference>();
			for(EReference reference : contextMetaclass.getEAllReferences()) {
				if(reference.isContainment() && reference.getUpperBound() != 1) {
					result.add(reference);
				}
			}
			return result.toArray(new EReference[result.size()]);
		}

		return new EReference[0];
	}

	public Object getParent(Object element) {
		if(element instanceof EReference) {
			return ((EReference)element).getEContainingClass();
		}
		return null;
	}

	public boolean hasChildren(Object element) {
		return getChildren(element).length > 0;
	}

}

Back to the top