package be.iminds.ilabt.jfed.experimenter_gui.slice.ribbon_tabs;

import be.iminds.ilabt.jfed.experimenter_gui.slice.events.ExportToolsConfigFilesEvent;
import be.iminds.ilabt.jfed.experimenter_gui.slice.events.SaveExperimentEvent;
import be.iminds.ilabt.jfed.experimenter_gui.ui.ribbon.RibbonButton;
import be.iminds.ilabt.jfed.ui.javafx.FXMLUtil;
import com.google.common.eventbus.EventBus;
import javafx.fxml.FXML;

/**
 * User: twalcari
 * Date: 7/1/2014
 * Time: 17:31
 */
public class RspecViewerRibbonTab extends SliceRibbonTab {
    private final EventBus eventBus;

    @FXML
    private RibbonButton saveExperimentButton;

    @FXML
    private RibbonButton saveNodeLoginInfoButton;

    public RspecViewerRibbonTab(EventBus eventBus) {
        this.eventBus = eventBus;

        FXMLUtil.injectFXML(this, aClass -> {
            if (aClass == GenericSliceRibbonComponentGroupController.class) {
                return new GenericSliceRibbonComponentGroupController(RspecViewerRibbonTab.this, eventBus);
            } else if (aClass == AdvancedSliceRibbonComponentGroupController.class) {
                return new AdvancedSliceRibbonComponentGroupController(RspecViewerRibbonTab.this, eventBus);
            }
            throw new RuntimeException("Unexpected class in ControllerFactory: " + aClass.getName());
        });

        setOnSelectionChanged(event -> {
            if (isSelected() && !getActiveExperimentViewController().isRawRspecVisible()) {
                getActiveExperimentViewController().switchToRawView();
            }
        });
    }

    @FXML
    public void onSaveExperimentAction() {
        eventBus.post(new SaveExperimentEvent(getActiveExperimentViewController(), false  /*saveToCSV*/));
    }

    @FXML
    public void onSaveNodeLoginInfoAction() {
        eventBus.post(new SaveExperimentEvent(getActiveExperimentViewController(), true  /*saveToCSV*/));
    }

    @FXML
    public void onExportAction(){
        eventBus.post(new ExportToolsConfigFilesEvent(getActiveExperimentViewController()));
    }
}
