package de.prob2.ui.verifications.cbc;

import de.prob2.ui.internal.StageManager;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.stage.Modality;

import javax.inject.Inject;

import com.google.inject.Injector;

public class CBCDeadlock extends AbstractCBCFormulaInputStage {
		
	@FXML
	private TextField tfFormula;
	

	@Inject
	private CBCDeadlock(final StageManager stageManager, final CBCFormulaHandler cbcHandler,
						final Injector injector) {
		super(cbcHandler, injector);
		stageManager.loadFXML(this, "cbc_deadlock.fxml");
		this.initModality(Modality.APPLICATION_MODAL);
	}
	
	@FXML
	public void addFormula() {
		addFormula(false);
	}
	
	private void addFormula(boolean checking) {
		cbcHandler.addFormula(tfFormula.getText(), tfFormula.getText(), CBCFormulaItem.CBCType.DEADLOCK,
								checking);
		this.close();
	}
	
	@FXML
	public void checkFormula() {
		addFormula(true);
		cbcHandler.checkDeadlock(tfFormula.getText());
		this.close();
	}
	
	public void changeFormula(CBCFormulaItem item) {
		super.changeFormula(tfFormula, item);
	}
	
	
	@FXML
	public void cancel() {
		this.close();
	}
		
}

@@ -128,25 +128,105 @@
 control.
-TextField
+Alert;%0Aimport javafx.scene.control.TextField;%0Aimport javafx.scene.control.Alert.AlertType
 ;%0Aimport
@@ -797,16 +797,108 @@
 king) %7B%0A
+%09%09if(%22FIND DEADLOCK%22.equals(tfFormula.getText())) %7B%0A%09%09%09showInvalidFormula();%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09cbcHan
@@ -1057,32 +1057,124 @@
 heckFormula() %7B%0A
+%09%09if(%22FIND DEADLOCK%22.equals(tfFormula.getText())) %7B%0A%09%09%09showInvalidFormula();%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09addFormula(tru
@@ -1375,16 +1375,16 @@
 cel() %7B%0A
-
 %09%09this.c
@@ -1394,13 +1394,251 @@
 e();%0A%09%7D%0A
+%09%0A%09public void showInvalidFormula() %7B%0A%09%09Alert alert = new Alert(AlertType.INFORMATION);%0A%09%09alert.setTitle(%22Invalid Formula%22);%0A%09%09alert.setHeaderText(%22Invalid Formula%22);%0A%09%09alert.setContentText(%22Formula is valid!%22);%0A%09%09alert.showAndWait();%0A%09%7D%0A
 %09%09%0A%7D%0A

Update CBCDeadlock