Esempio n. 1
0
        //*************************************************************************
        //  Constructor: AutomateTasksDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="AutomateTasksDialog" />
        /// class.
        /// </summary>
        ///
        /// <param name="thisWorkbook">
        /// Workbook containing the graph contents.
        /// </param>
        ///
        /// <param name="ribbon">
        /// The application's Ribbon.
        /// </param>
        //*************************************************************************
        public AutomateTasksDialog(
            ThisWorkbook thisWorkbook,
            Ribbon ribbon
            )
        {
            Debug.Assert(thisWorkbook != null);
            Debug.Assert(ribbon != null);

            m_oAutomateTasksUserSettings = new AutomateTasksUserSettings();
            m_oThisWorkbook = thisWorkbook;
            m_oRibbon = ribbon;

            InitializeComponent();

            // Instantiate an object that saves and retrieves the user settings for
            // this dialog.  Note that the object automatically saves the settings
            // when the form closes.

            m_oAutomateTasksDialogUserSettings =
            new AutomateTasksDialogUserSettings(this);

            DoDataExchange(false);

            AssertValid();
        }
Esempio n. 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();
            }
        }
Esempio n. 3
0
        //*************************************************************************
        //  Constructor: TaskPane()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskPane" /> class.
        /// </summary>
        ///
        /// <param name="thisWorkbook">
        /// The workbook.
        /// </param>
        ///
        /// <param name="ribbon">
        /// The application's ribbon.
        /// </param>
        //*************************************************************************
        public TaskPane(
            ThisWorkbook thisWorkbook,
            Ribbon ribbon
            )
        {
            Debug.Assert(thisWorkbook != null);
            Debug.Assert(ribbon != null);

            InitializeComponent();

            m_oWorkbook = thisWorkbook.InnerObject;
            m_oRibbon = ribbon;

            // The WpfImageUtil uses the screen DPI in its image handling.

            Graphics oGraphics = this.CreateGraphics();
            WpfImageUtil.ScreenDpi = oGraphics.DpiX;
            oGraphics.Dispose();

            // Get the template version from the per-workbook settings.

            PerWorkbookSettings oPerWorkbookSettings =
            this.PerWorkbookSettings;

            m_iTemplateVersion = oPerWorkbookSettings.TemplateVersion;

            m_bHandlingLayoutChanged = false;
            m_iEnableGraphControlsCount = 0;
            m_oEdgeRowIDDictionary = null;
            m_oVertexRowIDDictionary = null;
            m_oSaveGraphImageFileDialog = null;
            m_oDynamicFilterDialog = null;

            GeneralUserSettings oGeneralUserSettings = new GeneralUserSettings();
            LayoutUserSettings oLayoutUserSettings = new LayoutUserSettings();

            LayoutType eInitialLayout = oLayoutUserSettings.Layout;

            // Instantiate an object that populates the sbLayout
            // ToolStripSplitButton and handles its LayoutChanged event.

            m_oLayoutManagerForToolStripSplitButton =
            new LayoutManagerForToolStripSplitButton();

            m_oLayoutManagerForToolStripSplitButton.AddItems(this.sbLayout);
            m_oLayoutManagerForToolStripSplitButton.Layout = eInitialLayout;

            // Instantiate an object that populates the msiContextLayout
            // context menu and handles the Clicked events on the child menu items.

            m_oLayoutManagerForContextMenu = new LayoutManagerForMenu();
            m_oLayoutManagerForContextMenu.AddMenuItems(this.msiContextLayout);
            m_oLayoutManagerForContextMenu.Layout = eInitialLayout;

            m_oLayoutManagerForToolStripSplitButton.LayoutChanged +=
            new EventHandler(this.LayoutManager_LayoutChanged);

            m_oLayoutManagerForContextMenu.LayoutChanged +=
            new EventHandler(this.LayoutManager_LayoutChanged);

            thisWorkbook.VisualAttributeSetInWorkbook +=
            new EventHandler(ThisWorkbook_VisualAttributeSetInWorkbook);

            thisWorkbook.CollapseOrExpandGroups +=
            new CollapseOrExpandGroupsEventHandler(
                ThisWorkbook_CollapseOrExpandGroups);

            thisWorkbook.WorksheetContextMenuManager.RequestVertexCommandEnable +=
            new RequestVertexCommandEnableEventHandler(
                WorksheetContextMenuManager_RequestVertexCommandEnable);

            thisWorkbook.WorksheetContextMenuManager.RequestEdgeCommandEnable +=
            new RequestEdgeCommandEnableEventHandler(
                WorksheetContextMenuManager_RequestEdgeCommandEnable);

            thisWorkbook.WorksheetContextMenuManager.RunVertexCommand +=
            new RunVertexCommandEventHandler(
                WorksheetContextMenuManager_RunVertexCommand);

            thisWorkbook.WorksheetContextMenuManager.RunEdgeCommand +=
            new RunEdgeCommandEventHandler(
                WorksheetContextMenuManager_RunEdgeCommand);

            // There is no Closing event on the TaskPane and no parent form whose
            // Closing event can be handled.  Instead, using the Shutdown event on
            // the workbook to perform closing tasks.

            thisWorkbook.Shutdown += new EventHandler(ThisWorkbook_Shutdown);

            m_oRibbon.Layout = eInitialLayout;

            m_oRibbon.RibbonControlsChanged +=
            new RibbonControlsChangedEventHandler(
                Ribbon_RibbonControlsChanged);

            m_oRibbon.RunRibbonCommand += new RunRibbonCommandEventHandler(
            Ribbon_RunRibbonCommand);

            CreateNodeXLControl(oGeneralUserSettings);
            CreateGraphZoomAndScaleControl();

            oNodeXLControl.GraphScale =
            ( new GraphZoomAndScaleUserSettings() ).GraphScale;

            ApplyGeneralUserSettings(oGeneralUserSettings);
            ApplyLayoutUserSettings(oLayoutUserSettings);

            this.ShowGraphLegend = m_oRibbon.ShowGraphLegend;

            UpdateAutoFillResultsLegend(oPerWorkbookSettings);
            UpdateDynamicFiltersLegend();
            UpdateAxes(oPerWorkbookSettings);

            AssertValid();
        }
