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

import be.iminds.ilabt.jfed.experimenter_gui.config.JFedGuiConfig;
import be.iminds.ilabt.jfed.experimenter_gui.editor.views.EditorViewType;
import be.iminds.ilabt.jfed.experimenter_gui.gts_editor.views.RawGtsDslEditor;
import be.iminds.ilabt.jfed.experimenter_gui.ui.ribbon.RibbonButton;
import be.iminds.ilabt.jfed.lowlevel.TestbedInfoSource;
import be.iminds.ilabt.jfed.ui.javafx.FXMLUtil;
import javafx.fxml.FXML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: twalcari
 * Date: 7/1/2014
 * Time: 11:10
 */
public class GTSRawEditorRibbonTab extends GTSEditorRibbonTab {
    private static final Logger LOG = LoggerFactory.getLogger(GTSRawEditorRibbonTab.class);

    private JFedGuiConfig jFedConfiguration;
    private TestbedInfoSource testbedInfoSource;

    @FXML
    private RibbonButton verifyCodeButton;
    @FXML
    private RibbonButton searchCodeButton;
    @FXML
    private RibbonButton replaceCodeButton;

    public GTSRawEditorRibbonTab() {
        FXMLUtil.injectFXML(this, aClass -> {
            if (aClass == GTSGenericEditorRibbonComponentGroupController.class) {
                return new GTSGenericEditorRibbonComponentGroupController(this);
            }
            throw new RuntimeException("Unexpected class in ControllerFactory: " + aClass.getName());
        });

        setOnSelectionChanged(event -> {
            if (isSelected() && getActiveGtsEditor().getCurrentEditorViewType() != EditorViewType.RAW) {
                getActiveGtsEditor().trySwitchToEditorViewByType(EditorViewType.RAW); //this should always go OK!
            }
        });

    }

    public void setJFedGuiConfig(JFedGuiConfig conf) {
        this.jFedConfiguration = conf;
    }

    public void setAuthorityList(TestbedInfoSource testbedInfoSource) {
        this.testbedInfoSource = testbedInfoSource;
    }

    private RawGtsDslEditor getActiveRawRspecEditor() {
        assert (getActiveGtsEditor().getCurrentEditorViewType() == EditorViewType.RAW);

        return (RawGtsDslEditor) getActiveGtsEditor().getCurrentEditorView();
    }


    @FXML
    private void onVerifyGtsAction() {
        //TODO implement
    }

    @FXML
    private void onSearchAction() {
        getActiveRawRspecEditor().showSearch();
    }

    @FXML
    private void onReplaceAction() {
        getActiveRawRspecEditor().showReplace();
    }

}
