package be.iminds.ilabt.jfed.experimenter_gui.canvas;

import be.iminds.ilabt.jfed.experimenter_gui.canvas.rspec.AddressPoolCanvasNode;
import be.iminds.ilabt.jfed.experimenter_gui.canvas.rspec.RspecCanvasLink;
import be.iminds.ilabt.jfed.experimenter_gui.canvas.rspec.RspecChannelCanvasNode;
import be.iminds.ilabt.jfed.experimenter_gui.canvas.rspec.RspecGTSNode;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;

/**
 * User: twalcari
 * Date: 11/8/13
 * Time: 12:27 PM
 */
public class SelectionProvider {

    private final ObjectProperty<Object> selectedObject = new SimpleObjectProperty<>(null);

    //////////////////////////////////////////////////////////////////////////////////////////////////////////

    public SelectionProvider() {
    }

    public void clearAllSelections() {
        selectedObject.setValue(null);
    }

    @Deprecated
    public CanvasNode getSelectedCanvasNode() {
        if (selectedObject.get() instanceof CanvasNode)
            return (CanvasNode) selectedObject.get();
        else
            return null;
    }


    @Deprecated
    public void setSelectedCanvasNode(CanvasNode value) {
        if (value == null)
            return;

        selectedObject.set(value);
    }

    public ObjectProperty<Object> selectedObjectProperty() {
        return selectedObject;
    }

    @Deprecated
    public RspecCanvasLink getSelectedCanvasLink() {
        if (selectedObject.get() instanceof RspecCanvasLink)
            return (RspecCanvasLink) selectedObject.get();
        else
            return null;
    }


    @Deprecated
    public void setSelectedCanvasLink(RspecCanvasLink value) {
        if (value == null)
            return;

        selectedObject.set(value);
    }

    @Deprecated
    public RspecCanvasLink.InterfaceLink getSelectedInterfaceLink() {
        if (selectedObject.get() instanceof RspecCanvasLink.InterfaceLink) {
            return (RspecCanvasLink.InterfaceLink) selectedObject.get();
        } else {
            return null;
        }
    }


    @Deprecated
    public void setSelectedInterfaceLink(RspecCanvasLink.InterfaceLink selectedInterfaceLink) {
        if (selectedInterfaceLink == null)
            return;

        this.selectedObject.setValue(selectedInterfaceLink);
    }


    @Deprecated
    public RspecChannelCanvasNode getSelectedChannel() {
        if (selectedObject.get() instanceof RspecChannelCanvasNode)
            return (RspecChannelCanvasNode) selectedObject.get();
        else
            return null;
    }


    @Deprecated
    public void setSelectedChannel(RspecChannelCanvasNode channel) {
        if (channel == null)
            return;

        this.selectedObject.setValue(channel);
    }



    @Deprecated
    public RspecGTSNode getSelectedGTSNode() {
        if (selectedObject.get() instanceof RspecGTSNode)
            return (RspecGTSNode) selectedObject.get();
        else
            return null;
    }


    @Deprecated
    public void setSelectedGTSNode(RspecGTSNode gtsNode) {
        if (gtsNode == null)
            return;

        this.selectedObject.setValue(gtsNode);
    }

    public Object getSelectedObject() {
        return selectedObject.get();
    }

    public void setSelectedObject(Object selectedObject) {
        this.selectedObject.set(selectedObject);
    }

    @Deprecated
    public void setSelectedAddressPool(AddressPoolCanvasNode addressPoolCanvasNode) {
        if(addressPoolCanvasNode == null)
            return;
        this.selectedObject.set(addressPoolCanvasNode);
    }

    @Deprecated
    public AddressPoolCanvasNode getSelectedAddressPool() {
        if (selectedObject.get() instanceof AddressPoolCanvasNode)
            return (AddressPoolCanvasNode) selectedObject.get();
        else
            return null;
    }
}
