public WindowPreconditionEditor(PlotFragment frag, PreconditionStatement currEntity, StoryData currStoryData)
        {
            InitializeComponent();

            _currentStoryData = currStoryData;
            _currentEntity = currEntity;
            _parentPlotFragment = frag;
            _currentlySelectedConstraint = null;
            _currentlyDataBinding = false;

            //Find editing type
            if (currEntity is PreconditionStatementCharacter)
            {
                _editingMode = 0;
            }
            else if (currEntity is PreconditionStatementEnvironment)
            {
                _editingMode = 1;
            }
            else
            {
                PlotPointType currType = currStoryData.findPlotPointTypeById(((PreconditionStatementPlotPoint)currEntity).MatchTypeId);

                _editingMode = 2;
                _ppType = currType;

            }
            txtBoxNumberInput.NullValue = 0.0;

            dataBind();
        }
        public List<Trait> getPreviouslyBoundPrimitiveVariables(TraitDataType variableType, bool allTypes, Constraint currentConstraint)
        {
            PlotFragment parentFrag = StoryWorldDataProvider.getStoryData().findPlotFragmentById(_parentPlotFragmentId);
            List<Trait> varsToReturn = parentFrag.getPreviouslyBoundPrimitiveVariables(variableType, allTypes, this);

            foreach (Constraint cons in Constraints)
            {
                if (cons == currentConstraint)
                {
                    //We have found where to stop looking, can now return variable list
                    return varsToReturn;
                }
                else if (cons.ContainsSavedVariable)
                {
                    if (allTypes || (cons.SavedVariable.Type == variableType))
                    {
                        //Add the variable names bound in this constraint to the running list
                        varsToReturn.Add(cons.SavedVariable);
                    }

                }
            }

            return varsToReturn;
        }
        public List<string> getAllPreviouslyBoundVariableNames(Constraint currentConstraint)
        {
            PlotFragment parentFrag = StoryWorldDataProvider.getStoryData().findPlotFragmentById(_parentPlotFragmentId);
            List<string> varsToReturn = parentFrag.getAllPreviouslyBoundVariableNames(this, true);

            foreach (Constraint cons in Constraints)
            {
                if (cons == currentConstraint)
                {
                    //We have found where to stop looking, can now return variable list
                    return varsToReturn;
                }
                else if (cons.ContainsSavedVariable)
                {

                        //Add the variable names bound in this constraint to the running list
                        varsToReturn.Add(cons.SavedVariable.Name);

                }
            }

            return varsToReturn;
        }
        private void constraintDataGrid_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Object selectedItem = constraintDataGrid.SelectedItem;
            if(selectedItem ==  null)
            {
                saveData();
                _currentlySelectedConstraint = null;
                clearDataElements();
                dataBind();
            }
            else
            {
                //Save before switching;
                saveData();
                _currentlySelectedConstraint = (Constraint)selectedItem;
                clearDataElements();
                dataBind();
                constraintDataGrid.SelectedItem = _currentlySelectedConstraint;

            }
        }
        private void btDelConstraint_Click(object sender, RoutedEventArgs e)
        {
            Object itemToEdit = constraintDataGrid.SelectedItem;
            if (itemToEdit == null) { return; }
            saveData();
            MessageBoxResult result = Utilities.MakeYesNoWarningDialog("Are you sure you want to delete this constraint?", "Confirm Deletion", this);

            if(result == MessageBoxResult.Yes)
            {
                _currentEntity.Constraints.Remove((Constraint)itemToEdit);
                _currentlySelectedConstraint = null;

                clearDataElements();
                dataBind();
                constraintDataGrid.SelectedItem = _currentlySelectedConstraint;
                constraintDataGrid_MouseUp(null, null);
            }
        }