1 | package de.uka.ipd.sdq.pcmbench.tabs.parameters; |
2 | |
3 | import org.eclipse.emf.common.notify.AdapterFactory; |
4 | import org.eclipse.emf.common.util.EList; |
5 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
6 | import org.eclipse.emf.edit.provider.ITableItemLabelProvider; |
7 | import org.eclipse.emf.edit.provider.ItemProviderDecorator; |
8 | |
9 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
10 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
11 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
12 | import de.uka.ipd.sdq.pcm.stochasticexpressions.PCMStoExPrettyPrintVisitor; |
13 | |
14 | /** |
15 | * @author Snowball This class is a decorator for the generated EMF.Edit item |
16 | * providers. It provides item providers which are used in the |
17 | * operations tab of the tabbed properties sheet when editing |
18 | * interfaces. It implements ITableItemLabelProvider to display the |
19 | * given EObject in a tabular form. Additionally it provided the labels |
20 | * by partcial delegation to the original IItemLabelProvider. |
21 | */ |
22 | public class ParametersTabItemProvider extends ItemProviderDecorator implements |
23 | ITableItemLabelProvider, IItemLabelProvider { |
24 | |
25 | private PCMStoExPrettyPrintVisitor print; |
26 | |
27 | /** |
28 | * Inherited default constructor |
29 | * |
30 | * @param factory |
31 | * The factory which created this object |
32 | */ |
33 | public ParametersTabItemProvider(AdapterFactory factory) { |
34 | super(factory); |
35 | print = new PCMStoExPrettyPrintVisitor(); |
36 | } |
37 | |
38 | /* |
39 | * (non-Javadoc) |
40 | * |
41 | * @see org.eclipse.emf.edit.provider.ItemProviderDecorator#getColumnImage(java.lang.Object, |
42 | * int) |
43 | */ |
44 | @Override |
45 | public Object getColumnImage(Object object, int columnIndex) { |
46 | if (columnIndex == ComponentParametersEditorSection.ICON_COLUMN_INDEX) |
47 | return this.getImage(object); |
48 | return null; |
49 | } |
50 | |
51 | /** |
52 | * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, |
53 | * int) Format the columns with the given index constant as string text |
54 | * for displaying |
55 | */ |
56 | @Override |
57 | public String getColumnText(Object element, int columnIndex) { |
58 | String result = ""; |
59 | VariableUsageWrapper variable = (VariableUsageWrapper) element; |
60 | |
61 | switch (columnIndex) { |
62 | case ComponentParametersEditorSection.ICON_COLUMN_INDEX: |
63 | break; |
64 | case ComponentParametersEditorSection.VARIABLE_COLUMN_INDEX: |
65 | result = print.prettyPrint(variable.getVariableUsage()); |
66 | break; |
67 | case ComponentParametersEditorSection.STOEX_COLUMN_INDEX: |
68 | result = getSpecification(variable.getVariableUsage()); |
69 | break; |
70 | default: |
71 | break; |
72 | } |
73 | return result; |
74 | } |
75 | |
76 | |
77 | private String getSpecification(VariableUsage variable) { |
78 | String specification = ""; |
79 | EList<VariableCharacterisation> characterisation = variable |
80 | .getVariableCharacterisation_VariableUsage(); |
81 | if (characterisation.size() > 0) { |
82 | PCMRandomVariable randomVariable = characterisation.get(0) |
83 | .getSpecification_VariableCharacterisation(); |
84 | specification = randomVariable.getSpecification(); |
85 | } |
86 | return specification; |
87 | } |
88 | |
89 | } |