| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.views; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.List; |
| 6 | |
| 7 | import org.eclipse.core.runtime.IAdaptable; |
| 8 | |
| 9 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
| 10 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
| 11 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
| 12 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
| 13 | |
| 14 | /** |
| 15 | * @author roman |
| 16 | * |
| 17 | * The content provider class is responsible for providing objects to the view. |
| 18 | * It can wrap existing objects in adapters or simply return objects as-is. |
| 19 | * These objects may be sensitive to the current input of the view, or ignore it |
| 20 | * and always show the same content (like Task List, for example). |
| 21 | */ |
| 22 | public class TreeContainer implements IAdaptable { |
| 23 | |
| 24 | private Experiment experiment; |
| 25 | private List<TreeObject> elements = null; |
| 26 | private String name; |
| 27 | private int type; |
| 28 | |
| 29 | private String EXPERIMENT_RUNS_NAME = "Experiment Runs"; |
| 30 | private String SENSORS_NAME = "Sensors"; |
| 31 | |
| 32 | /** |
| 33 | * REFACTORIN!! |
| 34 | * @param experiment |
| 35 | */ |
| 36 | public TreeContainer(IDAOFactory datasource, Experiment experiment, int type) { |
| 37 | this.experiment = experiment; |
| 38 | this.type = type; |
| 39 | this.elements = new ArrayList<TreeObject>(); |
| 40 | |
| 41 | if (type == TreeContentProvider.EXPERIMENT_RUNS){ |
| 42 | Collection<ExperimentRun> runs = experiment.getExperimentRuns(); |
| 43 | for(ExperimentRun r : runs) |
| 44 | elements.add(new TreeObject(r,datasource,experiment)); |
| 45 | |
| 46 | this.name = EXPERIMENT_RUNS_NAME; |
| 47 | } |
| 48 | if (type == TreeContentProvider.SENSORS){ |
| 49 | Collection<Sensor> sensors = experiment.getSensors(); |
| 50 | for(Sensor s : sensors) |
| 51 | elements.add(new TreeObject (s,datasource,experiment)); |
| 52 | |
| 53 | this.name = SENSORS_NAME; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public List<TreeObject> getElements() { |
| 58 | return elements; |
| 59 | } |
| 60 | |
| 61 | public Experiment getParent() { |
| 62 | return experiment; |
| 63 | } |
| 64 | |
| 65 | public void setParent(Experiment parent) { |
| 66 | this.experiment = parent; |
| 67 | } |
| 68 | |
| 69 | @SuppressWarnings("unchecked") |
| 70 | public Object getAdapter(Class adapter) { |
| 71 | // if (adapter == de.uka.ipd.sdq.sensorfactory.entities.ExperimentRun.class) { |
| 72 | // this.elements = experiment.getExperimentRuns(); |
| 73 | // this.name = EXPERIMENT_RUNS_NAME; |
| 74 | // return this; |
| 75 | // } |
| 76 | // if (adapter == de.uka.ipd.sdq.sensorfactory.entities.Sensor.class) { |
| 77 | // this.elements = experiment.getSensors(); |
| 78 | // this.name = SENSORS_NAME; |
| 79 | // return this; |
| 80 | // } |
| 81 | return null; |
| 82 | } |
| 83 | |
| 84 | public String getName() { |
| 85 | return name; |
| 86 | } |
| 87 | |
| 88 | public int getType() { |
| 89 | return type; |
| 90 | } |
| 91 | } |