package de.prob2.ui.menu;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import de.prob2.ui.dotty.DotView;
import de.prob2.ui.internal.StageManager;
import de.prob2.ui.visualisation.fx.VisualisationController;
import javafx.fxml.FXML;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Christoph Heinzen
 * @since 21.09.17
 */
@Singleton
public class VisualisationMenu extends Menu{

	private static final Logger LOGGER = LoggerFactory.getLogger(VisualisationMenu.class);

	@FXML
	private MenuItem openVisualisationItem;

	@FXML
	private MenuItem stopVisualisationItem;

	@FXML
	private MenuItem detachVisualisationItem;

	private final VisualisationController visualisationController;
	
	private final DotView dotView;

	@Inject
	public VisualisationMenu(final StageManager stageManager, final VisualisationController visualisationController, final DotView dotView) {
		this.visualisationController = visualisationController;
		this.dotView = dotView;
		stageManager.loadFXML(this, "visualisationMenu.fxml");
	}

	@FXML
	public void initialize() {
		LOGGER.debug("Initializing the visualization-menu!");
		openVisualisationItem.disableProperty().bind(visualisationController.currentMachineProperty().isNull());
		stopVisualisationItem.disableProperty().bind(visualisationController.visualisationProperty().isNull());
		detachVisualisationItem.disableProperty()
				.bind(visualisationController.visualisationProperty().isNull().or(visualisationController.detachProperty()));
	}

	@FXML
	private void stopVisualisation() {
		LOGGER.debug("Stop menu-item called.");
		visualisationController.stopVisualisation();
	}

	@FXML
	private void openVisualisation() {
		LOGGER.debug("Open menu-item called.");
		visualisationController.openVisualisation();
	}

	@FXML 
	void detachVisualisation() {
		LOGGER.debug("Detach menu-item called.");
		visualisationController.detachVisualisation();
	}
	
	@FXML
	private void showCurrentState() {
		dotView.show();
	}
	

}

@@ -800,16 +800,18 @@
 ler;%0A%09%0A%09
+//
 private 
@@ -955,16 +955,18 @@
 ntroller
+/*
 , final 
@@ -980,16 +980,18 @@
  dotView
+*/
 ) %7B%0A%09%09th
@@ -1046,16 +1046,18 @@
 ller;%0A%09%09
+//
 this.dot
@@ -2008,16 +2008,18 @@
 ;%0A%09%7D%0A%09%0A%09
+/*
 @FXML%0A%09p
@@ -2071,14 +2071,16 @@
 ow();%0A%09%7D
+*/
 %0A%09%0A%0A%7D%0A

comment out dot view part in VisualisationMenu to remove bug (Location not set in DotView constructor)