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

COVERAGE SUMMARY FOR SOURCE FILE [TreeContentProvider.java]

nameclass, %method, %block, %line, %
TreeContentProvider.java0%   (0/1)0%   (0/8)0%   (0/200)0%   (0/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TreeContentProvider0%   (0/1)0%   (0/8)0%   (0/200)0%   (0/49)
TreeContentProvider (): void 0%   (0/1)0%   (0/3)0%   (0/1)
createExperimentAndDAOList (IDAOFactory, Collection): List 0%   (0/1)0%   (0/25)0%   (0/4)
dispose (): void 0%   (0/1)0%   (0/7)0%   (0/3)
getChildren (Object): Object [] 0%   (0/1)0%   (0/117)0%   (0/28)
getElements (Object): Object [] 0%   (0/1)0%   (0/16)0%   (0/3)
getParent (Object): Object 0%   (0/1)0%   (0/2)0%   (0/1)
hasChildren (Object): boolean 0%   (0/1)0%   (0/29)0%   (0/8)
inputChanged (Viewer, Object, Object): void 0%   (0/1)0%   (0/1)0%   (0/1)

1package de.uka.ipd.sdq.sensorframework.visualisation.views;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6 
7import org.eclipse.jface.viewers.ITreeContentProvider;
8import org.eclipse.jface.viewers.Viewer;
9 
10import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset;
11import de.uka.ipd.sdq.sensorframework.entities.Experiment;
12import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun;
13import de.uka.ipd.sdq.sensorframework.entities.Sensor;
14import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
15import de.uka.ipd.sdq.sensorframework.entities.dao.IExperimentDAO;
16 
17/**
18 * TODO
19 * @author admin
20 */
21public class TreeContentProvider implements ITreeContentProvider {
22 
23        protected static final int EXPERIMENT_RUNS = 0;
24        protected static final int SENSORS = 1;
25 
26        private List<IDAOFactory> rootEntry;
27 
28        /* (non-Javadoc)
29         * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
30         */
31        public Object[] getElements(Object parent) {
32                rootEntry = new ArrayList<IDAOFactory>();
33                rootEntry.addAll(SensorFrameworkDataset.singleton().getDataSources());
34                return getChildren(rootEntry);
35        }
36 
37        /* (non-Javadoc)
38         * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
39         */
40        @SuppressWarnings("unchecked")
41        public Object[] getChildren(Object parent) {
42 
43                /** List of root elements (DAO,...) */
44                if (parent instanceof ArrayList)
45                        return ((ArrayList<IDAOFactory>) parent).toArray();
46 
47                /** ExperimentDAO */
48                if (parent instanceof IDAOFactory){
49                        IExperimentDAO experimentDAO = ((IDAOFactory)parent).createExperimentDAO();
50                        return createExperimentAndDAOList((IDAOFactory)parent,experimentDAO.getExperiments()).toArray();
51                }
52                
53                /** Experiment */
54                if (parent instanceof ExperimentAndDAO) {
55                        ExperimentAndDAO experiment = (ExperimentAndDAO) parent;
56                        Object[] objects = {
57                                        new TreeContainer(experiment.getDatasource(), experiment.getExperiment(), EXPERIMENT_RUNS),
58                                        new TreeContainer(experiment.getDatasource(), experiment.getExperiment(), SENSORS) };
59                        return objects;
60                }
61 
62                /** TreeObject - container of Sensor or ExperimentRun */
63                if (parent instanceof TreeObject) {
64                        TreeObject treeObject = (TreeObject) parent;
65                        if (treeObject.getObject() instanceof ExperimentRun) {
66                                ExperimentRun run = (ExperimentRun) treeObject.getObject();
67                                Experiment experiment = treeObject.getExperiment();
68                                Collection<Sensor> sensors = experiment.getSensors();
69                                
70                                TreeObject[] objects = new TreeObject[sensors.size()];
71                                
72                                int i = 0;
73                                for (Sensor sensor : sensors) {
74                                        objects[i++] = 
75                                                        new TreeObject(
76                                                                        sensor, treeObject.getDatasource(), experiment,
77                                                                        run);
78                                }
79                                return objects;
80 
81                        }
82                }
83 
84                /** TreeContainer - container a collection of TreeObject */
85                if (parent instanceof TreeContainer)
86                        return ((TreeContainer) parent).getElements().toArray();
87 
88                return new Object[0];
89        }
90 
91        private List<ExperimentAndDAO> createExperimentAndDAOList(
92                        IDAOFactory dao, Collection<Experiment> experiments){
93                ArrayList<ExperimentAndDAO>result = new ArrayList<ExperimentAndDAO>();
94                for(Experiment e:experiments)
95                        result.add(new ExperimentAndDAO(dao,e));
96                return result;
97        }
98 
99        /* (non-Javadoc)
100         * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
101         */
102        public boolean hasChildren(Object parent) {
103                if (parent instanceof TreeObject){
104                        TreeObject object = (TreeObject) parent;
105                        if (object.getObject() instanceof Sensor)
106                                return false;
107                }
108                
109                if (parent instanceof IDAOFactory) {
110                        IExperimentDAO experimentDAO = ((IDAOFactory)parent).createExperimentDAO();
111                        return !experimentDAO.getExperiments().isEmpty();
112                }
113                return true;
114        }
115 
116        /* (non-Javadoc)
117         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
118         */
119        public void dispose() {
120                if (rootEntry != null)
121                        rootEntry.clear();
122        }
123 
124        /* (non-Javadoc)
125         * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
126         */
127        public Object getParent(Object child) {
128                // TODO Auto-generated method stub
129                return null;
130        }
131 
132        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
133                // TODO Auto-generated method stub
134        }
135}

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