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

import be.iminds.ilabt.jfed.rspec.model.javafx_impl.FXRspecNode;
import be.iminds.ilabt.jfed.ui.javafx.FXMLUtil;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: twalcari
 * Date: 9/10/2014
 * Time: 09:44
 */
public class RoutableIPTab extends AdaptivePropertiesTab<FXRspecNode> {
    private static final Logger LOG = LoggerFactory.getLogger(RoutableIPTab.class);
    private static final String BOOT_SCRIPTS_FXML = "RoutableIPTab.fxml";

    private final AdaptivePropertiesDialog adaptivePropertiesDialog;

    @FXML
    private CheckBox routableIPCheckbox;


    public RoutableIPTab(AdaptivePropertiesDialog adaptivePropertiesDialog) {
        super("Routable Control IP");
        this.adaptivePropertiesDialog = adaptivePropertiesDialog;
        setContent(FXMLUtil.createFromFXML(this));
    }

    @Override
    public void load(FXRspecNode rspecNode) {
        routableIPCheckbox.setSelected(rspecNode.getRoutableControlIp());
    }

    @Override
    public void save(FXRspecNode rspecNode) {
        rspecNode.setRoutableControlIp(routableIPCheckbox.isSelected());
    }

    @Override
    public void onTabShown() {

    }

    @Override
    public boolean shouldBeVisible(FXRspecNode rspecNode) {
        final String currentSliverTypeName = adaptivePropertiesDialog.getCurrentSliverTypeName();
        return "emulab-xen".equals(currentSliverTypeName) ||
                "emulab-openvz".equals(currentSliverTypeName);
    }

    @Override
    public String validateConfiguration() {
        return null;
    }


//    public void onHelpLinkClicked() {
//        if(java.awt.Desktop.isDesktopSupported())
//        {
//            try {
//                java.awt.Desktop.getDesktop().browse(new URI("?"));
//            } catch (IOException | URISyntaxException e) {
//                LOG.warn("Exception starting browser", e);
//            }
//        }
//    }
}
