Exemplo n.º 1
0
        public void AddButtontoDialogBox(CyPhyComponentAuthoringToolGUI CATgut, CATName attr, Type classtype, MethodInfo meth)
        {
            // add the Event Handler to the Button List
            CATName a = (CATName)attr;

            EventHandler handler;

            // create a delegate event handler for the button
            if (classtype.Name == typeof(CyPhyComponentAuthoringInterpreter).Name)
            {
                // local methods don't require a new instance of CATModule
                handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this, meth);
            }
            else
            {
                CATModule newinst = CreateCATModuleLogged(classtype);
                if (newinst == null)
                {
                    return;
                }

                // create a delegate for the dialog button to call to invoke the method
                handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), newinst, meth);
            }

            // Create our list view item
            CatToolListViewItem listViewItem = new CatToolListViewItem(attr, CATgut.ComponentIconList);

            listViewItem.Action += handler;

            CATgut.CatModuleListView.Items.Add(listViewItem);

            // associate the event handler with the button click
            //ev.AddEventHandler(button, handler);

            // Add a second event handler to each button to close the CAT dialog box after executing the first event handler
            //ev.AddEventHandler(button, (EventHandler)((sender, e) => close_dialog_box(sender, e)));
        }
Exemplo n.º 2
0
        public void PopulateDialogBox(SupportedDesignEntityType designElementType, bool testonly = false)
        {
            List <Tuple <CATName, Type, MethodInfo> > listofCATmethods = new List <Tuple <CATName, Type, MethodInfo> >();

            // create the dialog box
            using (CyPhyComponentAuthoringToolGUI CATgut = new CyPhyComponentAuthoringToolGUI(DragNDropHandler))
            {
                // get the current assembly
                Assembly thisAssembly = Assembly.GetExecutingAssembly();

                // scan each class in the current assembly
                foreach (Type classtype in thisAssembly.GetTypes())
                {
                    // send_to_logger(String.Format("Found class {0}", classtype.ToString()), testonly);

                    // Linq query to get all CATModules
                    var CATModulesQuery = classtype.GetCustomAttributes(true)
                                          .OfType <IsCATModule>()
                                          .Where(x => x.ContainsCATmethod)
                                          .Distinct();

                    foreach (var CATMod in CATModulesQuery)
                    {
                        send_to_logger(String.Format("Found CATModule class {0}", classtype.ToString()), testonly);

                        // get a list of all the methods in the class
                        // scan each method in the class for custom attributes
                        foreach (MethodInfo meth in classtype.GetMethods())
                        {
                            // send_to_logger(String.Format("Found method {0}", meth.ToString()), testonly);

                            // Get the custom attributes for this method.
                            // If it has the CATName attribute, we'll add it as a button.
                            foreach (CATName attr in meth.GetCustomAttributes(typeof(CATName), true))
                            {
                                if ((attr.SupportedDesignEntityTypes & designElementType) ==
                                    designElementType)
                                {
                                    listofCATmethods.Add(new Tuple <CATName, Type, MethodInfo>(attr, classtype, meth));
                                }
                            }

                            if (designElementType == SupportedDesignEntityType.Component)
                            {
                                foreach (CATDnD attr in meth.GetCustomAttributes(typeof(CATDnD), true))
                                {
                                    // NOTE: Drag and drop support only on components for now
                                    dictofCATDnDMethods.Add(attr.Extension.ToLowerInvariant(), new Tuple <Type, MethodInfo>(classtype, meth));
                                }
                            }
                        }
                    }
                }

                CATgut.SuspendLayout();
                CATgut.AutoScaleDimensions = new SizeF(6F, 13F);
                foreach (Tuple <CATName, Type, MethodInfo> item in listofCATmethods.OrderBy(i => i.Item1.RoleVal))
                {
                    AddButtontoDialogBox(CATgut, item.Item1, item.Item2, item.Item3);
                }
                CATgut.ResumeLayout();

                // META-2679 Set the start position of CAT dialog box to the center of the screen.
                CATgut.StartPosition = FormStartPosition.CenterScreen;
                // save the dialog box ref for testing
                ThisDialogBox = CATgut;
                // start up the dialog box
                if (!testonly)
                {
                    CATgut.ShowDialog();
                }
            }
        }
        public void PopulateDialogBox(bool testonly = false)
        {
            List<Tuple<CATName, Type, MethodInfo>> listofCATmethods = new List<Tuple<CATName, Type, MethodInfo>>();

            // create the dialog box
            using (CyPhyComponentAuthoringToolGUI CATgut = new CyPhyComponentAuthoringToolGUI())
            {
                // get the current assembly
                Assembly thisAssembly = Assembly.GetExecutingAssembly();

                // scan each class in the current assembly
                foreach (Type classtype in thisAssembly.GetTypes())
                {
                    send_to_logger(String.Format("Found class {0}", classtype.ToString()), testonly);

                    // Linq query to get all CATModules
                    var CATModulesQuery = classtype.GetCustomAttributes(true)
                                                   .OfType<IsCATModule>()
                                                   .Where(x => x.ContainsCATmethod)
                                                   .Distinct();

                    foreach (var CATMod in CATModulesQuery)
                    {
                        send_to_logger(String.Format("Found CATModule {0}", CATMod.ToString()), testonly);

                        // get a list of all the methods in the class
                        // scan each method in the class for custom attributes
                        foreach (MethodInfo meth in classtype.GetMethods())
                        {
                            send_to_logger(String.Format("Found method {0}", meth.ToString()), testonly);

                            // Get the custom attributes for this method.
                            // If it has the CATName attribute, we'll add it as a button.
                            foreach (CATName attr in meth.GetCustomAttributes(typeof(CATName), true))
                            {
                                listofCATmethods.Add(new Tuple<CATName, Type, MethodInfo>(attr, classtype, meth));
                            }
                        }
                    }
                }

                foreach (Tuple<CATName, Type, MethodInfo> item in listofCATmethods.OrderBy(i => i.Item1.RoleVal))
                {
                    AddButtontoDialogBox(CATgut, item.Item1, item.Item2, item.Item3);
                }

                // META-2679 Set the start position of CAT dialog box to the center of the screen.
                CATgut.StartPosition = FormStartPosition.CenterScreen;
                // save the dialog box ref for testing
                ThisDialogBox = CATgut;
                // start up the dialog box
                if (!testonly)
                {
                    CATgut.ShowDialog();
                }
            }
        }
        public void AddButtontoDialogBox(CyPhyComponentAuthoringToolGUI CATgut, CATName attr, Type classtype, MethodInfo meth)
        {
            // add the Event Handler to the Button List
            CATName a = (CATName)attr;

            // setup button properties
            Button button = new Button();
            button.Name = a.NameVal;
            button.Text = a.NameVal;
            button.Anchor = AnchorStyles.Top;

            // set the button size
            button.Width = CAT_BUTTON_WIDTH;
            button.Height = CAT_BUTTON_HEIGHT;

            // make clicking the button an event we can handle
            Type buttonType = typeof(Button);
            EventInfo ev = buttonType.GetEvent("Click");
            Delegate handler = null;

            // create a delegate event handler for the button
            if (classtype.Name == typeof(CyPhyComponentAuthoringInterpreter).Name)
            {
                // local methods don't require a new instance of CATModule
                handler = Delegate.CreateDelegate(ev.EventHandlerType, this, meth);
            }
            else
            {
                // create a new CATModule class instance 
                CATModule newinst = Activator.CreateInstance(classtype) as CATModule;
                if (newinst == null)
                {
                    // problem
                    this.Logger.WriteFailed("Unable to create a new CATModule class instance. CreateInstance call failed.");
                    return;
                }

                // set the current component for use by the new class instance
                newinst.SetCurrentComp(StashCurrentComponent);
                newinst.CurrentProj = StashProject;
                newinst.CurrentObj = StashCurrentObj;

                // create a delegate for the dialog button to call to invoke the method
                handler = Delegate.CreateDelegate(ev.EventHandlerType, newinst, meth);
            }
            // associate the event handler with the button click
            ev.AddEventHandler(button, handler);

            // Add a second event handler to each button to close the CAT dialog box after executing the first event handler
            Delegate closer = Delegate.CreateDelegate(ev.EventHandlerType, this, this.GetType().GetMethod("close_dialog_box"));
            ev.AddEventHandler(button, closer);

            // add another row to the table - each "row" is actually a smaller 2 column table
            TableLayoutPanel new_mini_table = new TableLayoutPanel();
            new_mini_table.AutoSize = true;
            new_mini_table.ColumnCount = 2;
            new_mini_table.RowCount = 1;

            // create the button
            new_mini_table.Controls.Add(button, 0, 0);

            //setup description properties
            Label description = new Label();
            description.Text = a.DescriptionVal;
            description.MinimumSize = new System.Drawing.Size(CAT_DESCRIPTION_WIDTH, CAT_DESCRIPTION_HEIGHT);
            description.Anchor = AnchorStyles.Top;
            description.TextAlign = ContentAlignment.MiddleCenter;
            
            // set the description
            new_mini_table.Controls.Add(description, 1, 0);

            // add the new CAT module to the dialog box
            CATgut.tableLayoutPanel0.Controls.Add(new_mini_table, 1, ++CATgut.tableLayoutPanel0.RowCount);
        }
