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

import be.iminds.ilabt.jfed.fedmon.webapi.service.json.Resource;
import be.iminds.ilabt.jfed.ui.javafx.GlyphUtils;
import be.iminds.ilabt.jfed.ui.javafx.GuiceFXMLUtil;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.paint.Color;
import org.controlsfx.glyphfont.FontAwesome;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;

/**
 * User: twalcari
 * Date: 9/11/2014
 * Time: 11:57
 */
public class SelectDiskImageDialog extends Dialog<String> {
    private static final Logger LOG = LoggerFactory.getLogger(SelectDiskImageDialog.class);


    private final SelectDiskImageController controller;

    @Inject
    public SelectDiskImageDialog(GuiceFXMLUtil guiceFXMLUtil) {
        GuiceFXMLUtil.Result<?, SelectDiskImageController> fxmlResult =
                guiceFXMLUtil.createFromFXML(SelectDiskImageController.class);
        this.controller = fxmlResult.getController();

        setTitle("Select Disk Image");
        getDialogPane().setContent(fxmlResult.getRoot());
        setGraphic(GlyphUtils.createDialogGlyph(FontAwesome.Glyph.HDD_ALT, Color.BLACK));

        ButtonType selectDiskImageButtonType = new ButtonType("Select Disk Image", ButtonBar.ButtonData.OK_DONE);
        getDialogPane().getButtonTypes().setAll(selectDiskImageButtonType, ButtonType.CANCEL);

        setResultConverter(param -> {
            if (param == selectDiskImageButtonType) {
                return controller.getDiskImageString();
            } else
                return null;
        });
    }


    public void setResource(Resource nodeResource) {
        this.controller.setResource(nodeResource);
    }


}
