1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.dialogs.variableusage; |
5 | |
6 | import org.eclipse.emf.common.notify.AdapterFactory; |
7 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
8 | import org.eclipse.emf.edit.provider.ItemProviderDecorator; |
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 | |
19 | /** |
20 | * @author admin |
21 | * |
22 | */ |
23 | public class VariableUsageLabelProvider extends ItemProviderDecorator implements |
24 | IItemLabelProvider { |
25 | |
26 | public VariableUsageLabelProvider(AdapterFactory adapterFactory) { |
27 | super(adapterFactory); |
28 | } |
29 | |
30 | @Override |
31 | public Object getImage(Object object) { |
32 | |
33 | if (object instanceof DataTypeContainer) { |
34 | DataTypeContainer treeType = (DataTypeContainer) object; |
35 | return super.getImage(treeType.getObject()); |
36 | } |
37 | |
38 | if (object instanceof InnerDeclarationContainer) { |
39 | InnerDeclarationContainer treeDeclaration = (InnerDeclarationContainer) object; |
40 | return super.getImage(treeDeclaration.getObject()); |
41 | } |
42 | |
43 | return super.getImage(object); |
44 | } |
45 | |
46 | /* (non-Javadoc) |
47 | * @see org.eclipse.emf.edit.provider.ItemProviderDecorator#getText(java.lang.Object) |
48 | */ |
49 | @Override |
50 | public String getText(Object object) { |
51 | |
52 | if (object instanceof Parameter) { |
53 | Parameter p = (Parameter) object; |
54 | String result = p.getParameterName(); |
55 | if (p.getDataType__Parameter() != null) { |
56 | result += ": " + super.getText(p.getDataType__Parameter()); |
57 | } |
58 | return result; |
59 | } |
60 | |
61 | if (object instanceof DataTypeContainer) { |
62 | DataType dataType = getTreeTypeObject(object); |
63 | return "INNER: " + getNameDataType(dataType); |
64 | } |
65 | |
66 | if (object instanceof InnerDeclarationContainer) { |
67 | InnerDeclaration declaration = getTreeDeclarationObject(object); |
68 | DataType dataType = declaration.getDatatype_InnerDeclaration(); |
69 | |
70 | String typeName = ""; |
71 | |
72 | if (dataType instanceof CollectionDataType) { |
73 | CollectionDataType collType = (CollectionDataType) dataType; |
74 | typeName = collType.getEntityName(); |
75 | } |
76 | if (dataType instanceof CompositeDataType) { |
77 | CompositeDataType compType = (CompositeDataType) dataType; |
78 | typeName = compType.getEntityName(); |
79 | } |
80 | if (dataType instanceof PrimitiveDataType) { |
81 | PrimitiveDataType primType = (PrimitiveDataType) dataType; |
82 | typeName = primType.getType().getName(); |
83 | } |
84 | |
85 | return declaration.getEntityName() + ": " + typeName; |
86 | } |
87 | return super.getText(object); |
88 | } |
89 | |
90 | /** |
91 | * @return - return the DdataType from TreeType-Object |
92 | */ |
93 | private DataType getTreeTypeObject(Object object){ |
94 | DataTypeContainer treeType = (DataTypeContainer)object; |
95 | return (DataType) treeType.getObject(); |
96 | } |
97 | |
98 | /** |
99 | * @return - return the InnerDeclaration from TreeDeclaration-Object |
100 | */ |
101 | private InnerDeclaration getTreeDeclarationObject(Object object) { |
102 | InnerDeclarationContainer treeDeclaration = (InnerDeclarationContainer) object; |
103 | return (InnerDeclaration) treeDeclaration.getObject(); |
104 | } |
105 | |
106 | private String getNameDataType(DataType dataType) { |
107 | if (dataType != null) |
108 | return super.getText(dataType); |
109 | return "null"; |
110 | } |
111 | } |