protected void CustomTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs args) { if (AllowUserInput) { if (args.Button == MouseButtons.Right) // right click { this.ContextMenuStrip.Items.Clear(); // detect node click if (args.Node != null && (args.X >= args.Node.Bounds.Left) && (args.X <= args.Node.Bounds.Right) && (args.Y >= args.Node.Bounds.Top) && (args.Y <= args.Node.Bounds.Bottom)) { ProcessingNode cast = (ProcessingNode)args.Node; // handle right click by populating with node functions List<Function> functions = cast.Functions; if (functions != null) { ToolStripItem newItem; if (functions.Count > 0) { NodeFunctionListEventArgs e = new NodeFunctionListEventArgs(cast, functions); OnNodeFunctionList(e); } foreach (Function f in functions) { if (f.Visible) { newItem = this.ContextMenuStrip.Items.Add(f.FunctionName); if (!f.Enabled) newItem.Enabled = f.Enabled; CustomContextMenuTag customTag = new CustomContextMenuTag(cast, f.FunctionName, f.FunctionAction); customTag.Arguments = f.Arguments; newItem.Tag = customTag; } } } } // arg check } // right click } // input }
private void customTreeView2_NodeFunctionList(object sender, NodeFunctionListEventArgs e) { if (e.Node.Name.Equals("Levels")) { AME.Nodes.ProcessingNode parentNode = e.Node.Parent as AME.Nodes.ProcessingNode; if (parentNode.NodeType.Equals("Emitter")) { // get parameters using node id IXPathNavigable iNavParameters = vsgController.GetParametersForComponent(parentNode.NodeID); XPathNavigator navParameters = iNavParameters.CreateNavigator(); XPathNavigator navAttribute = navParameters.SelectSingleNode("/ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Attribute_Emitter']"); XPathNavigator navCustomAttribute = navParameters.SelectSingleNode("/ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Custom_Attribute_Emitter']"); if (navAttribute.GetAttribute("value", navAttribute.NamespaceURI).ToLower() == "true") {//standard attribute emitter navAttribute = navParameters.SelectSingleNode("/ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Attribute']"); if (navAttribute != null) { String attributeValue = navAttribute.GetAttribute("value", navAttribute.NamespaceURI); if (attributeValue.Equals("Default") || attributeValue.Equals("Invisible")) { foreach (AME.Nodes.Function function in e.Functions) { if (function.FunctionName.Equals("Create Level")) { function.Enabled = false; } } MessageBox.Show(string.Format("Emitter \'{0}\' is defined as a Default or Invisible.\nLevels can only be used with Attribute Emitters.", parentNode.Name), "Using Default or Invisible Emitters", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else if (navCustomAttribute.GetAttribute("value", navAttribute.NamespaceURI).ToLower() == "true") { //Custom attribute emitter navAttribute = navParameters.SelectSingleNode("/ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Custom_Attribute']"); } //if (navAttribute != null) //{ // String attributeValue = navAttribute.GetAttribute("value", navAttribute.NamespaceURI); // if (attributeValue.Equals("Default") || attributeValue.Equals("Invisible")) // { // foreach (AME.Nodes.Function function in functions) // { // if (function.FunctionName.Equals("Create Level")) // { // function.Enabled = false; // } // } // } //} } } if (e.Node.Name == "Sensor Ranges") { AME.Nodes.ProcessingNode parentNode = e.Node.Parent as AME.Nodes.ProcessingNode; IXPathNavigable iNavParameters = vsgController.GetParametersForComponent(parentNode.NodeID); XPathNavigator navParameters = iNavParameters.CreateNavigator(); XPathNavigator navAttribute = navParameters.SelectSingleNode("/ComponentParameters/Parameter[@category='Sensor']/Parameter[@displayedName='Global_Sensor']"); if (navAttribute.GetAttribute("value", navAttribute.NamespaceURI).ToLower() == "true") { MessageBox.Show(string.Format("Sensor \'{0}\' is defined as a Global Sensor.\nSensor Ranges can only be used with Attribute Sensors.", parentNode.Name), "Using Global Sensors", MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (AME.Nodes.Function function in e.Functions) { if (function.FunctionName == "Create Sensor Range") { function.Enabled = false; } } } } }
protected virtual void OnNodeFunctionList(NodeFunctionListEventArgs e) { NodeFunctionListEventHandler handler = NodeFunctionList; if (handler != null) { handler(this, e); } }