package be.iminds.ilabt.jfed.experimenter_gui.editor.properties;

import be.iminds.ilabt.jfed.rspec.model.javafx_impl.FXRspecNode;import javafx.scene.control.Tab;

/**
 * User: twalcari
 * Date: 4/10/2014
 * Time: 12:03
 */
public abstract class AdaptivePropertiesTab<N extends FXRspecNode> extends Tab {

    public AdaptivePropertiesTab(String s) {
        super(s);
    }

    //instance initializer
    {
        setClosable(false);

        selectedProperty().addListener(observable -> {
            if (isSelected()) {
                onTabShown();
            }
        });
    }


    /**
     * Loads the configuration from a given node instance into the dialog window.
     * This method is called when the user switches to the tab, so that dependent settings in other tabs
     * can be interpreted.
     *
     * @param rspecNode
     */
    public abstract void load(N rspecNode);

    /**
     * Saves the configuration from the dialog to the given node instance
     *
     * @param rspecNode
     */
    public abstract void save(N rspecNode);

    /**
     * This function is called when the tab is about to become visible
     */
    public abstract void onTabShown();

    /**
     * This method determines whether the tab should be visible in the properties-dialog. We suppose that the tab
     * has enough information to determine this.
     *
     * @return
     */

    public abstract boolean shouldBeVisible(FXRspecNode rspecNode);


    /**
     * This function should return null if validation of the configuration in the tab is OK. Otherwise, it should
     * return an error message.
     *
     * @return
     */
    public abstract String validateConfiguration();
}
