// ------------------------------------------------------------------- // AddCombobox // ------------------------------------------------------------------- public void AddCombobox(NTree <List <object> > node, NTree <List <object> > parentNode, string selected, NTree <List <object> > lastNode) { ComboBoxCondition comboBox = new ComboBoxCondition(node, parentNode, selected); if (selected != "") { comboBox.Items.Add(selected); } else { comboBox.Items.Add(""); if (node == lastNode) { comboBox.Items.Add("And"); comboBox.Items.Add("Or"); } else { comboBox.Items.Add((string)parentNode.Data[0]); } } comboBox.AutoSize = true; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; comboBox.Size = new Size(45, 20); comboBox.Anchor = AnchorStyles.Left; comboBox.SelectedItem = selected; comboBox.SelectedIndexChanged += ComboBox_SelectedIndexChanged; mainTableLayout.Controls.Add(comboBox, mainTableLayout.ColumnStyles.Count, 0); mainTableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); }
// ------------------------------------------------------------------- // CopyTreeNode // ------------------------------------------------------------------- public void CopyTreeNode(NTree <EventCommand> tree, NTree <EventCommand> treeToCopy) { foreach (NTree <EventCommand> childToCopy in treeToCopy.Children) { CopyTreeNode(tree.AddChildData(childToCopy.Data.CreateCopy()), childToCopy); } }
// ------------------------------------------------------------------- // CreateCopy // ------------------------------------------------------------------- public override EventCommand CreateCopy() { NTree <List <object> > tree = new NTree <List <object> >(new List <object>(new object[] { Tree.Data[0] })); CopyTreeNode(tree, Tree); return(new EventCommandConditions(tree)); }
public NTree <T> AddChildData(T data) { NTree <T> child = new NTree <T>(data); Children.AddLast(child); return(child); }
// ------------------------------------------------------------------- // CreateCopy // ------------------------------------------------------------------- public SystemEventPage CreateCopy() { NTree <EventCommand> treeCommandsCopy = new NTree <EventCommand>(null); CopyTreeNode(treeCommandsCopy, CommandsTree); return(new SystemEventPage(Graphic.CreateCopy(), GraphicDrawType, Options.CreateCopy(), Trigger, (EventCommandConditions)ConditionsTree.CreateCopy(), treeCommandsCopy)); }
// ------------------------------------------------------------------- // GetDefaultTreeCommands // ------------------------------------------------------------------- public static NTree <EventCommand> GetDefaultTreeCommands() { NTree <EventCommand> tree = new NTree <EventCommand>(null); tree.AddChildData(new EventCommandOther()); return(tree); }
// ------------------------------------------------------------------- // GetDefaultTreeConditions // ------------------------------------------------------------------- public static NTree <List <object> > GetDefaultTreeConditions() { NTree <List <object> > tree = new NTree <List <object> >(new List <object>(new object[] { "" })); tree.AddChildData(null); return(tree); }
public SystemEventPage(SystemGraphic graphic, DrawType graphicDrawType, PageOptions options, EventTrigger trigger, EventCommandConditions conditionsTree, NTree <EventCommand> commandsTree) { Graphic = graphic; GraphicDrawType = graphicDrawType; Options = options; Trigger = trigger; ConditionsTree = conditionsTree; CommandsTree = commandsTree; }
// ------------------------------------------------------------------- // AddCommandNodes // ------------------------------------------------------------------- public void AddCommandNodes(NTree <EventCommand> node, TreeNodeCollection commandNode) { foreach (NTree <EventCommand> child in node.Children) { TreeNode commandChild = commandNode.Add(WANOK.ListBeginning + child.Data.ToString()); commandChild.Tag = child; AddCommandNodes(child, commandChild.Nodes); } }
// ------------------------------------------------------------------- // AddButton // ------------------------------------------------------------------- public void AddButton(NTree <List <object> > node, NTree <List <object> > parentNode) { FlatButtonCondition button = new FlatButtonCondition(node, parentNode); button.AutoSize = true; button.Text = node.Data == null ? "New" : Condition.ToString(node.Data); button.BackColor = node.Data == null ? FlatButtonCondition.NoneColor : FlatButtonCondition.FullColor; button.Size = new Size(0, 0); button.MouseDown += Button_MouseDown; mainTableLayout.Controls.Add(button, mainTableLayout.ColumnStyles.Count, 0); mainTableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); }
public void CleanTree(NTree <List <object> > node) { foreach (NTree <List <object> > child in node.Children) { CleanTree(child); if (child.Data != null && child.Data.Count == 1 && child.Children.Count == 1) { node.DeleteChild(child); node.AddChild(child.Children.First.Value); break; } } }
// ------------------------------------------------------------------- // CleanTree // ------------------------------------------------------------------- public void CleanTree() { CleanTree(Tree); if (Tree.Data.Count == 1 && Tree.Children.Count == 1) { if (Tree.Children.First.Value.Children.Count == 0) { Tree.Data = new List <object>(new object[] { "" }); } else { Tree = Tree.Children.First.Value; } } }
// ------------------------------------------------------------------- // TreeContainsAndOr // ------------------------------------------------------------------- public bool TreeContainsAndOr(NTree <List <object> > node, string i) { foreach (NTree <List <object> > child in node.Children) { if (node.Data != null && node.Data.Count == 1 && (string)node.Data[0] == i) { return(true); } if (TreeContainsAndOr(child, i)) { return(true); } } return(false); }
// ------------------------------------------------------------------- // CopyTreeNode // ------------------------------------------------------------------- public void CopyTreeNode(NTree <List <object> > tree, NTree <List <object> > treeToCopy) { foreach (NTree <List <object> > childToCopy in treeToCopy.Children) { List <object> command = null; if (childToCopy.Data != null) { command = new List <object>(); for (int i = 0; i < childToCopy.Data.Count; i++) { command.Add(childToCopy.Data[i]); } } CopyTreeNode(tree.AddChildData(command), childToCopy); } }
private int GetNodesCount(NTree <T> node) { int count = 0; if (node.Children.Count == 0) { count++; } else { foreach (NTree <T> child in node.Children) { count += GetNodesCount(child); } } return(count); }
// ------------------------------------------------------------------- // OpenLabelDialogCommand // ------------------------------------------------------------------- public void OpenLabelDialogCommand() { if (ListCommandsSelectedLabel != null) { EventCommandKind kind = (EventCommandKind)ListCommandsSelectedLabel.Tag; EventCommand eventCommand = null; switch (kind) { case EventCommandKind.None: eventCommand = new EventCommandOther(); break; case EventCommandKind.ChangeSwitches: eventCommand = new EventCommandOther(EventCommandKind.ChangeSwitches, new List <object>(new object[] { 0, 1, 0 })); break; case EventCommandKind.Conditions: eventCommand = new EventCommandConditions(); break; default: break; } ModelForm dialog = (ModelForm)GetDialogEventCommand(eventCommand); if (kind == EventCommandKind.None) { WANOK.ShowActionMessage(); } else { DontLooseFocus = true; if (dialog.ShowDialog() == DialogResult.OK) { ((NTree <EventCommand>)CommandsView.SelectedNode.Tag).Data = dialog.GetModel(); CommandsView.SelectedNode.Text = WANOK.ListBeginning + dialog.GetModel().ToString(); TreeNode node = CommandsView.Nodes.Add(WANOK.ListBeginning); NTree <EventCommand> commandTree = Control.Model.GetCurrentPage().CommandsTree.AddChildData(new EventCommandOther()); node.Tag = commandTree; UpdateTreeCommandsSelection(); } DontLooseFocus = false; } } }
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { string previousSelecteIndex = ((ComboBoxCondition)sender).Index; string newSelectedIndex = ((ComboBox)sender).SelectedItem.ToString(); if (previousSelecteIndex != newSelectedIndex) { if ((string)Tree.Data[0] == newSelectedIndex) { Tree.AddChildData(null); } else if ((string)Tree.Data[0] == "") { ((ComboBoxCondition)sender).ParentNode.Data = new List <object>(new object[] { newSelectedIndex }); ((ComboBoxCondition)sender).ParentNode.AddChildData(null); } else { if (TreeContainsAndOr(Tree, newSelectedIndex)) { if (((ComboBoxCondition)sender).ParentNode.Data.Count == 1 && (string)((ComboBoxCondition)sender).ParentNode.Data[0] == newSelectedIndex) { ((ComboBoxCondition)sender).ParentNode.AddChildData(null); } else { List <object> previousData = ((ComboBoxCondition)sender).Node.Data; ((ComboBoxCondition)sender).Node.Data = new List <object>(new object[] { newSelectedIndex }); ((ComboBoxCondition)sender).Node.AddChildData(previousData); ((ComboBoxCondition)sender).Node.AddChildData(null); } } else { NTree <List <object> > previousTree = Tree; Tree = new NTree <List <object> >(new List <object>(new object[] { newSelectedIndex })); Tree.AddChild(previousTree); Tree.AddChildData(null); } } GeneratePanel(); } }
private NTree <T> GetLastNode(NTree <T> node) { NTree <T> lastNode = null; if (node.Children.Count > 0) { foreach (NTree <T> child in node.Children) { NTree <T> lastNodeChild = GetLastNode(child); if (lastNodeChild != null) { lastNode = lastNodeChild; } } } else { return(node); } return(lastNode); }
private void BrowseNode(NTree <List <object> > node, NTree <List <object> > parent, NTree <List <object> > lastNode) { if (node.Children.Count > 1) { AddLabel("("); } foreach (NTree <List <object> > child in node.Children) { BrowseNode(child, node, lastNode); } if (node.Children.Count > 1) { AddLabel(")"); } if (node.Children.Count == 0) { // Button AddButton(node, parent); // ComboBox var lastChild = parent.IsLastChild(node); if (node.Data != null && lastChild) { AddCombobox(node, parent, "", lastNode); } else if (!lastChild) { AddCombobox(node, parent, (string)parent.Data[0], lastNode); } } else { if (parent.Data != null && parent.Data.Count == 1 && (string)parent.Data[0] != "" && !parent.IsLastChild(node)) { AddCombobox(node, parent, (string)parent.Data[0], lastNode); } } }
public EventCommandConditions(NTree <List <object> > tree) { EventCommandKind = EventCommandKind.Conditions; Tree = tree; }
public void DeleteChild(NTree <T> child) { Children.Remove(child); }
public bool IsLastChild(NTree <T> d) { return(d == Children.Last.Value); }
public NTree <T> AddChild(NTree <T> child) { Children.AddLast(child); return(child); }
// ------------------------------------------------------------------- // InitializeListParameters // ------------------------------------------------------------------- public void InitializeListParameters(NTree <List <object> > tree) { Tree = tree; GeneratePanel(); }
public ComboBoxCondition(NTree <List <object> > node, NTree <List <object> > parentNode, string index) { Node = node; ParentNode = parentNode; Index = index; }
public FlatButtonCondition(NTree <List <object> > node, NTree <List <object> > parentNode) { Node = node; ParentNode = parentNode; }