1 | package de.uka.ipd.sdq.sensorframework.visualisation.tabs.filters; |
2 | |
3 | import java.util.Arrays; |
4 | import java.util.List; |
5 | import java.util.Properties; |
6 | |
7 | import org.eclipse.jface.dialogs.MessageDialog; |
8 | import org.eclipse.jface.viewers.ICellModifier; |
9 | import org.eclipse.swt.widgets.Shell; |
10 | import org.eclipse.swt.widgets.TableItem; |
11 | |
12 | import de.uka.ipd.sdq.sensorframework.filter.IFilteredCollectionFactory; |
13 | import de.uka.ipd.sdq.sensorframework.visualisation.VisualisationPlugin; |
14 | |
15 | /** |
16 | * @author Roman Andrej |
17 | */ |
18 | public class FiltersTabCellModifier implements ICellModifier { |
19 | |
20 | private FiltersPropertySection section; |
21 | private List<String> columnNames; |
22 | |
23 | public FiltersTabCellModifier(FiltersPropertySection section) { |
24 | this.section = section; |
25 | this.columnNames = Arrays.asList(FiltersPropertySection.columnNames); |
26 | } |
27 | |
28 | /* (non-Javadoc) |
29 | * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String) |
30 | */ |
31 | public boolean canModify(Object element, String property) { |
32 | return true; |
33 | } |
34 | |
35 | /* (non-Javadoc) |
36 | * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String) |
37 | */ |
38 | public Object getValue(Object element, String property) { |
39 | return (new FiltersTabLabelProvider()).getColumnText(element, |
40 | columnNames.indexOf(property)); |
41 | } |
42 | |
43 | /* (non-Javadoc) |
44 | * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object) |
45 | */ |
46 | public void modify(Object element, String property, Object value) { |
47 | // Find the index of the column |
48 | int columnIndex = columnNames.indexOf(property); |
49 | |
50 | TableItem item = (TableItem) element; |
51 | |
52 | IFilteredCollectionFactory factory = (IFilteredCollectionFactory) item.getData(); |
53 | |
54 | switch (columnIndex) { |
55 | case FiltersPropertySection.ICON_COLUMN_INDEX: // ICON_COLUMN |
56 | break; |
57 | case FiltersPropertySection.FILTERNAME_COLUMN_INDEX: // FILTERNAME_COLUMN |
58 | break; |
59 | case FiltersPropertySection.PARAMETER_TYPE_COLUMN_INDEX: // PARAMETER_TYPE_COLUMN |
60 | break; |
61 | case FiltersPropertySection.PARAMETER_DESCRIPTION_COLUMN_INDEX: // PARAMETER_DESCRIPTION |
62 | break; |
63 | case FiltersPropertySection.PARAMETER_VALUE_COLUMN_INDEX: // PARAMETER_VALUE_COLUMN |
64 | setFilteringParameter(factory, ((String) value).trim()); |
65 | break; |
66 | default: |
67 | } |
68 | } |
69 | |
70 | /** |
71 | * The method set the new parameter value to the filter. |
72 | * |
73 | * @param selected |
74 | * filter |
75 | * @param new |
76 | * parameter value |
77 | */ |
78 | private void setFilteringParameter(IFilteredCollectionFactory factory, String input) { |
79 | try { |
80 | // get properties |
81 | Properties properties = factory.getProperties(); |
82 | // get first property description |
83 | String desc = properties.propertyNames().nextElement().toString(); |
84 | // set new parameter |
85 | properties.put(desc, factory.convertToType(input)); |
86 | // refresh section viewer |
87 | section.refresh(); |
88 | |
89 | } catch (NumberFormatException e) { |
90 | MessageDialog.openInformation(getShell(), |
91 | "Parameter conversion Error ", |
92 | "The entered parameter is not of the type Number!"); |
93 | } |
94 | } |
95 | |
96 | /** The method get the active shell. */ |
97 | private Shell getShell(){ |
98 | return VisualisationPlugin.getDefault() |
99 | .getWorkbench().getActiveWorkbenchWindow().getShell(); |
100 | } |
101 | } |