EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.sensorframework.visualisation.tabs.filters]

COVERAGE SUMMARY FOR SOURCE FILE [FiltersPropertySection.java]

nameclass, %method, %block, %line, %
FiltersPropertySection.java0%   (0/7)0%   (0/26)0%   (0/635)0%   (0/133)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FilterLabelProvider0%   (0/1)0%   (0/2)0%   (0/16)0%   (0/5)
FilterLabelProvider (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getText (Object): String 0%   (0/1)0%   (0/13)0%   (0/4)
     
class FiltersPropertySection0%   (0/1)0%   (0/14)0%   (0/402)0%   (0/81)
<static initializer> 0%   (0/1)0%   (0/24)0%   (0/2)
FiltersPropertySection (): void 0%   (0/1)0%   (0/9)0%   (0/3)
access$0 (FiltersPropertySection): TableViewer 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (FiltersPropertySection, IFilteredCollectionFactory): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$2 (FiltersPropertySection): ToolItem 0%   (0/1)0%   (0/3)0%   (0/1)
access$3 (FiltersPropertySection): ToolItem 0%   (0/1)0%   (0/3)0%   (0/1)
access$4 (FiltersPropertySection): ToolItem 0%   (0/1)0%   (0/3)0%   (0/1)
access$5 (FiltersPropertySection): ConfigEditorInput 0%   (0/1)0%   (0/3)0%   (0/1)
access$6 (FiltersPropertySection): IFilteredCollectionFactory 0%   (0/1)0%   (0/3)0%   (0/1)
access$7 (FiltersPropertySection): Object [] 0%   (0/1)0%   (0/3)0%   (0/1)
createControls (Composite, TabbedPropertySheetPage): void 0%   (0/1)0%   (0/310)0%   (0/61)
getDefinedFilters (): Object [] 0%   (0/1)0%   (0/4)0%   (0/2)
refresh (): void 0%   (0/1)0%   (0/9)0%   (0/3)
setInput (IWorkbenchPart, ISelection): void 0%   (0/1)0%   (0/21)0%   (0/6)
     
class FiltersPropertySection$10%   (0/1)0%   (0/2)0%   (0/69)0%   (0/17)
FiltersPropertySection$1 (FiltersPropertySection): void 0%   (0/1)0%   (0/6)0%   (0/2)
selectionChanged (SelectionChangedEvent): void 0%   (0/1)0%   (0/63)0%   (0/15)
     
class FiltersPropertySection$20%   (0/1)0%   (0/2)0%   (0/48)0%   (0/14)
FiltersPropertySection$2 (FiltersPropertySection): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/42)0%   (0/12)
     
class FiltersPropertySection$30%   (0/1)0%   (0/2)0%   (0/41)0%   (0/10)
FiltersPropertySection$3 (FiltersPropertySection): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/35)0%   (0/8)
     
class FiltersPropertySection$40%   (0/1)0%   (0/2)0%   (0/41)0%   (0/10)
FiltersPropertySection$4 (FiltersPropertySection): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/35)0%   (0/8)
     
class FiltersPropertySection$50%   (0/1)0%   (0/2)0%   (0/18)0%   (0/5)
FiltersPropertySection$5 (FiltersPropertySection): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/12)0%   (0/3)

