package de.prob2.ui.verifications.ltl;


import com.google.inject.Inject;
import com.google.inject.Injector;

import de.prob2.ui.internal.StageManager;
import de.prob2.ui.prob2fx.CurrentTrace;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class LTLFormulaStage extends Stage {
	
	
		
	@FXML
	private TextArea ta_formula;
	
	@FXML
	private Button checkFormulaButton;
	
	private final CurrentTrace currentTrace;
	
	private LTLFormulaItem item;
	
	private Injector injector;
		
	@Inject
	private LTLFormulaStage(final StageManager stageManager, final Injector injector, final CurrentTrace currentTrace) {
		this.injector = injector;
		this.currentTrace = currentTrace;
		this.item = null;
		stageManager.loadFXML(this, "ltlformula_stage.fxml");
	}
	
	@FXML
	public void initialize() {
		ta_formula.textProperty().addListener((observable, oldValue, newValue) -> item.setFormula(newValue));
		checkFormulaButton.disableProperty().bind(currentTrace.existsProperty().not());
	}
	
	public void setItem(LTLFormulaItem item) {
		this.item = item;
		ta_formula.setText(item.getFormula());
	}
	
	@FXML
	private void handleSave() {
		
	}
	
	@FXML
	private void handleClose() {
		this.close();
	}
	
	@FXML
	public void checkFormula() {
		injector.getInstance(LTLView.class).checkFormula(item);
	}
	

}

@@ -34,16 +34,68 @@
 .ltl;%0A%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import c
@@ -119,16 +119,16 @@
 Inject;%0A
-
 import c
@@ -197,16 +197,59 @@
 anager;%0A
+import de.prob2.ui.prob2fx.CurrentProject;%0A
 import d
@@ -459,13 +459,8 @@
 %7B%0A%09%0A
-%09%0A%09%09%0A
 %09@FX
@@ -579,24 +579,72 @@
 entTrace;%0A%09%0A
+%09private final CurrentProject currentProject;%0A%09%0A
 %09private LTL
@@ -817,16 +817,60 @@
 entTrace
+,%0A%09%09%09%09%09%09%09final CurrentProject currentProject
 ) %7B%0A%09%09th
@@ -929,16 +929,56 @@
 tTrace;%0A
+%09%09this.currentProject = currentProject;%0A
 %09%09this.i
@@ -1165,33 +1165,304 @@
  -%3E 
-item.setFormula(newValue)
+%7B%0A%09%09%09List%3CLTLFormulaItem%3E newFormulas = new ArrayList%3C%3E(currentProject.getLtlFormulas());%0A%09%09%09int index = newFormulas.indexOf(item);%0A%09%09%09item.setFormula(newValue);%0A%09%09%09if(index != -1) %7B%0A%09%09%09%09newFormulas.set(index, new LTLFormulaItem(item));%0A%09%09%09%7D%0A%09%09%09currentProject.refreshLTLFormulas(newFormulas);%0A%09%09%7D
 );%0A%09

Update triggering unsaved changes