| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.views; |
| 2 | |
| 3 | import org.eclipse.jface.viewers.LabelProvider; |
| 4 | import org.eclipse.swt.graphics.Image; |
| 5 | import org.eclipse.ui.ISharedImages; |
| 6 | import org.eclipse.ui.PlatformUI; |
| 7 | |
| 8 | import de.uka.ipd.sdq.sensorframework.dialogs.dataset.DatasourceListLabelProvider; |
| 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 | import de.uka.ipd.sdq.sensorframework.visualisation.VisualisationImages; |
| 13 | |
| 14 | /** |
| 15 | * The label provider to define how model objects should be presented in the |
| 16 | * view. Each view can present the same model objects using different labels and |
| 17 | * icons, if needed. Alternatively, a single label provider can be shared |
| 18 | * between views in order to ensure that objects of the same type are presented |
| 19 | * in the same way everywhere. |
| 20 | * |
| 21 | */ |
| 22 | public class TreeLabelProvider extends LabelProvider { |
| 23 | |
| 24 | /* (non-Javadoc) |
| 25 | * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
| 26 | */ |
| 27 | @Override |
| 28 | public String getText(Object obj) { |
| 29 | if (obj instanceof ExperimentAndDAO) |
| 30 | return ((ExperimentAndDAO) obj).getExperiment().getExperimentName(); |
| 31 | |
| 32 | if (obj instanceof TreeContainer) |
| 33 | return ((TreeContainer) obj).getName(); |
| 34 | |
| 35 | if (obj instanceof TreeObject) { |
| 36 | TreeObject object = (TreeObject) obj; |
| 37 | |
| 38 | if (object.getObject() instanceof ExperimentRun) { |
| 39 | ExperimentRun run = (ExperimentRun) object.getObject(); |
| 40 | return runRepresentation(run); |
| 41 | } |
| 42 | |
| 43 | if (object.getObject() instanceof Sensor) { |
| 44 | Sensor sensor = (Sensor) object.getObject(); |
| 45 | if (object.isEmpty()) |
| 46 | return "EMPTY -"+ sensorRepresentation(sensor); |
| 47 | return sensorRepresentation(sensor); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (obj instanceof IDAOFactory) { |
| 52 | IDAOFactory factory = (IDAOFactory) obj; |
| 53 | return DatasourceListLabelProvider.dataSetRepresentation(factory); |
| 54 | } |
| 55 | |
| 56 | return obj.toString(); |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * (non-Javadoc) |
| 61 | * |
| 62 | * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) |
| 63 | */ |
| 64 | @Override |
| 65 | public Image getImage(Object obj) { |
| 66 | |
| 67 | if (obj instanceof ExperimentAndDAO) |
| 68 | return VisualisationImages.imageRegistry.get(VisualisationImages.EXPERIMENT); |
| 69 | |
| 70 | if (obj instanceof TreeContainer){ |
| 71 | String icon = ""; |
| 72 | TreeContainer container = (TreeContainer) obj; |
| 73 | switch (container.getType()) { |
| 74 | case TreeContentProvider.EXPERIMENT_RUNS: |
| 75 | icon = VisualisationImages.RUNS; |
| 76 | break; |
| 77 | case TreeContentProvider.SENSORS: |
| 78 | icon = VisualisationImages.SENSORS; |
| 79 | break; |
| 80 | } |
| 81 | return VisualisationImages.imageRegistry.get(icon); |
| 82 | } |
| 83 | |
| 84 | if (obj instanceof TreeObject) { |
| 85 | TreeObject object = (TreeObject) obj; |
| 86 | |
| 87 | if (object.getObject() instanceof ExperimentRun) |
| 88 | return VisualisationImages.imageRegistry.get(VisualisationImages.RUN); |
| 89 | |
| 90 | if (object.getObject() instanceof Sensor) |
| 91 | return VisualisationImages.imageRegistry.get(VisualisationImages.SENSOR); |
| 92 | } |
| 93 | |
| 94 | if (obj instanceof IDAOFactory) |
| 95 | return VisualisationImages.imageRegistry.get(VisualisationImages.TREEROOT); |
| 96 | |
| 97 | return PlatformUI.getWorkbench().getSharedImages().getImage( |
| 98 | ISharedImages.IMG_OBJ_ELEMENT); |
| 99 | } |
| 100 | |
| 101 | public String sensorRepresentation(Sensor sensor) { |
| 102 | return sensor.getSensorName() + " [ID:" + sensor.getSensorID() + "]"; |
| 103 | } |
| 104 | |
| 105 | public String runRepresentation(ExperimentRun run) { |
| 106 | return run.getExperimentDateTime() + " [ID:" + run.getExperimentRunID() + "]"; |
| 107 | } |
| 108 | } |