1 | package de.uka.ipd.sdq.sensorframework.visualisation.dialogs; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Collection; |
5 | import java.util.List; |
6 | |
7 | import org.eclipse.jface.viewers.ITreeContentProvider; |
8 | import org.eclipse.jface.viewers.Viewer; |
9 | |
10 | import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset; |
11 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
12 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
13 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
14 | import de.uka.ipd.sdq.sensorframework.entities.dao.IExperimentDAO; |
15 | import de.uka.ipd.sdq.sensorframework.visualisation.views.ExperimentAndDAO; |
16 | import de.uka.ipd.sdq.sensorframework.visualisation.views.TreeObject; |
17 | |
18 | /** @author roman */ |
19 | public class ExperimentRunsDialogContentProvider implements ITreeContentProvider { |
20 | |
21 | private List<IDAOFactory> root; |
22 | |
23 | /* (non-Javadoc) |
24 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
25 | */ |
26 | @SuppressWarnings("unchecked") |
27 | public Object[] getChildren(Object parent) { |
28 | |
29 | if (parent instanceof ArrayList) |
30 | return ((ArrayList<IDAOFactory>) parent).toArray(); |
31 | |
32 | if (parent instanceof IDAOFactory){ |
33 | IExperimentDAO experimentDAO = ((IDAOFactory)parent).createExperimentDAO(); |
34 | return createExperimentAndDAOList((IDAOFactory)parent,experimentDAO.getExperiments()).toArray(); |
35 | } |
36 | |
37 | if (parent instanceof ExperimentAndDAO) { |
38 | ExperimentAndDAO experiment = (ExperimentAndDAO) parent; |
39 | Collection<ExperimentRun> runs = experiment.getExperiment().getExperimentRuns(); |
40 | Object[] objects = new Object[runs.size()]; |
41 | int i = 0; |
42 | for (ExperimentRun r : runs) |
43 | objects[i++] = new TreeObject(r,experiment.getDatasource(), experiment.getExperiment()); |
44 | |
45 | return objects; |
46 | } |
47 | |
48 | |
49 | return new Object[0]; |
50 | } |
51 | |
52 | private List<ExperimentAndDAO> createExperimentAndDAOList( |
53 | IDAOFactory dao, Collection<Experiment> experiments){ |
54 | ArrayList<ExperimentAndDAO>result = new ArrayList<ExperimentAndDAO>(); |
55 | for(Experiment e:experiments) |
56 | result.add(new ExperimentAndDAO(dao,e)); |
57 | return result; |
58 | } |
59 | |
60 | /* (non-Javadoc) |
61 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
62 | */ |
63 | public Object getParent(Object element) { |
64 | // TODO Auto-generated method stub |
65 | return null; |
66 | } |
67 | |
68 | /* (non-Javadoc) |
69 | * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
70 | */ |
71 | public boolean hasChildren(Object element) { |
72 | if (element instanceof TreeObject){ |
73 | TreeObject object = (TreeObject) element; |
74 | if (object.getObject() instanceof ExperimentRun) |
75 | return false; |
76 | } |
77 | return true; |
78 | } |
79 | |
80 | /* (non-Javadoc) |
81 | * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
82 | */ |
83 | public Object[] getElements(Object inputElement) { |
84 | if (root == null){ |
85 | root = new ArrayList<IDAOFactory>(); |
86 | root.addAll(SensorFrameworkDataset.singleton().getDataSources()); |
87 | } |
88 | return getChildren(root); |
89 | } |
90 | |
91 | /* (non-Javadoc) |
92 | * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
93 | */ |
94 | public void dispose() { |
95 | // TODO Auto-generated method stub |
96 | |
97 | } |
98 | |
99 | /* (non-Javadoc) |
100 | * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
101 | */ |
102 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
103 | // TODO Auto-generated method stub |
104 | |
105 | } |
106 | |
107 | } |