1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.dialogs.variableusage; |
5 | |
6 | import org.eclipse.emf.common.util.EList; |
7 | import org.eclipse.jface.viewers.ITreeContentProvider; |
8 | import org.eclipse.jface.viewers.Viewer; |
9 | |
10 | import de.uka.ipd.sdq.pcm.dialogs.datatype.DataTypeContainer; |
11 | import de.uka.ipd.sdq.pcm.dialogs.datatype.InnerDeclarationContainer; |
12 | import de.uka.ipd.sdq.pcm.repository.CollectionDataType; |
13 | import de.uka.ipd.sdq.pcm.repository.CompositeDataType; |
14 | import de.uka.ipd.sdq.pcm.repository.DataType; |
15 | import de.uka.ipd.sdq.pcm.repository.InnerDeclaration; |
16 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
17 | import de.uka.ipd.sdq.pcm.repository.PrimitiveDataType; |
18 | import de.uka.ipd.sdq.pcm.repository.Signature; |
19 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
20 | |
21 | /** |
22 | * @author admin |
23 | * |
24 | */ |
25 | public class VariableUsageContentProvider implements ITreeContentProvider { |
26 | |
27 | /* (non-Javadoc) |
28 | * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
29 | */ |
30 | public Object[] getElements(Object inputElement) { |
31 | if (inputElement instanceof Signature) { |
32 | return getChildren(inputElement); |
33 | } |
34 | return null; |
35 | } |
36 | |
37 | /* (non-Javadoc) |
38 | * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
39 | */ |
40 | public void dispose() { |
41 | // TODO Auto-generated method stub |
42 | } |
43 | |
44 | /* (non-Javadoc) |
45 | * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
46 | */ |
47 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
48 | // TODO Auto-generated method stub |
49 | } |
50 | |
51 | /* (non-Javadoc) |
52 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
53 | */ |
54 | public Object[] getChildren(Object parent) { |
55 | /** |
56 | * SEFF |
57 | */ |
58 | if (parent instanceof ResourceDemandingSEFF) { |
59 | ResourceDemandingSEFF seff = (ResourceDemandingSEFF) parent; |
60 | return new Object[] {seff.getDescribedService__SEFF()}; |
61 | } |
62 | |
63 | /** |
64 | * Parameter |
65 | */ |
66 | if (parent instanceof Parameter) { |
67 | Parameter parameter = (Parameter) parent; |
68 | DataType dataType = (DataType) parameter.getDataType__Parameter(); |
69 | |
70 | if (dataType instanceof CompositeDataType) { |
71 | return getCompositeTypeElements(dataType, parameter); |
72 | } |
73 | else if (dataType instanceof CollectionDataType) { |
74 | return new Object[] {new DataTypeContainer(((CollectionDataType)dataType).getInnerType_CollectionDataType(),parent)}; |
75 | } |
76 | else |
77 | return new Object[]{}; |
78 | } |
79 | |
80 | /** |
81 | * TreeType |
82 | */ |
83 | if (parent instanceof DataTypeContainer) { |
84 | DataType innerType = getTreeTypeInner(parent); |
85 | |
86 | if (innerType instanceof PrimitiveDataType) |
87 | return new Object[0]; |
88 | |
89 | if (innerType instanceof CompositeDataType) |
90 | return getCompositeTypeElements(innerType,parent); |
91 | |
92 | return new Object[] { new DataTypeContainer(innerType,parent) }; |
93 | } |
94 | |
95 | /** |
96 | * TreeDeclaration |
97 | */ |
98 | if (parent instanceof InnerDeclarationContainer) { |
99 | DataType innerType = getTreeDeclarationInner(parent); |
100 | |
101 | if (innerType instanceof CompositeDataType) { |
102 | return getCompositeTypeElements(innerType, parent); |
103 | } |
104 | |
105 | CollectionDataType collDataType = (CollectionDataType) innerType; |
106 | return new Object[] { new DataTypeContainer(collDataType |
107 | .getInnerType_CollectionDataType(),parent) }; |
108 | } |
109 | |
110 | return new Object[0]; |
111 | } |
112 | |
113 | /** |
114 | * @return - return the DataType from InnerDeclaration of |
115 | * TreeDeclaration-Object |
116 | */ |
117 | private DataType getTreeDeclarationInner(Object parent) { |
118 | InnerDeclarationContainer treeDeclaration = (InnerDeclarationContainer) parent; |
119 | InnerDeclaration declaration = (InnerDeclaration) treeDeclaration |
120 | .getObject(); |
121 | return declaration.getDatatype_InnerDeclaration(); |
122 | } |
123 | |
124 | /** |
125 | * @return - return the DataType from inner collection datatype of |
126 | * TreeType-Object |
127 | */ |
128 | private DataType getTreeTypeInner(Object parent) { |
129 | DataTypeContainer treeType = (DataTypeContainer) parent; |
130 | DataType dataType = (DataType) treeType.getObject(); |
131 | |
132 | if (dataType instanceof PrimitiveDataType) { |
133 | return dataType; |
134 | |
135 | } |
136 | CollectionDataType collDataType = (CollectionDataType) dataType; |
137 | return collDataType.getInnerType_CollectionDataType(); |
138 | } |
139 | |
140 | /** |
141 | * TODO |
142 | * |
143 | * @return - array of TreeDeclaration from composite datatype |
144 | */ |
145 | private Object[] getCompositeTypeElements(DataType dataType, Object parent) { |
146 | CompositeDataType compDataType = (CompositeDataType) dataType; |
147 | EList<InnerDeclaration> list = compDataType |
148 | .getInnerDeclaration_CompositeDataType(); |
149 | Object[] objects = new Object[list.size()]; |
150 | |
151 | int i = 0; |
152 | |
153 | for (InnerDeclaration inner : list) |
154 | objects[i++] = new InnerDeclarationContainer(inner, parent); |
155 | |
156 | return objects; |
157 | } |
158 | |
159 | /* (non-Javadoc) |
160 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
161 | */ |
162 | public Object getParent(Object element) { |
163 | // TODO Auto-generated method stub |
164 | return null; |
165 | } |
166 | |
167 | /* (non-Javadoc) |
168 | * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
169 | */ |
170 | public boolean hasChildren(Object element) { |
171 | |
172 | if (element instanceof Parameter) { |
173 | Parameter parameter = (Parameter) element; |
174 | DataType dataType = parameter.getDataType__Parameter(); |
175 | return hasChildren(dataType); |
176 | } |
177 | |
178 | if (element instanceof DataTypeContainer){ |
179 | DataType innerType = getTreeTypeInner(element); |
180 | return hasChildren(innerType); |
181 | } |
182 | |
183 | if (element instanceof InnerDeclarationContainer){ |
184 | DataType dataType = getTreeDeclarationInner(element); |
185 | return hasChildren(dataType); |
186 | } |
187 | |
188 | if (element instanceof PrimitiveDataType) |
189 | return false; |
190 | |
191 | return true; |
192 | } |
193 | } |
194 | |
195 | |
196 | |
197 | |