User Tools

Site Tools


zalozeni:grafika:experimenttabs:export

Export namerenych dat

Pro export namerenych dat neni vytvorena zadna podpurna grafika v marklar-fx-common. Vse je treba si od zakladu vytvorit. Grafika by se mela opirat o ExportService, ktera je k dispozici u kazdeho ExperimentType. Jelikoz pri vykreslovani praveho panelu je vzdy k dispozici ExperimentInstance, doporucuji controller pro ovladani zalozky s merenim odvodit od ExperimentInstanceController. Konkretni implementace muze vypadat nasledovne.

public class DokuwikiExportTabController extends ExperimentInstanceController {
 
	@FXML
	private TextField edtDirectory;
	@FXML
	private TextField edtFileName;
	@FXML
	private CheckBox cbTXT;
	@FXML
	private CheckBox cbCSV;
	@FXML
	private CheckBox cbPDF;
 
	private ExpTypeSettingsService expTypeSS;
	private Sample sample;
 
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
	}
 
	@Override
	public void setExpInstance(ExperimentInstance expInstance) {
		super.setExpInstance(expInstance);
		sample = expInstance.getSample();
 
		expTypeSS = expInstance.getExperimentType().getExpDefaultSettingsService();
		edtDirectory.setText(expTypeSS.getDataExportPath());
 
		edtFileName.setText(String.format("%05d", sample.getId()) + "_" + sample.getName());
	}
 
	@Override
	public void repaint() {
		// TODO Auto-generated method stub
	}
 
	@Override
	public void newData(Object dataRow) {
		// TODO Auto-generated method stub
	}
 
	@FXML
	private void chooseDirectory() {
		final DirectoryChooser directoryChooser = new DirectoryChooser();
		final File selectedDirectory = directoryChooser.showDialog(new Stage());
		if (selectedDirectory != null) {
			String path = selectedDirectory.getAbsolutePath();
			edtDirectory.setText(path);
			expTypeSS.setDataExportPath(path);
		}
	}
 
	@FXML
	private void export() {
		String directoryName = edtDirectory.getText() + File.separator + edtFileName.getText() + File.separator;
		File directory = new File(directoryName);
		if (!directory.exists()) {
			try {
				directory.mkdirs();
			} catch (Exception e) {
				LogService.getInstance().info("Chyba pri vytvareni adresare " + directoryName);
				e.printStackTrace();
			}
		}
 
		Map<ExperimentType, List<ExperimentInstance>> map = ServiceLocator.getInstance().getExperimentService()
				.getGroupedExperimentForSample(sample);
 
		for (Map.Entry<ExperimentType, List<ExperimentInstance>> experimentTypeEntry : map.entrySet()) {
			String fileName = directoryName + experimentTypeEntry.getKey().getName();
 
			if (cbTXT.isSelected()) {
				try {
					expType.getExperimentExportService(experimentTypeEntry.getValue()).exportAsTXT(fileName);
					LogService.getInstance().info("TXT uspesne vytvoreno");
				} catch (IOException e) {
					LogService.getInstance().info("TXT nevytvoreno. Existuje zvoleny adresar? Ma prislusna opravneni?");
					e.printStackTrace();
				}
			}
 
			if (cbCSV.isSelected()) {
				try {
					expType.getExperimentExportService(experimentTypeEntry.getValue()).exportAsCSV(fileName);
					LogService.getInstance().info("CSV uspesne vytvoreno");
				} catch (IOException e) {
					LogService.getInstance().info("CSV nevytvoreno. Existuje zvoleny adresar? Ma prislusna opravneni?");
					e.printStackTrace();
				}
			}
 
			if (cbPDF.isSelected()) {
				ComplexTask task = new ComplexTask() {
					@Override
					protected void runThis() {
						try {
							expType.getExperimentExportService(experimentTypeEntry.getValue()).exportAsPDF(fileName);
							LogService.getInstance().info("PDF uspesne vytvoreno");
						} catch (IOException e) {
							LogService.getInstance().info("PDF nevytvoreno. Existuje zvoleny adresar? Ma prislusna opravneni?");
							e.printStackTrace();
						}
					}
				};
				ControllersLocator.getInstance().getStandardLayoutController().getMainPane().disableProperty().bind(task.runningProperty());
				task.start();
			}
		}
	}
}
zalozeni/grafika/experimenttabs/export.txt · Last modified: 2016/07/25 13:49 by jlochman