Exemple #1
0
        btnOK_Click
        (
            object sender,
            System.EventArgs e
        )
        {
            if (!DoDataExchange(true))
            {
                return;
            }

            if (m_oGraphMetricUserSettings.GraphMetricsToCalculate ==
                GraphMetrics.None)
            {
                this.ShowInformation("No metrics have been selected.");
                return;
            }

            if (m_eMode == DialogMode.EditOnly)
            {
                DialogResult = DialogResult.OK;
                this.Close();
                return;
            }

            // The CalculateGraphMetricsDialog does all the work.  Use the
            // constructor overload that uses a default list of graph metric
            // calculators.

            CalculateGraphMetricsDialog oCalculateGraphMetricsDialog =
                new CalculateGraphMetricsDialog(m_oWorkbook,
                                                m_oGraphMetricUserSettings);

            if (oCalculateGraphMetricsDialog.ShowDialog() == DialogResult.OK)
            {
                DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemple #2
0
        //*************************************************************************
        //  Method: AutomateThisWorkbook()
        //
        /// <summary>
        /// Runs a specified set of tasks on one NodeXL workbook.
        /// </summary>
        ///
        /// <param name="thisWorkbook">
        /// The NodeXL workbook to run the tasks on.
        /// </param>
        ///
        /// <param name="tasksToRun">
        /// The tasks to run, as an ORed combination of <see
        /// cref="AutomationTasks" /> flags.
        /// </param>
        ///
        /// <param name="ribbon">
        /// The workbook's Ribbon.
        /// </param>
        //*************************************************************************
        public static void AutomateThisWorkbook(
            ThisWorkbook thisWorkbook,
            AutomationTasks tasksToRun,
            Ribbon ribbon
            )
        {
            Debug.Assert(thisWorkbook != null);
            Debug.Assert(ribbon != null);

            Microsoft.Office.Interop.Excel.Workbook oWorkbook =
            thisWorkbook.InnerObject;

            if ( (tasksToRun & AutomationTasks.MergeDuplicateEdges) != 0 )
            {
            // In general, automation is best performed by simulating a click
            // of a Ribbon button, thus avoiding any duplicate code.

            if ( !ribbon.OnMergeDuplicateEdgesClick(false) )
            {
                return;
            }
            }

            if ( (tasksToRun & AutomationTasks.CalculateGraphMetrics) != 0 )
            {
            // In this case, clicking the corresponding Ribbon button opens a
            // GraphMetricsDialog, which allows the user to edit the graph
            // metric settings before calculating the graph metrics.  The
            // actual calculations are done by CalculateGraphMetricsDialog, so
            // just use that dialog directly.

            CalculateGraphMetricsDialog oCalculateGraphMetricsDialog =
                new CalculateGraphMetricsDialog( oWorkbook,
                    new GraphMetricUserSettings() );

            if (oCalculateGraphMetricsDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            }

            if ( (tasksToRun & AutomationTasks.AutoFillWorkbook) != 0 )
            {
            // In this case, clicking the corresponding Ribbon button opens an
            // AutoFillWorkbookDialog, which allows the user to edit the
            // autofill settings before autofilling the workbook.  The actual
            // autofilling is done by WorkbookAutoFiller, so just use that
            // class directly.

            try
            {
                WorkbookAutoFiller.AutoFillWorkbook(
                    oWorkbook, new AutoFillUserSettings(oWorkbook) );

                ribbon.OnWorkbookAutoFilled(false);
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }
            }

            if ( (tasksToRun & AutomationTasks.CreateSubgraphImages) != 0 )
            {
            ribbon.OnCreateSubgraphImagesClick(
                CreateSubgraphImagesDialog.DialogMode.Automate);
            }

            if ( (tasksToRun & AutomationTasks.CalculateClusters) != 0 )
            {
            if ( !ribbon.OnCalculateClustersClick() )
            {
                return;
            }
            }

            if ( (tasksToRun & AutomationTasks.ReadWorkbook) != 0 )
            {
            // If the vertex X and Y columns were autofilled, the layout type
            // was set to LayoutType.Null.  This will cause
            // TaskPane.ReadWorkbook() to display a warning.  Temporarily turn
            // the warning off.

            NotificationUserSettings oNotificationUserSettings =
                new NotificationUserSettings();

            Boolean bOldLayoutTypeIsNull =
                oNotificationUserSettings.LayoutTypeIsNull;

            oNotificationUserSettings.LayoutTypeIsNull = false;
            oNotificationUserSettings.Save();

            if ( (tasksToRun & AutomationTasks.SaveGraphImageFile) != 0 )
            {
                if ( String.IsNullOrEmpty(thisWorkbook.Path) )
                {
                    throw new InvalidOperationException(
                        WorkbookNotSavedMessage);
                }

                // After the workbook is read and the graph is laid out, save
                // an image of the graph to a file.

                GraphLaidOutEventHandler oGraphLaidOutEventHandler = null;

                oGraphLaidOutEventHandler =
                    delegate(Object sender, GraphLaidOutEventArgs e)
                {
                    // This delegate remains forever, even when the dialog
                    // class is destroyed.  Prevent it from being called again.

                    thisWorkbook.GraphLaidOut -= oGraphLaidOutEventHandler;

                    SaveGraphImageFile(e.NodeXLControl, thisWorkbook.FullName);
                };

                thisWorkbook.GraphLaidOut += oGraphLaidOutEventHandler;
            }

            ribbon.OnReadWorkbookClick();

            oNotificationUserSettings.LayoutTypeIsNull = bOldLayoutTypeIsNull;
            oNotificationUserSettings.Save();
            }
        }
        //*************************************************************************
        //  Method: btnOK_Click()
        //
        /// <summary>
        /// Handles the Click event on the btnOK button.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        private void btnOK_Click(
            object sender,
            System.EventArgs e
            )
        {
            if ( !DoDataExchange(true) )
            {
            return;
            }

            if (m_oGraphMetricUserSettings.GraphMetricsToCalculate ==
            GraphMetrics.None)
            {
            this.ShowInformation("No metrics have been selected.");
            return;
            }

            if (m_eMode == DialogMode.EditOnly)
            {
            DialogResult = DialogResult.OK;
            this.Close();
            return;
            }

            // The CalculateGraphMetricsDialog does all the work.  Use the
            // constructor overload that uses a default list of graph metric
            // calculators.

            CalculateGraphMetricsDialog oCalculateGraphMetricsDialog =
            new CalculateGraphMetricsDialog(m_oWorkbook,
                m_oGraphMetricUserSettings);

            if (oCalculateGraphMetricsDialog.ShowDialog() == DialogResult.OK)
            {
            DialogResult = DialogResult.OK;
            this.Close();
            }
        }
Exemple #4
0
        AutomateThisWorkbook
        (
            ThisWorkbook thisWorkbook,
            AutomationTasks tasksToRun,
            Ribbon ribbon
        )
        {
            Debug.Assert(thisWorkbook != null);
            Debug.Assert(ribbon != null);

            Microsoft.Office.Interop.Excel.Workbook oWorkbook =
                thisWorkbook.InnerObject;

            if ((tasksToRun & AutomationTasks.MergeDuplicateEdges) != 0)
            {
                // In general, automation is best performed by simulating a click
                // of a Ribbon button, thus avoiding any duplicate code.

                if (!ribbon.OnMergeDuplicateEdgesClick(false))
                {
                    return;
                }
            }

            if ((tasksToRun & AutomationTasks.CalculateGraphMetrics) != 0)
            {
                // In this case, clicking the corresponding Ribbon button opens a
                // GraphMetricsDialog, which allows the user to edit the graph
                // metric settings before calculating the graph metrics.  The
                // actual calculations are done by CalculateGraphMetricsDialog, so
                // just use that dialog directly.

                CalculateGraphMetricsDialog oCalculateGraphMetricsDialog =
                    new CalculateGraphMetricsDialog(oWorkbook,
                                                    new GraphMetricUserSettings());

                if (oCalculateGraphMetricsDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            if ((tasksToRun & AutomationTasks.AutoFillWorkbook) != 0)
            {
                // In this case, clicking the corresponding Ribbon button opens an
                // AutoFillWorkbookDialog, which allows the user to edit the
                // autofill settings before autofilling the workbook.  The actual
                // autofilling is done by WorkbookAutoFiller, so just use that
                // class directly.

                try
                {
                    WorkbookAutoFiller.AutoFillWorkbook(
                        oWorkbook, new AutoFillUserSettings(oWorkbook));

                    ribbon.OnWorkbookAutoFilled(false);
                }
                catch (Exception oException)
                {
                    ErrorUtil.OnException(oException);
                    return;
                }
            }

            if ((tasksToRun & AutomationTasks.CreateSubgraphImages) != 0)
            {
                ribbon.OnCreateSubgraphImagesClick(
                    CreateSubgraphImagesDialog.DialogMode.Automate);
            }

            if ((tasksToRun & AutomationTasks.CalculateClusters) != 0)
            {
                if (!ribbon.OnCalculateClustersClick())
                {
                    return;
                }
            }

            if ((tasksToRun & AutomationTasks.ReadWorkbook) != 0)
            {
                // If the vertex X and Y columns were autofilled, the layout type
                // was set to LayoutType.Null.  This will cause
                // TaskPane.ReadWorkbook() to display a warning.  Temporarily turn
                // the warning off.

                NotificationUserSettings oNotificationUserSettings =
                    new NotificationUserSettings();

                Boolean bOldLayoutTypeIsNull =
                    oNotificationUserSettings.LayoutTypeIsNull;

                oNotificationUserSettings.LayoutTypeIsNull = false;
                oNotificationUserSettings.Save();

                if ((tasksToRun & AutomationTasks.SaveGraphImageFile) != 0)
                {
                    if (String.IsNullOrEmpty(thisWorkbook.Path))
                    {
                        throw new InvalidOperationException(
                                  WorkbookNotSavedMessage);
                    }

                    // After the workbook is read and the graph is laid out, save
                    // an image of the graph to a file.

                    GraphLaidOutEventHandler oGraphLaidOutEventHandler = null;

                    oGraphLaidOutEventHandler =
                        delegate(Object sender, GraphLaidOutEventArgs e)
                    {
                        // This delegate remains forever, even when the dialog
                        // class is destroyed.  Prevent it from being called again.

                        thisWorkbook.GraphLaidOut -= oGraphLaidOutEventHandler;

                        SaveGraphImageFile(e.NodeXLControl, thisWorkbook.FullName);
                    };

                    thisWorkbook.GraphLaidOut += oGraphLaidOutEventHandler;
                }

                ribbon.OnReadWorkbookClick();

                oNotificationUserSettings.LayoutTypeIsNull = bOldLayoutTypeIsNull;
                oNotificationUserSettings.Save();
            }
        }
Exemple #5
0
        //*************************************************************************
        //  Method: CalculateGroups()
        //
        /// <summary>
        /// Group's the graph's vertices using a graph metric calculator.
        /// </summary>
        ///
        /// <param name="oGraphMetricCalculator">
        /// The IGraphMetricCalculator2 to use.
        /// </param>
        ///
        /// <param name="sDialogTitle">
        /// Title for the CalculateGraphMetricsDialog, or null to use a default
        /// title.
        /// </param>
        ///
        /// <returns>
        /// true if the graph metrics were successfully calculated, or false if
        /// they were cancelled or the application isn't ready.
        /// </returns>
        //*************************************************************************
        private Boolean CalculateGroups(
            IGraphMetricCalculator2 oGraphMetricCalculator,
            String sDialogTitle
            )
        {
            Debug.Assert(oGraphMetricCalculator != null);
            Debug.Assert( !String.IsNullOrEmpty(sDialogTitle) );
            AssertValid();

            if ( !this.ExcelApplicationIsReady(true) )
            {
            return (false);
            }

            // The CalculateGraphMetricsDialog does the work.

            CalculateGraphMetricsDialog oCalculateGraphMetricsDialog =
            new CalculateGraphMetricsDialog(
                this.InnerObject,
                new GraphMetricUserSettings(),
                new IGraphMetricCalculator2[] {oGraphMetricCalculator},
                sDialogTitle
                );

            if (oCalculateGraphMetricsDialog.ShowDialog() == DialogResult.OK)
            {
            // Check the "read groups" checkbox in the ribbon.

            this.Ribbon.ReadGroups = true;

            return (true);
            }

            return (false);
        }