public CreateBranchWindowVM(ControlConstructSchemeVM controlConstructScheme, IfThenElse ifThenElse) { this.controlConstructScheme = controlConstructScheme; questionConstructs = new ObservableCollection<QuestionConstructVM>(); questionConstructs.AddRange(controlConstructScheme.QuestionConstructs); thenConstructs = new ObservableCollection<ConstructVM>(); thenConstructs.AddRange(controlConstructScheme.ThenConstructs); if (ifThenElse == null) { //新規作成の場合 TargetQuestionConstruct = controlConstructScheme.SelectedConstruct as QuestionConstructVM; branches = new ObservableCollection<BranchVM>(); //IF~THENを追加 BranchVM ifBranch = new BranchVM(BranchVM.TYPE_IF_CODE) { Parent = this, No = 1, }; ifBranch.Init(); branches.Add(ifBranch); } else { // 編集の場合 TargetQuestionConstruct = EDOUtils.Find(controlConstructScheme.QuestionConstructs, ifThenElse.IfCondition.QuestionId); branches = SequenceUtils.CreateBranches(ifThenElse, this); } }
private static void CreateCondGroups(string code, BranchVM branch, ObservableCollection<QuestionConstructVM> questionConstructs) { CondParser parser = new CondParser(code); List<CondGroup> condGroupElems = parser.Parse(); foreach (CondGroup condGroupElem in condGroupElems) { CondGroupVM condGroup = new CondGroupVM() { Parent = branch }; condGroup.SelectedConnectionCode = Option.FindCodeByLabel(Options.Connections, condGroupElem.Connector); branch.CondGroups.Add(condGroup); foreach (Cond condElem in condGroupElem.Conds) { CondVM cond = new CondVM() { Parent = condGroup }; condGroup.Conds.Add(cond); cond.SelectedQuestionConstruct = QuestionConstructVM.FindQuestionConstructByNo(questionConstructs, condElem.LeftValue); cond.SelectedOperatorCode = Option.FindCodeByLabel(Options.Operators, condElem.Operator); cond.CondValue = condElem.RightValue; } } }
private static BranchVM CreateIfBranch(IfThenElse ifThenElse, CreateBranchWindowVM window) { BranchVM branch = new BranchVM(BranchVM.TYPE_IF_CODE) { Parent = window }; branch.Init(); branch.CondGroups.Clear(); IfCondition ifCondition = ifThenElse.IfCondition; CreateCondGroups(ifCondition.Code, branch, window.QuestionConstructs); branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, ifThenElse.ThenConstructId); return(branch); }
public BranchVM DeepCopy() { BranchVM newBranch = new BranchVM(TypeCode); newBranch.Parent = Parent; newBranch.Init(); newBranch.IsNew = IsNew; newBranch.ThenConstruct = ThenConstruct; newBranch.CondGroups.Clear(); foreach (CondGroupVM condGroup in condGroups) { CondGroupVM newGroup = condGroup.DeepCopy(newBranch); newBranch.CondGroups.Add(newGroup); } return(newBranch); }
private static BranchVM CreateElseBranch(IfThenElse ifThenElse, CreateBranchWindowVM window) { if (ifThenElse.ElseConstructId == null) { return(null); } BranchVM branch = new BranchVM(BranchVM.TYPE_ELSE_CODE) { Parent = window }; branch.Init(); branch.CondGroups.Clear(); branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, ifThenElse.ElseConstructId); return(branch); }
public static ObservableCollection <BranchVM> CreateBranches(IfThenElse ifThenElse, CreateBranchWindowVM window) { ObservableCollection <BranchVM> branches = new ObservableCollection <BranchVM>(); BranchVM ifBranch = CreateIfBranch(ifThenElse, window); branches.Add(ifBranch); List <BranchVM> elseIfBranches = CreateElseIfBranches(ifThenElse, window); branches.AddRange(elseIfBranches); BranchVM elseBranch = CreateElseBranch(ifThenElse, window); if (elseBranch != null) { branches.Add(elseBranch); } return(branches); }
public void SubmitEditingBranch() { if (selectedBranch == null || editingBranch == null) { return; } int index = branches.IndexOf(selectedBranch); branches.RemoveAt(index); branches.Insert(index, editingBranch); editingBranch.IsNew = false; selectedBranch = null; EditingBranch = null; OnBranchOrderChanged(); // Necessary for displaying Add button of branch(Adding ELSE clause) }
private static List <BranchVM> CreateElseIfBranches(IfThenElse ifThenElse, CreateBranchWindowVM window) { List <BranchVM> branches = new List <BranchVM>(); List <ElseIf> elseIfs = ifThenElse.ElseIfs; foreach (ElseIf elseIf in elseIfs) { BranchVM branch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE) { Parent = window }; branch.Init(); branch.CondGroups.Clear(); CreateCondGroups(elseIf.IfCondition.Code, branch, window.QuestionConstructs); branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, elseIf.ThenConstructId); branches.Add(branch); } return(branches); }
public bool CanChangeType(BranchVM branch) { if (!branch.IsNew) { return(false); } if (branch.IsTypeIf) { return(false); } foreach (BranchVM b in branches) { if (b.IsTypeElse) { return(false); } } return(true); }
public void AddBranch(BranchVM branch) { int index = Branches.IndexOf(branch); //Add ELSE IF ~ THEN ~ BranchVM elseIfBranch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE) { Parent = this, IsNew = true }; elseIfBranch.Init(); branches.Insert(index + 1, elseIfBranch); OnBranchOrderChanged(); Editor.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { elseIfBranch.EditBranch(); })); }
public void CancelEditingBranch() { selectedBranch = null; EditingBranch = null; }
public bool CanRemoveBranch(BranchVM branch) { if (EditingBranch != null) { return false; } return !branch.IsTypeIf; }
public void EditBranch(BranchVM branch) { selectedBranch = branch; selectedBranch.OnEditStarted(); EditingBranch = selectedBranch.DeepCopy(); }
private static List<BranchVM> CreateElseIfBranches(IfThenElse ifThenElse, CreateBranchWindowVM window) { List<BranchVM> branches = new List<BranchVM>(); List<ElseIf> elseIfs = ifThenElse.ElseIfs; foreach (ElseIf elseIf in elseIfs) { BranchVM branch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE) { Parent = window }; branch.Init(); branch.CondGroups.Clear(); CreateCondGroups(elseIf.IfCondition.Code, branch, window.QuestionConstructs); branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, elseIf.ThenConstructId); branches.Add(branch); } return branches; }
private static ElseIf CreateElseIf(BranchVM branch) { ElseIf elseIf = new ElseIf(); elseIf.IfCondition = CreateIfCondition(branch.ValidCondGroups); elseIf.ThenConstructId = branch.ThenConstruct.Id; return elseIf; }
public bool CanChangeType(BranchVM branch) { if (!branch.IsNew) { return false; } if (branch.IsTypeIf) { return false; } foreach (BranchVM b in branches) { if (b.IsTypeElse) { return false; } } return true; }
public void SubmitEditingBranch() { if (selectedBranch == null || editingBranch == null) { return; } int index = branches.IndexOf(selectedBranch); branches.RemoveAt(index); branches.Insert(index, editingBranch); editingBranch.IsNew = false; selectedBranch = null; EditingBranch = null; OnBranchOrderChanged(); // 分岐追加ボタンを表示するために必要(ELSE節の追加) }
public void RemoveBranch(BranchVM branch) { Branches.Remove(branch); OnBranchOrderChanged(); if (editingBranch != null) { editingBranch.OnOrderChanged(); } }
public void EditBranch(BranchVM branch) { selectedBranch = branch; selectedBranch.OnEditStarted(); EditingBranch = selectedBranch.DeepCopy(); }
public bool CanEditBranch(BranchVM branch) { return(EditingBranch == null); }
private static BranchVM CreateIfBranch(IfThenElse ifThenElse, CreateBranchWindowVM window) { BranchVM branch = new BranchVM(BranchVM.TYPE_IF_CODE) { Parent = window }; branch.Init(); branch.CondGroups.Clear(); IfCondition ifCondition = ifThenElse.IfCondition; CreateCondGroups(ifCondition.Code, branch, window.QuestionConstructs); branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, ifThenElse.ThenConstructId); return branch; }
public static CondGroupVM CreateDefault(BranchVM parent) { CondGroupVM condGroup = new CondGroupVM() { Parent = parent }; CondVM cond = CondVM.CreateDefault(condGroup); condGroup.Conds.Add(cond); return condGroup; }
public bool CanAddBranch(BranchVM branch) { if (EditingBranch != null) { return false; } if (branch.IsTypeElse) { //ELSE節には追加できない return false; } if (branches.Count == 0) { return false; } // IF or ELSE IFの場合、最後のブランチか、ELSEの1つ前ならば良い if (branches.Last() == branch) { return true; } if (branches.Count < 2) { return false; } int size = branches.Count; if (branches.Last().IsTypeElse && branches[size - 2] == branch) { return true; } return false; }
public void CancelEditingBranch() { selectedBranch = null; EditingBranch = null; }
private static BranchVM CreateElseBranch(IfThenElse ifThenElse, CreateBranchWindowVM window) { if (ifThenElse.ElseConstructId == null) { return null; } BranchVM branch = new BranchVM(BranchVM.TYPE_ELSE_CODE) { Parent = window }; branch.Init(); branch.CondGroups.Clear(); branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, ifThenElse.ElseConstructId); return branch; }
private static IfThenElse CreateIfThenElse(BranchVM branch) { IfThenElse ifThenElse = new IfThenElse(); ifThenElse.No = "-"; ifThenElse.IfCondition = CreateIfCondition(branch.ValidCondGroups); ifThenElse.ThenConstructId = branch.ThenConstruct.Id; return ifThenElse; }
public bool CanEditBranch(BranchVM branch) { return EditingBranch == null; }
public BranchVM DeepCopy() { BranchVM newBranch = new BranchVM(TypeCode); newBranch.Parent = Parent; newBranch.Init(); newBranch.IsNew = IsNew; newBranch.ThenConstruct = ThenConstruct; newBranch.CondGroups.Clear(); foreach (CondGroupVM condGroup in condGroups) { CondGroupVM newGroup = condGroup.DeepCopy(newBranch); newBranch.CondGroups.Add(newGroup); } return newBranch; }
public void AddBranch(BranchVM branch) { int index = Branches.IndexOf(branch); //ELSE IF~THEN~を追加 BranchVM elseIfBranch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE) { Parent = this, IsNew = true }; elseIfBranch.Init(); branches.Insert(index + 1, elseIfBranch); OnBranchOrderChanged(); Editor.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { elseIfBranch.EditBranch(); })); }