Exemplo n.º 5
0
        public void AddButtontoDialogBox(CyPhyComponentAuthoringToolGUI CATgut, CATName attr, Type classtype, MethodInfo meth)
        {
            // add the Event Handler to the Button List
            CATName a = (CATName)attr;

            // setup button properties
            Button button = new Button();

            button.Name   = a.NameVal;
            button.Text   = a.NameVal;
            button.Anchor = AnchorStyles.Top;

            // set the button size
            button.Width  = CAT_BUTTON_WIDTH;
            button.Height = CAT_BUTTON_HEIGHT;

            // make clicking the button an event we can handle
            Type      buttonType = typeof(Button);
            EventInfo ev         = buttonType.GetEvent("Click");
            Delegate  handler    = null;

            // create a delegate event handler for the button
            if (classtype.Name == typeof(CyPhyComponentAuthoringInterpreter).Name)
            {
                // local methods don't require a new instance of CATModule
                handler = Delegate.CreateDelegate(ev.EventHandlerType, this, meth);
            }
            else
            {
                CATModule newinst = CreateCATModule(classtype);
                if (newinst == null)
                {
                    return;
                }

                // create a delegate for the dialog button to call to invoke the method
                handler = Delegate.CreateDelegate(ev.EventHandlerType, newinst, meth);
            }
            // associate the event handler with the button click
            ev.AddEventHandler(button, handler);

            // Add a second event handler to each button to close the CAT dialog box after executing the first event handler
            ev.AddEventHandler(button, (EventHandler)((sender, e) => close_dialog_box(sender, e)));

            // add another row to the table - each "row" is actually a smaller 2 column table
            TableLayoutPanel new_mini_table = new TableLayoutPanel();

            new_mini_table.AutoSize    = true;
            new_mini_table.ColumnCount = 2;
            new_mini_table.RowCount    = 1;

            // create the button
            new_mini_table.Controls.Add(button, 0, 0);

            //setup description properties
            Label description = new Label();

            description.Text        = a.DescriptionVal;
            description.MinimumSize = new System.Drawing.Size(CAT_DESCRIPTION_WIDTH, CAT_DESCRIPTION_HEIGHT);
            // description.Anchor = AnchorStyles.Top;
            description.TextAlign = ContentAlignment.MiddleCenter;

            // set the description
            new_mini_table.Controls.Add(description, 1, 0);

            // add the new CAT module to the dialog box
            CATgut.tableLayoutPanel0.Controls.Add(new_mini_table, 1, ++CATgut.tableLayoutPanel0.RowCount);
        }