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

import be.iminds.ilabt.jfed.experimenter_gui.timeline.view.TimelineView;
import be.iminds.ilabt.jfed.experimenter_gui.timeline.view.TimelineViewFactory;
import be.iminds.ilabt.jfed.experimenter_gui.timeline.view.dialogs.AddMultipleCommandDialog;
import be.iminds.ilabt.jfed.experimenter_gui.editor.ModelRspecEditor;
import be.iminds.ilabt.jfed.rspec.rspec_source.RequestRspecSource;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.layout.Region;

/**
 * User: twalcari
 * Date: 5/20/2015
 * Time: 12:18
 */
public class EditableControllerView implements EditableRspecView {


    private final ModelRspecEditor modelRspecEditor;
    private final TimelineView timelineView;

    private final StringProperty status = new SimpleStringProperty();

    public EditableControllerView(ModelRspecEditor modelRspecEditor, TimelineViewFactory timelineViewFactory) {
        this.modelRspecEditor = modelRspecEditor;
        this.timelineView = timelineViewFactory.createControllerUI(modelRspecEditor);
    }


    @Override
    public Region getView() {
        return timelineView;
    }

    @Override
    public EditorViewType getType() {
        return EditorViewType.CONTROLLER;
    }

    @Override
    public RequestRspecSource getRequestRspecSource() {
        return new RequestRspecSource(timelineView.getModelRspec());
    }

    @Override
    public void dispose() {
        timelineView.getController().unregister();
    }

    @Override
    public ReadOnlyStringProperty statusProperty() {
        return status;
    }

    public TimelineView getTimelineView() {
        return timelineView;
    }

    public void showAddCommandDialog() {

        AddMultipleCommandDialog.showSimpleAddDialog(timelineView.getScene().getWindow(),
                getTimelineView().getController(), modelRspecEditor.getModelRspec().getNodes());
    }
}