1package de.uka.ipd.sdq.sensorframework.visualisation.tabs.filters;
2 
3import java.util.ArrayList;
4 
5import org.eclipse.jface.viewers.CellEditor;
6import org.eclipse.jface.viewers.ISelection;
7import org.eclipse.jface.viewers.ISelectionChangedListener;
8import org.eclipse.jface.viewers.IStructuredSelection;
9import org.eclipse.jface.viewers.LabelProvider;
10import org.eclipse.jface.viewers.SelectionChangedEvent;
11import org.eclipse.jface.viewers.TableViewer;
12import org.eclipse.jface.viewers.TextCellEditor;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.events.SelectionAdapter;
15import org.eclipse.swt.events.SelectionEvent;
16import org.eclipse.swt.layout.FormAttachment;
17import org.eclipse.swt.layout.FormData;
18import org.eclipse.swt.layout.GridData;
19import org.eclipse.swt.widgets.Composite;
20import org.eclipse.swt.widgets.Table;
21import org.eclipse.swt.widgets.TableColumn;
22import org.eclipse.swt.widgets.ToolBar;
23import org.eclipse.swt.widgets.ToolItem;
24import org.eclipse.ui.IWorkbenchPart;
25import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
26import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
27 
28import de.uka.ipd.sdq.sensorframework.filter.FilteredCollectionRegistry;
29import de.uka.ipd.sdq.sensorframework.filter.IFilteredCollectionFactory;
30import de.uka.ipd.sdq.sensorframework.visualisation.VisualisationImages;
31import de.uka.ipd.sdq.sensorframework.visualisation.dialogs.ActionListSelectionDialog;
32import de.uka.ipd.sdq.sensorframework.visualisation.editor.AbstractReportView;
33import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEditorInput;
34 
35/**
36 * This class defines the 'Filters' tab section, which makes a definition
37 * possible of filter and their pure sequence for measured values indicated in
38 * the opinion.
39 * 
40 * @author Roman Andrej
41 */
42public class FiltersPropertySection extends AbstractPropertySection {
43        
44        private ConfigEditorInput configObject;
45        private TableViewer viewer;
46        private ToolItem deleteItem, upItem, downItem;
47        
48        private IFilteredCollectionFactory selectedFactory;
49        
50 
51        public static final int ICON_COLUMN_INDEX = 0;
52        public static final int FILTERNAME_COLUMN_INDEX = 1;
53        public static final int PARAMETER_TYPE_COLUMN_INDEX = 2;
54        public static final int PARAMETER_DESCRIPTION_COLUMN_INDEX = 3;
55        public static final int PARAMETER_VALUE_COLUMN_INDEX = 4;
56 
57        /**
58         * Columns of a table, which is used into ParameterEditDialog.
59         */
60        public final static String ICON_COLUMN = "";
61        public final static String FILTERNAME_COLUMN = "Filter name";
62        public final static String PARAMETER_TYPE_COLUMN = "Parameter type";
63        public final static String PARAMETER_DESCRIPTION_COLUMN = "Description";
64        public final static String PARAMETER_VALUE_COLUMN = "Value";
65        /** ToolBar width. */
66        private final int toolbarWidth = 23;
67 
68        // Set column names of Tabele
69        protected static String[] columnNames = new String[] { ICON_COLUMN, FILTERNAME_COLUMN, PARAMETER_TYPE_COLUMN,PARAMETER_DESCRIPTION_COLUMN, PARAMETER_VALUE_COLUMN };
70 
71        // style the style of table to construct
72        int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
73                        | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
74 
75        /* (non-Javadoc)
76         * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
77         */
78        @Override
79        public void createControls(Composite parent,
80                        TabbedPropertySheetPage tabbedPropertySheetPage) {
81                super.createControls(parent, tabbedPropertySheetPage);
82                
83                Composite composite = getWidgetFactory()
84                                .createFlatFormComposite(parent);
85                composite.getParent().setLayoutData(
86                                new GridData(SWT.FILL, SWT.FILL, true, true));
87                
88                // create table
89                final Table table = new Table(composite, style);
90                final FormData fd_table = new FormData();
91                fd_table.bottom = new FormAttachment(100, 0);
92                fd_table.top = new FormAttachment(0, 0);
93                fd_table.left = new FormAttachment(0, 0);
94                table.setLayoutData(fd_table);
95                table.setLinesVisible(true);
96                table.setHeaderVisible(true);
97 
98                // create 'Viewer'
99                viewer = new TableViewer(table);
100                viewer.setColumnProperties(columnNames);
101                viewer.setContentProvider(new FiltersTabContentProvider());
102                viewer.setLabelProvider(new FiltersTabLabelProvider());
103                
104                viewer.setCellModifier(new FiltersTabCellModifier(this));
105                viewer.addSelectionChangedListener(new ISelectionChangedListener() {
106                        public void selectionChanged(SelectionChangedEvent event) {
107                                Object object = ((IStructuredSelection) viewer.getSelection())
108                                                .getFirstElement();
109                                if (object instanceof IFilteredCollectionFactory) {
110                                        selectedFactory = (IFilteredCollectionFactory) object;
111                                        upItem.setEnabled(true);
112                                        downItem.setEnabled(true);
113                                        deleteItem.setEnabled(true);
114 
115                                        int index = configObject.getFiltersManager().getFactories()
116                                                        .indexOf(selectedFactory);
117                                        if (index == 0) {
118                                                upItem.setEnabled(false);
119                                        }
120                                        if (index == configObject.getFiltersManager()
121                                                        .getFactories().size()-1) {
122                                                downItem.setEnabled(false);
123                                        }
124                                }
125                        }
126                });
127 
128                // Create the cell editors for 'Parameters' column
129                CellEditor[] editors = new CellEditor[columnNames.length];
130                editors[PARAMETER_VALUE_COLUMN_INDEX] = new TextCellEditor(table);
131                
132                // Assign the cell editors to the viewer
133                viewer.setCellEditors(editors);
134 
135                // create icon column
136                final TableColumn iconColumn = new TableColumn(table, SWT.NONE);
137                iconColumn.setWidth(30);
138                iconColumn.setText(ICON_COLUMN);
139 
140                // create filter name column
141                final TableColumn nameColumn = new TableColumn(table, SWT.NONE);
142                nameColumn.setWidth(210);
143                nameColumn.setText(FILTERNAME_COLUMN);
144 
145                // create parameter type column
146                final TableColumn parametersColumn = new TableColumn(table, SWT.CENTER);
147                parametersColumn.setWidth(100);
148                parametersColumn.setText(PARAMETER_TYPE_COLUMN);
149                
150                // create parameter description column
151                final TableColumn parameterDescColumn = new TableColumn(table, SWT.CENTER);
152                parameterDescColumn.setWidth(140);
153                parameterDescColumn.setText(PARAMETER_DESCRIPTION_COLUMN);
154                
155                // create parameter value column
156                final TableColumn parameterValueColumn = new TableColumn(table, SWT.CENTER);
157                parameterValueColumn.setWidth(80);
158                parameterValueColumn.setText(PARAMETER_VALUE_COLUMN);
159                
160                // create tool bar
161                final ToolBar toolBar = new ToolBar(composite, SWT.VERTICAL);
162                fd_table.right = new FormAttachment(toolBar, 0 , SWT.LEFT);
163                final FormData fd_toolBar = new FormData();
164                fd_toolBar.bottom = new FormAttachment(100, 0);
165                fd_toolBar.left = new FormAttachment(100, - toolbarWidth);
166                fd_toolBar.right = new FormAttachment(100, 0);
167                fd_toolBar.top = new FormAttachment(0, 0);
168                toolBar.setLayoutData(fd_toolBar);
169 
170                // create 'Add' button
171                ToolItem addRunItem = new ToolItem(toolBar, SWT.PUSH);
172                addRunItem.setImage(VisualisationImages.imageRegistry.get(VisualisationImages.ADD));
173                addRunItem.addSelectionListener(new SelectionAdapter(){
174 
175                        /* (non-Javadoc)
176                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
177                         */
178                        @Override
179                        public void widgetSelected(SelectionEvent event) {
180                                IFilteredCollectionFactory factory = null;
181 
182                                ActionListSelectionDialog dialog = new ActionListSelectionDialog(
183                                                event.display.getActiveShell(),
184                                                new FilterLabelProvider(), 250, 200);
185                                dialog.setElements(getDefinedFilters());
186                                dialog.open();
187                                Object[] results = dialog.getResult();
188 
189                                if (results != null) {
190                                        factory = (IFilteredCollectionFactory) results[0];
191                                        // add the filtered collection to the FilteredCollectionsManager
192                                        configObject.getFiltersManager().addFactory(factory);
193                                        // refresh TabeleViewer
194                                        refresh();
195                                }
196                        }
197                });
198 
199                // create 'Up' button
200                upItem = new ToolItem(toolBar, SWT.PUSH);
201                upItem.setImage(VisualisationImages.imageRegistry.get(VisualisationImages.UP));
202                upItem.addSelectionListener(new SelectionAdapter(){
203 
204                        /* (non-Javadoc)
205                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
206                         */
207                        @Override
208                        public void widgetSelected(SelectionEvent e) {
209                                ArrayList<IFilteredCollectionFactory> factories = configObject
210                                                .getFiltersManager().getFactories();
211                                int index = factories.indexOf(selectedFactory);
212                                factories.remove(selectedFactory);
213                                factories.add(index - 1, selectedFactory);
214                                upItem.setEnabled(false);
215                                refresh();
216                        }
217                });
218                upItem.setEnabled(false);
219                
220                // create 'Down' button
221                downItem = new ToolItem(toolBar, SWT.PUSH);
222                downItem.setImage(VisualisationImages.imageRegistry.get(VisualisationImages.DOWN));
223                downItem.addSelectionListener(new SelectionAdapter(){
224 
225                        /* (non-Javadoc)
226                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
227                         */
228                        @Override
229                        public void widgetSelected(SelectionEvent e) {
230                                ArrayList<IFilteredCollectionFactory> factories = configObject
231                                                .getFiltersManager().getFactories();
232                                int index = factories.indexOf(selectedFactory);
233                                factories.remove(selectedFactory);
234                                factories.add(index + 1, selectedFactory);
235                                downItem.setEnabled(false);
236                                refresh();
237                        }
238                });
239                downItem.setEnabled(false);
240                
241                // create 'Delete' button
242                deleteItem = new ToolItem(toolBar, SWT.PUSH);
243                deleteItem.setImage(VisualisationImages.imageRegistry.get(VisualisationImages.DELETE));
244                deleteItem.addSelectionListener(new SelectionAdapter(){
245 
246                        /* (non-Javadoc)
247                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
248                         */
249                        @Override
250                        public void widgetSelected(SelectionEvent event) {
251                                // remove in viewer selected filter from 'FilterManager'
252                                configObject.getFiltersManager().removeFactory(selectedFactory);
253                                refresh();
254                        }
255                });
256                deleteItem.setEnabled(false);
257        }
258        
259        /* (non-Javadoc)
260         * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#setInput(org.eclipse.ui.IWorkbenchPart,
261         *      org.eclipse.jface.viewers.ISelection)
262         */
263        @Override
264        public void setInput(IWorkbenchPart part, ISelection selection) {
265                super.setInput(part, selection);
266 
267                if (part instanceof AbstractReportView) {
268                        AbstractReportView view = (AbstractReportView) part;
269                        configObject = (ConfigEditorInput) view.getEditorInput();
270                        
271                        viewer.setInput(configObject);
272                }
273        }
274        
275        private Object[] getDefinedFilters() {
276                return FilteredCollectionRegistry
277                                .singleton().getAllAvailableCollectionFactories().toArray();
278        }
279 
280        /* (non-Javadoc)
281         * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh()
282         */
283        @Override
284        public void refresh() {
285                // send message to observer
286                configObject.update(null, null);
287                // refresh TableViewer (FilterTab)
288                viewer.refresh();
289        }
290}
291 
292/** The Class define the LabelProvider for ActionListSelectionDialog. */
293class FilterLabelProvider extends LabelProvider {
294        
295        /* (non-Javadoc)
296         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
297         */
298        @Override
299        public String getText(Object element) {
300                if (element instanceof IFilteredCollectionFactory) {
301                        IFilteredCollectionFactory factory = (IFilteredCollectionFactory) element;
302                        return factory.getFilterFactoryID();
303                }
304                return super.getText(element);
305        }
306}

[all classes][de.uka.ipd.sdq.sensorframework.visualisation.tabs.filters]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov