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

import be.iminds.ilabt.jfed.experimenter_gui.editor.ModelRspecEditor;
import be.iminds.ilabt.jfed.experimenter_gui.util.ui.FXUtils;
import be.iminds.ilabt.jfed.ui.javafx.util.StageUtils;

import be.iminds.ilabt.jfed.lowlevel.TestbedInfoSource;
import be.iminds.ilabt.jfed.rspec.model.javafx_impl.FXRspecLink;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.Window;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * User: twalcari
 * Date: 12/5/2014
 * Time: 11:48
 */
@Singleton
public class LinkPropertiesDialogFactory {

    private final TestbedInfoSource testbedInfoSource;

    @Inject
    public LinkPropertiesDialogFactory(TestbedInfoSource testbedInfoSource) {
        this.testbedInfoSource = testbedInfoSource;
    }

    public void showLinkPropertiesDialog(Window parentWindow, ModelRspecEditor modelRspecEditor, FXRspecLink link) {
        //check if the link is in a valid state before showing the configuration window
        if (!LinkPropertiesDialog.validateIncomingLink(link))
            return;

        Scene scene = new Scene(new LinkPropertiesDialog(modelRspecEditor, link, testbedInfoSource));

        Stage dialogStage = new Stage();
        StageUtils.setJFedStageIcons(dialogStage);
        dialogStage.setScene(scene);

        dialogStage.setTitle("Properties of " + link.getClientId());
        dialogStage.setResizable(false);
        FXUtils.centerToOwner(parentWindow, dialogStage);
        dialogStage.showAndWait();
    }

}
