1 | package de.uka.ipd.sdq.sensorframework.visualisation.editor; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | import java.util.Observable; |
6 | |
7 | import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset; |
8 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
9 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
10 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
11 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
12 | |
13 | /** |
14 | * TODO: Document me! What do I do? |
15 | * @author ? |
16 | * |
17 | */ |
18 | public class ConfigEntry extends Observable { |
19 | private List<Long> sensorIDs; |
20 | private long experimentRunID; |
21 | private long experimentID; |
22 | private long datasourceID; |
23 | |
24 | public ConfigEntry(IDAOFactory factory, ExperimentRun experimentRun, Experiment experiment, |
25 | Sensor sensor) { |
26 | this.datasourceID = factory.getID(); |
27 | this.experimentRunID = experimentRun.getExperimentRunID(); |
28 | this.experimentID = experiment.getExperimentID(); |
29 | this.sensorIDs = new ArrayList<Long>(); |
30 | if (sensor != null) |
31 | this.sensorIDs.add(sensor.getSensorID()); |
32 | } |
33 | |
34 | public List<Sensor> getSensors() { |
35 | ArrayList<Sensor> result = new ArrayList<Sensor>(); |
36 | for (long sensorID : this.sensorIDs) |
37 | result.add(getDatasource().createSensorDAO().get(sensorID)); |
38 | return result; |
39 | } |
40 | |
41 | /** |
42 | * Adds the given Sensor (or its id, respectively) to the list of |
43 | * sensors of this ConfigEntry. TODO: What does that mean? Are these the |
44 | * sensors shown in one diagram, for example? |
45 | * @param sensor |
46 | */ |
47 | public void setSensorChecked(Sensor sensor) { |
48 | if (!isSensorChecked(sensor)){ |
49 | sensorIDs.add(sensor.getSensorID()); |
50 | this.setChanged(); |
51 | } |
52 | notifyObservers(); |
53 | } |
54 | |
55 | public void setSensorUnchecked(Sensor sensor) { |
56 | sensorIDs.remove(sensor.getSensorID()); |
57 | this.setChanged(); |
58 | notifyObservers(); |
59 | } |
60 | |
61 | /** |
62 | * @return - status of sensor (checked/unchecked) |
63 | */ |
64 | public boolean isSensorChecked(Sensor sensor) { |
65 | if (sensorIDs != null) { |
66 | return sensorIDs.contains(sensor.getSensorID()); |
67 | } |
68 | return false; |
69 | } |
70 | |
71 | public ExperimentRun getExperimentRun() { |
72 | return getDatasource().createExperimentRunDAO().get(experimentRunID); |
73 | } |
74 | |
75 | public Experiment getExperiment() { |
76 | return getDatasource().createExperimentDAO().get(experimentID); |
77 | } |
78 | |
79 | public void setExperiment(Experiment experiment) { |
80 | this.experimentID = experiment.getExperimentID(); |
81 | } |
82 | |
83 | public IDAOFactory getDatasource() { |
84 | return SensorFrameworkDataset.singleton().getDataSourceByID(this.datasourceID); |
85 | } |
86 | } |