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

COVERAGE SUMMARY FOR SOURCE FILE [SensorValidationToView.java]

nameclass, %method, %block, %line, %
SensorValidationToView.java0%   (0/2)0%   (0/8)0%   (0/181)0%   (0/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DialogLabelProvider0%   (0/1)0%   (0/2)0%   (0/30)0%   (0/6)
DialogLabelProvider (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getText (Object): String 0%   (0/1)0%   (0/27)0%   (0/5)
     
class SensorValidationToView0%   (0/1)0%   (0/6)0%   (0/151)0%   (0/41)
SensorValidationToView (): void 0%   (0/1)0%   (0/3)0%   (0/1)
canViewSensor (SensorAndMeasurements): boolean 0%   (0/1)0%   (0/37)0%   (0/10)
findViews (SensorAndMeasurements): Object [] 0%   (0/1)0%   (0/65)0%   (0/12)
getConfigurationElements (): IConfigurationElement [] 0%   (0/1)0%   (0/6)0%   (0/4)
getSelectedAction (Shell, Object []): ViewAndAdapterFactory 0%   (0/1)0%   (0/26)0%   (0/8)
showMessage (Shell): void 0%   (0/1)0%   (0/14)0%   (0/6)

1package de.uka.ipd.sdq.sensorframework.visualisation.editor;
2 
3import java.util.ArrayList;
4 
5import org.eclipse.core.runtime.IConfigurationElement;
6import org.eclipse.core.runtime.Platform;
7import org.eclipse.jface.dialogs.MessageDialog;
8import org.eclipse.jface.viewers.LabelProvider;
9import org.eclipse.swt.widgets.Shell;
10 
11import de.uka.ipd.sdq.sensorframework.adapter.AdapterRegistry;
12import de.uka.ipd.sdq.sensorframework.adapter.IAdapterFactory;
13import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements;
14import de.uka.ipd.sdq.sensorframework.visualisation.VisualisationPlugin;
15import de.uka.ipd.sdq.sensorframework.visualisation.dialogs.ActionListSelectionDialog;
16import de.uka.ipd.sdq.sensorframework.visualisation.dialogs.ViewAndAdapterFactory;
17 
18/**
19 * This class offers the methods, which it for validating possible a 
20 * Sensor->View makes. Sensor->View - that only Views for sensors can be
21 * selected that can represent this sensor
22 * 
23 * @author Roman Andrej
24 * 
25 */
26public class SensorValidationToView {
27 
28        /**
29         * @return - all view, which can represent the sensor
30         */
31        public static Object[] findViews(SensorAndMeasurements sensorAndMeasurements) {
32                ArrayList<ViewAndAdapterFactory> result = new ArrayList<ViewAndAdapterFactory>();
33                IConfigurationElement[] elements = getConfigurationElements();
34 
35                for (IConfigurationElement element : elements) { // Iterate over all registered views
36                        String executableObject = element.getAttribute("acceptsData");
37                        try {
38                                Class<?> viewerAcceptsClass = Class.forName(executableObject);
39                                if (AdapterRegistry.singleton().canAdapt(sensorAndMeasurements,viewerAcceptsClass)) {
40                                        // there is at least one adapter which makes the combination work
41                                        for (IAdapterFactory f : AdapterRegistry.singleton().getAllAvailableFactories(sensorAndMeasurements, viewerAcceptsClass)) {
42                                                result.add(new ViewAndAdapterFactory(element,f));
43                                        }
44                                }
45                        } catch (ClassNotFoundException e) {
46                                // catch exception for TimeSpanSensor
47                        } catch (Exception e) {
48                                e.printStackTrace();
49                        }
50                }
51                return result.toArray();
52        }
53 
54        public static boolean canViewSensor(
55                        SensorAndMeasurements sensorAndMeasurements) {
56 
57                String activeEditorId = VisualisationPlugin.getDefault().getWorkbench()
58                                .getActiveWorkbenchWindow().getActivePage().getActiveEditor()
59                                .getSite().getId();
60                Object[] views = findViews(sensorAndMeasurements);
61 
62                for (int i = 0; i < views.length; i++) {
63                        ViewAndAdapterFactory viewer = (ViewAndAdapterFactory) views[i];
64                        String editorId = viewer.getView().getAttribute("editorID");
65                        if (activeEditorId.equals(editorId))
66                                return true;
67                }
68                return false;
69        }
70 
71        /**
72         * @return - actions, which are present in Menu/Visualization
73         */
74        public static IConfigurationElement[] getConfigurationElements() {
75                IConfigurationElement[] configurationElements = Platform
76                                .getExtensionRegistry().getConfigurationElementsFor(
77                                                "de.uka.ipd.sdq.sensorframework.visualisation");
78                return configurationElements;
79        }
80 
81        /**
82         * show message use the MessageDialog. DialogTitle is a curent name of
83         * active editor
84         */
85        public static void showMessage(Shell shell) {
86                String msg = "This View do not support the representation of the selected sensor!";
87 
88                String editorName = VisualisationPlugin.getDefault().getWorkbench()
89                                .getActiveWorkbenchWindow().getActivePage().getActiveEditor()
90                                .getTitle();
91 
92                MessageDialog.openInformation(shell, editorName, msg);
93        }
94        
95        /**
96         * The method get a selected action from 'ActionListSelectionDialog'.
97         * 
98         * @return - choose Action from ActionListSelectionDialog
99         */
100        public static ViewAndAdapterFactory getSelectedAction(Shell shell,
101                        Object[] elements) {
102                ActionListSelectionDialog dialog = new ActionListSelectionDialog(shell,
103                                new DialogLabelProvider());
104 
105                dialog.setElements(elements);
106                dialog.open();
107                Object[] results = dialog.getResult();
108                if (results != null)
109                        return (ViewAndAdapterFactory) results[0];
110                else
111                        return null;
112        }
113}
114 
115/** The Class define the LabelProvider for ActionListSelectionDialog. */
116class DialogLabelProvider extends LabelProvider {
117        
118        /* (non-Javadoc)
119         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
120         */
121        @Override
122        public String getText(Object element) {
123                if (element instanceof ViewAndAdapterFactory) {
124                        ViewAndAdapterFactory viewAndAdapter = (ViewAndAdapterFactory) element;
125                        String displayName = viewAndAdapter.getView().getAttribute("displayName");
126                        return displayName.replace("{0}",viewAndAdapter.getFactory() == null ? "" : viewAndAdapter.getFactory().getMetricLabel());
127                }
128                return super.getText(element);
129        }
130}

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