| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.views; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | |
| 6 | |
| 7 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
| 8 | import de.uka.ipd.sdq.sensorframework.visualisation.IVisualisation; |
| 9 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.IReportItem; |
| 10 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reports.RReport; |
| 11 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.utils.RConnection; |
| 12 | |
| 13 | /**Abstract class with basic capabilities to show reports containing |
| 14 | * data of the SensorFramework in R. |
| 15 | * @author groenda |
| 16 | */ |
| 17 | public abstract class AbstractHtmlRReportView extends AbstractHtmlReportView |
| 18 | implements IVisualisation < SensorAndMeasurements > { |
| 19 | |
| 20 | /**Delegates the creation to the ancestor and does nothing else. |
| 21 | */ |
| 22 | public AbstractHtmlRReportView() { |
| 23 | super(); |
| 24 | } |
| 25 | |
| 26 | /**Used to ask for the report that should be displayed. |
| 27 | * @return The report that should be displayed by this view. |
| 28 | */ |
| 29 | abstract public RReport getReport(); |
| 30 | |
| 31 | /** {@inheritDoc} |
| 32 | */ |
| 33 | public void setInput(final Collection < SensorAndMeasurements > c) { |
| 34 | if (RConnection.isEngineAvailable()) { |
| 35 | if (c.isEmpty()) { |
| 36 | browser.setText("<html><body><h1>Error! </h1>At least " |
| 37 | + "the measurements for one sensor must be " |
| 38 | + "available!</body></html>"); |
| 39 | } else { |
| 40 | if (getReport() == null) { |
| 41 | browser.setText("<html><body><h1>Error!</h1> There " |
| 42 | + "is no report associated with this view. " |
| 43 | + "Ask the developer to correct this error. " |
| 44 | + "</body></html>"); |
| 45 | } else { |
| 46 | RConnection rConnection = RConnection.getRConnection(); |
| 47 | ArrayList<IReportItem> items = |
| 48 | getReport().prepareReportItems(c, rConnection); |
| 49 | |
| 50 | HTMLVisitor visitor = new HTMLVisitor(); |
| 51 | for (IReportItem item : items) { |
| 52 | item.generateData(rConnection); |
| 53 | item.visit(visitor); |
| 54 | } |
| 55 | browser.setText(visitor.getHTML()); |
| 56 | } |
| 57 | } |
| 58 | } else { |
| 59 | browser.setText("<html><body><h1>Error! </h1>Connection to R " |
| 60 | + "engine is not available!</body></html>"); |
| 61 | } |
| 62 | } |
| 63 | } |