1 | package de.uka.ipd.sdq.pcmbench.propertytabs; |
2 | |
3 | import org.eclipse.emf.common.notify.AdapterFactory; |
4 | import org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEditor; |
5 | import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
6 | import org.eclipse.emf.edit.provider.IItemPropertySource; |
7 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
8 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
9 | import org.eclipse.emf.edit.ui.provider.PropertyDescriptor; |
10 | import org.eclipse.emf.edit.ui.provider.PropertySource; |
11 | import org.eclipse.jface.dialogs.Dialog; |
12 | import org.eclipse.jface.viewers.CellEditor; |
13 | import org.eclipse.swt.widgets.Composite; |
14 | import org.eclipse.swt.widgets.Control; |
15 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
16 | import org.eclipse.ui.views.properties.IPropertySource; |
17 | |
18 | import de.uka.ipd.sdq.pcm.dialogs.stoex.StochasticExpressionEditDialog; |
19 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
20 | import de.uka.ipd.sdq.pcm.stochasticexpressions.PCMStoExPrettyPrintVisitor; |
21 | import de.uka.ipd.sdq.stoex.RandomVariable; |
22 | import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum; |
23 | |
24 | public class PalladioAdapterFactoryContentProvider extends |
25 | AdapterFactoryContentProvider { |
26 | |
27 | public PalladioAdapterFactoryContentProvider(AdapterFactory adapterFactory) { |
28 | super(adapterFactory); |
29 | } |
30 | |
31 | @Override |
32 | protected IPropertySource createPropertySource(Object object, IItemPropertySource itemPropertySource) { |
33 | if (object instanceof RandomVariable) |
34 | { |
35 | return getRandomVariablePropertySheet(object, itemPropertySource); |
36 | } |
37 | else |
38 | return super.createPropertySource(object, itemPropertySource); |
39 | } |
40 | |
41 | protected IPropertySource getRandomVariablePropertySheet(Object object,IItemPropertySource itemPropertySource) { |
42 | return new PropertySource(object, itemPropertySource) { |
43 | |
44 | @Override |
45 | protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor) { |
46 | if (itemPropertyDescriptor.getDisplayName(object).equals("Specification")) { |
47 | return getDescriptorWithStoExParser(object,itemPropertyDescriptor); |
48 | } else { |
49 | return super.createPropertyDescriptor(itemPropertyDescriptor); |
50 | } |
51 | } |
52 | |
53 | }; |
54 | } |
55 | |
56 | private IPropertyDescriptor getDescriptorWithStoExParser(Object object, IItemPropertyDescriptor itemPropertyDescriptor) { |
57 | return new PropertyDescriptor(object,itemPropertyDescriptor) { |
58 | |
59 | @Override |
60 | public CellEditor createPropertyEditor(Composite composite) { |
61 | |
62 | CellEditor result = new ExtendedDialogCellEditor(composite, new AdapterFactoryLabelProvider(adapterFactory)) { |
63 | |
64 | @Override |
65 | protected Object openDialogBox(Control cellEditorWindow) { |
66 | RandomVariable randVar = (RandomVariable) object; |
67 | StochasticExpressionEditDialog dialog = |
68 | new StochasticExpressionEditDialog( |
69 | cellEditorWindow.getShell(), |
70 | getExpectedType(randVar), |
71 | randVar); |
72 | dialog.setInitialExpression(randVar); |
73 | dialog.open(); |
74 | if (dialog.getReturnCode() == Dialog.OK) { |
75 | String result = new PCMStoExPrettyPrintVisitor().prettyPrint(dialog.getResult()); |
76 | return result; |
77 | } |
78 | return null; |
79 | } |
80 | }; |
81 | return result; |
82 | } |
83 | }; |
84 | } |
85 | |
86 | protected TypeEnum getExpectedType(RandomVariable rv) { |
87 | TypeEnum expectedType = TypeEnum.ANY; |
88 | if (rv instanceof VariableCharacterisation){ |
89 | expectedType = StochasticExpressionEditDialog.getTypeFromVariableCharacterisation((VariableCharacterisation) rv); |
90 | } |
91 | return expectedType; |
92 | } |
93 | } |