Esempio n. 4
0
        //*************************************************************************
        //  Constructor: SelectionCoordinator()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectionCoordinator" />
        /// class.
        /// </summary>
        ///
        /// <param name="thisWorkbook">
        /// The Excel workbook.
        /// </param>
        ///
        /// <param name="edgeWorksheet">
        /// The edge worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="edgeTable">
        /// The edge table on the edge worksheet.
        /// </param>
        ///
        /// <param name="vertexWorksheet">
        /// The vertex worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="vertexTable">
        /// The vertex table on the vertex worksheet.
        /// </param>
        ///
        /// <param name="groupWorksheet">
        /// The group worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="groupTable">
        /// The group table on the group worksheet.
        /// </param>
        ///
        /// <param name="groupVertexWorksheet">
        /// The group-vertex worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="taskPane">
        /// The TaskPane.
        /// </param>
        //*************************************************************************

        public SelectionCoordinator
        (
            ThisWorkbook thisWorkbook,
            Sheet1 edgeWorksheet,
            Microsoft.Office.Tools.Excel.ListObject edgeTable,
            Sheet2 vertexWorksheet,
            Microsoft.Office.Tools.Excel.ListObject vertexTable,
            Sheet5 groupWorksheet,
            Microsoft.Office.Tools.Excel.ListObject groupTable,
            Sheet6 groupVertexWorksheet,
            TaskPane taskPane
        )
        {
            Debug.Assert(thisWorkbook != null);
            Debug.Assert(edgeWorksheet != null);
            Debug.Assert(edgeTable != null);
            Debug.Assert(vertexWorksheet != null);
            Debug.Assert(vertexTable != null);
            Debug.Assert(groupWorksheet != null);
            Debug.Assert(groupTable != null);
            Debug.Assert(groupVertexWorksheet != null);
            Debug.Assert(taskPane != null);

            m_oThisWorkbook         = thisWorkbook;
            m_oEdgeWorksheet        = edgeWorksheet;
            m_oVertexWorksheet      = vertexWorksheet;
            m_oGroupWorksheet       = groupWorksheet;
            m_oGroupTable           = groupTable;
            m_oGroupVertexWorksheet = groupVertexWorksheet;
            m_oTaskPane             = taskPane;

            m_bIgnoreSelectionEvents             = false;
            m_bUpdateVertexSelectionOnActivation = false;
            m_bUpdateEdgeSelectionOnActivation   = false;
            m_bUpdateGroupSelectionOnActivation  = false;


            edgeTable.SelectionChange += new DocEvents_SelectionChangeEventHandler(
                EdgeTable_SelectionChange);

            edgeTable.Deselected += new DocEvents_SelectionChangeEventHandler(
                EdgeTable_Deselected);

            m_oEdgeWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
                EdgeWorksheet_ActivateEvent);


            vertexTable.SelectionChange +=
                new DocEvents_SelectionChangeEventHandler(
                    VertexTable_SelectionChange);

            vertexTable.Deselected += new DocEvents_SelectionChangeEventHandler(
                VertexTable_Deselected);

            m_oVertexWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
                VertexWorksheet_ActivateEvent);


            m_oGroupTable.SelectionChange +=
                new DocEvents_SelectionChangeEventHandler(
                    GroupTable_SelectionChange);

            m_oGroupTable.Deselected += new DocEvents_SelectionChangeEventHandler(
                GroupTable_Deselected);

            m_oGroupWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
                GroupWorksheet_ActivateEvent);


            m_oTaskPane.SelectionChangedInGraph +=
                new EventHandler(this.TaskPane_SelectionChangedInGraph);
        }
Esempio n. 5
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();
            }
        }