1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcmbench.tabs.parameters; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.List; |
8 | |
9 | import org.eclipse.emf.common.util.EList; |
10 | import org.eclipse.jface.viewers.IStructuredContentProvider; |
11 | import org.eclipse.jface.viewers.Viewer; |
12 | |
13 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
14 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
15 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
16 | |
17 | /** |
18 | * @author Roman Andrej |
19 | */ |
20 | public class ParameterContentProvider implements IStructuredContentProvider { |
21 | |
22 | /* (non-Javadoc) |
23 | * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
24 | */ |
25 | public Object[] getElements(Object inputElement) { |
26 | |
27 | if (inputElement instanceof AssemblyContext) { |
28 | AssemblyContext context = (AssemblyContext) inputElement; |
29 | |
30 | EList<VariableUsage> contextParametrs = context |
31 | .getConfigParameterUsages__AssemblyContext(); |
32 | if (context.getEncapsulatedComponent__AssemblyContext() instanceof BasicComponent){ |
33 | EList<VariableUsage> componentParameters = ((BasicComponent) context |
34 | .getEncapsulatedComponent__AssemblyContext()) |
35 | .getComponentParameterUsage_ImplementationComponentType(); |
36 | return meargeParameter(contextParametrs, componentParameters); |
37 | |
38 | } |
39 | |
40 | } |
41 | |
42 | return null; |
43 | } |
44 | |
45 | private Object[] meargeParameter(EList<VariableUsage> ctxParameters, |
46 | EList<VariableUsage> cmpParameters) { |
47 | |
48 | VariableUsageWrapper removeWrapper = null; |
49 | |
50 | List<VariableUsageWrapper> parametrs = new ArrayList<VariableUsageWrapper>(); |
51 | |
52 | for (VariableUsage variableUsage : cmpParameters) { |
53 | parametrs.add(new VariableUsageWrapper(variableUsage)); |
54 | } |
55 | |
56 | for (VariableUsage ctx_variableUsage : ctxParameters) { |
57 | VariableUsageWrapper wrapper = new VariableUsageWrapper( |
58 | ctx_variableUsage, true); |
59 | for (VariableUsageWrapper cmpWrapper : parametrs) { |
60 | if (wrapper.equals(cmpWrapper)) { |
61 | removeWrapper = cmpWrapper; |
62 | } |
63 | |
64 | } |
65 | |
66 | int index = parametrs.size(); |
67 | |
68 | if (removeWrapper != null) { |
69 | index = parametrs.indexOf(removeWrapper); |
70 | parametrs.remove(removeWrapper); |
71 | removeWrapper = null; |
72 | } |
73 | |
74 | parametrs.add(index, wrapper); |
75 | } |
76 | |
77 | return parametrs.toArray(); |
78 | } |
79 | |
80 | |
81 | /* |
82 | * (non-Javadoc) |
83 | * |
84 | * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
85 | */ |
86 | public void dispose() { |
87 | // The implementation is not necessary. |
88 | } |
89 | |
90 | /* (non-Javadoc) |
91 | * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
92 | */ |
93 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
94 | // The implementation is not necessary. |
95 | } |
96 | } |