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

import be.iminds.ilabt.jfed.experimenter_gui.ui.code.XmlCodeView;
import be.iminds.ilabt.jfed.rspec.model.StringRspec;
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: 1/29/14
 * Time: 5:03 PM
 */
public class RawRspecEditor extends XmlCodeView implements EditableRspecView {

    private final StringRspec inputModel;
    private boolean dirty = false;

    private final StringProperty status = new SimpleStringProperty();

    RawRspecEditor(StringRspec inputModel, boolean dirty) {
        this(inputModel);
        this.dirty = dirty;
    }


    RawRspecEditor(StringRspec inputModel) {
        super(inputModel.getXmlString(), true);
        this.inputModel = inputModel;
    }

    public StringRspec getResultRspec() {
        return new StringRspec(getContent());
    }

    @Override
    public boolean isDirty() {
        return dirty || super.isDirty();
    }

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

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

    @Override
    public RequestRspecSource getRequestRspecSource() {
        return new RequestRspecSource(getResultRspec());
    }

    @Override
    public void dispose() {

    }

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