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

import be.iminds.ilabt.jfed.experimenter_gui.config.AdvertisementFetchManager;
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.FXModelRspec;
import be.iminds.ilabt.jfed.rspec.model.javafx_impl.FXRspecChannel;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.Window;

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

/**
 * User: twalcari
 * Date: 12/2/2014
 * Time: 14:45
 */
@Singleton
public class ChannelPropertiesDialogFactory {

    private final TestbedInfoSource testbedInfoSource;
    private final AdvertisementFetchManager advertisementFetchManager;

    @Inject
    public ChannelPropertiesDialogFactory(TestbedInfoSource testbedInfoSource, AdvertisementFetchManager advertisementFetchManager) {
        this.testbedInfoSource = testbedInfoSource;
        this.advertisementFetchManager = advertisementFetchManager;
    }

    public ChannelPropertiesDialog createChannelPropertiesDialog(FXRspecChannel channel, FXModelRspec modelRspec) {
        return new ChannelPropertiesDialog(channel, modelRspec, testbedInfoSource, advertisementFetchManager);
    }

    public boolean showChannelPropertiesDialog(Window parent, FXRspecChannel channel, FXModelRspec modelRspec) {
        final ChannelPropertiesDialog channelPropertiesDialog = createChannelPropertiesDialog(channel, modelRspec);
        Scene scene = new Scene(channelPropertiesDialog);

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


        dialogStage.setTitle("Channel properties");
        dialogStage.setMinHeight(300);
        dialogStage.setMaxHeight(300);
        dialogStage.setMinWidth(500);
        FXUtils.centerToOwner(parent, dialogStage);

        dialogStage.showAndWait();

        return channelPropertiesDialog.isSuccess();
    }
}
