blob: 35d554444a2a26c9ddffbda51e8b6bb32569145b (
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
124
125
126
127
|
/*****************************************************************************
* Copyright (c) 2014 Cedric Dumoulin.
*
*
* 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:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.profile.drafter.ui.model;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
import org.eclipse.papyrus.uml.profile.drafter.utils.UMLPrimitiveTypesModel;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Type;
/**
* A {@link ITypeCatalog} listing the type accessible from a specified {@link Element}.
*
* @author cedric dumoulin
*
*/
public class AccessibleTypeCatalog implements ITypeCatalog {
/**
*
*/
protected Element element;
protected UMLPrimitiveTypesModel primitiveTypesModel;
/**
* Constructor.
*
*/
public AccessibleTypeCatalog(Element element) {
this.element = element;
// Create primitiveTypeModel from the ResourceSet associated to the element.
// It will be used to add such types.
try {
primitiveTypesModel = new UMLPrimitiveTypesModel(element.eResource().getResourceSet());
} catch (UnsupportedOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Constructor.
*
*/
public AccessibleTypeCatalog(Element element, UMLPrimitiveTypesModel primitiveTypesLibrary) {
this.element = element;
this.primitiveTypesModel = primitiveTypesLibrary;
}
/**
* @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#getTypeLabel(org.eclipse.uml2.uml.Type)
*
* @param type
* @return
*/
// @Override
public String getTypeLabel(Type type) {
return type.getLabel();
}
/**
* @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#getType(java.lang.String)
*
* @param typeLabel
* @return
* @throws NotFoundException
*/
// @Override
public Type getType(String typeLabel) throws NotFoundException {
for( Type type : getTypes()) {
if( type.getLabel().equals(typeLabel))
return type;
}
throw new NotFoundException("No type found under name '" + typeLabel +"'.");
}
/**
* @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#getTypes()
*
* @return
*/
@Override
public List<Type> getTypes() {
if(primitiveTypesModel != null) {
return primitiveTypesModel.getLibraryPackage().getOwnedTypes();
}
// Retutn empty list
return Collections.emptyList();
// Package owningPackage = element.getNearestPackage();
//
// org.eclipse.papyrus.uml.tools.utils.PackageUtil.getAccessibleTypes(owningPackage);
//
// EcoreUtil.getObjectsByType(element.eResource().getAllContents(), UMLPackage.eINSTANCE.getType());
//
// element.eResource().g
// // TODO Auto-generated method stub
// return null;
}
@Override
public Iterator<Type> iterator() {
return getTypes().iterator();
}
}
|