Beispiel #1
0
        TryRemoveSelectedVerticesFromGroups
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet,
            out ICollection <String> oSelectedVertexNames
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);

            oSelectedVertexNames = oVertexWorksheet.GetSelectedVertexNames();

            ExcelUtil.RemoveTableRowsByStringColumnValues(oWorkbook,
                                                          WorksheetNames.GroupVertices, TableNames.GroupVertices,
                                                          GroupVertexTableColumnNames.VertexName, oSelectedVertexNames);

            return(true);
        }
Beispiel #2
0
        TrySelectGroupsWithSelectedVertices
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet,
            Sheet5 oGroupWorksheet
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);
            Debug.Assert(oGroupWorksheet != null);

            // For each selected vertex, get the vertex's group name from the
            // group-vertex worksheet and select that group in the group worksheet.

            ICollection <String> oSelectedVertexNames =
                oVertexWorksheet.GetSelectedVertexNames();

            oGroupWorksheet.SelectGroups(
                NodeXLWorkbookUtil.GetGroupNamesByVertexName(oWorkbook,
                                                             oSelectedVertexNames));

            return(true);
        }
Beispiel #3
0
        //*************************************************************************
        //  Method: TrySelectGroupsWithSelectedVertices()
        //
        /// <summary>
        /// Attempts to select the groups containing the selected vertices in the
        /// workbook.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// NodeXL workbook.
        /// </param>
        ///
        /// <param name="oVertexWorksheet">
        /// The vertex worksheet in the NodeXL workbook.
        /// </param>
        ///
        /// <param name="oGroupWorksheet">
        /// The group worksheet in the NodeXL workbook.
        /// </param>
        ///
        /// <returns>
        /// true if successful.
        /// </returns>
        ///
        /// <remarks>
        /// This method activates the group worksheet.
        /// </remarks>
        //*************************************************************************
        private static Boolean TrySelectGroupsWithSelectedVertices(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet,
            Sheet5 oGroupWorksheet
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);
            Debug.Assert(oGroupWorksheet != null);

            // For each selected vertex, get the vertex's group name from the
            // group-vertex worksheet and select that group in the group worksheet.

            ICollection<String> oSelectedVertexNames =
            oVertexWorksheet.GetSelectedVertexNames();

            oGroupWorksheet.SelectGroups(
            NodeXLWorkbookUtil.GetGroupNamesByVertexName(oWorkbook,
                oSelectedVertexNames) );

            return (true);
        }
Beispiel #4
0
        //*************************************************************************
        //  Method: TryRemoveSelectedVerticesFromGroups()
        //
        /// <summary>
        /// Attempts to remove the selected vertices from their groups in the
        /// workbook.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// NodeXL workbook.
        /// </param>
        ///
        /// <param name="oVertexWorksheet">
        /// The vertex worksheet in the NodeXL workbook.
        /// </param>
        ///
        /// <param name="oSelectedVertexNames">
        /// Where a collection of the selected vertex names gets stored if true is
        /// returned.
        /// </param>
        ///
        /// <returns>
        /// true if successful.
        /// </returns>
        //*************************************************************************
        private static Boolean TryRemoveSelectedVerticesFromGroups(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet,
            out ICollection<String> oSelectedVertexNames
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);

            oSelectedVertexNames = oVertexWorksheet.GetSelectedVertexNames();

            ExcelUtil.RemoveTableRowsByStringColumnValues(oWorkbook,
            WorksheetNames.GroupVertices, TableNames.GroupVertices,
            GroupVertexTableColumnNames.VertexName, oSelectedVertexNames);

            return (true);
        }
Beispiel #5
0
        //*************************************************************************
        //  Method: TryAddSelectedVerticesToGroup()
        //
        /// <summary>
        /// Attempts to add the selected vertices to a new or existing group.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// NodeXL workbook.
        /// </param>
        ///
        /// <param name="oVertexWorksheet">
        /// The vertex worksheet in the NodeXL workbook.
        /// </param>
        ///
        /// <returns>
        /// true if successful.
        /// </returns>
        //*************************************************************************
        private static Boolean TryAddSelectedVerticesToGroup(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);

            AddSelectedVerticesToGroupDialog oAddSelectedVerticesToGroupDialog =
            new AddSelectedVerticesToGroupDialog(oWorkbook);

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

            // First, remove the selected vertices from any groups they belong to.

            ListObject oGroupTable, oGroupVertexTable;
            ICollection<String> oSelectedVertexNames;

            if (
            !TryRemoveSelectedVerticesFromGroups(oWorkbook, oVertexWorksheet,
                out oSelectedVertexNames)
            ||
            !ExcelUtil.TryGetTable(oWorkbook, WorksheetNames.Groups,
                TableNames.Groups, out oGroupTable)
            ||
            !ExcelUtil.TryGetTable(oWorkbook, WorksheetNames.GroupVertices,
                TableNames.GroupVertices, out oGroupVertexTable)
            )
            {
            return (false);
            }

            String sGroupName = oAddSelectedVerticesToGroupDialog.GroupName;

            if (oAddSelectedVerticesToGroupDialog.IsNewGroup)
            {
            // Add the new group to the group table.

            ExcelUtil.TryAddTableRow(oGroupTable,

                GroupTableColumnNames.Name,
                sGroupName
                );

            SetVertexAttributesForAllGroups(oGroupTable);
            }

            // Add the selected vertices to the group-vertex table.

            foreach (String sSelectedVertexName in oSelectedVertexNames)
            {
            ExcelUtil.TryAddTableRow(oGroupVertexTable,

                GroupVertexTableColumnNames.GroupName,
                sGroupName,

                GroupVertexTableColumnNames.VertexName,
                sSelectedVertexName,

                GroupVertexTableColumnNames.VertexID,
                GetExcelFormulaForVertexID()
                );
            }

            return (true);
        }
Beispiel #6
0
        //*************************************************************************
        //  Method: TryRunGroupCommand()
        //
        /// <summary>
        /// Attempts to run a group command.
        /// </summary>
        ///
        /// <param name="groupCommand">
        /// One of the flags in the <see cref="GroupCommands" /> enumeration.
        /// </param>
        ///
        /// <param name="workbook">
        /// NodeXL workbook.
        /// </param>
        ///
        /// <param name="vertexWorksheet">
        /// The vertex worksheet in the NodeXL workbook.
        /// </param>
        ///
        /// <param name="groupWorksheet">
        /// The group worksheet in the NodeXL workbook.
        /// </param>
        ///
        /// <returns>
        /// true if successful.
        /// </returns>
        ///
        /// <remarks>
        /// This method may modify the contents of the workbook.  It does not
        /// interact with the TaskPane, which contains the graph created from the
        /// workbook.  It is the responsibility of the caller to communicate
        /// group changes to the TaskPane when necessary.
        ///
        /// <para>
        /// This method activates various worksheets to read their selection and
        /// write their contents.  It is the responsibility of the caller to save
        /// the active worksheet state before calling this method and restore it
        /// afterward.
        /// </para>
        ///
        /// </remarks>
        //*************************************************************************
        public static Boolean TryRunGroupCommand(
            GroupCommands groupCommand,
            Microsoft.Office.Interop.Excel.Workbook workbook,
            Sheet2 vertexWorksheet,
            Sheet5 groupWorksheet
            )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(vertexWorksheet != null);
            Debug.Assert(groupWorksheet != null);

            switch (groupCommand)
            {
            case GroupCommands.None:

                return (true);

            case GroupCommands.CollapseSelectedGroups:

                return ( TryCollapseOrExpandSelectedGroups(workbook, true) );

            case GroupCommands.ExpandSelectedGroups:

                return ( TryCollapseOrExpandSelectedGroups(workbook, false) );

            case GroupCommands.CollapseAllGroups:

                return ( TryCollapseOrExpandAllGroups(workbook, true) );

            case GroupCommands.ExpandAllGroups:

                return ( TryCollapseOrExpandAllGroups(workbook, false) );

            case GroupCommands.SelectGroupsWithSelectedVertices:

                return ( TrySelectGroupsWithSelectedVertices(workbook,
                    vertexWorksheet, groupWorksheet) );

            case GroupCommands.SelectAllGroups:

                return ( TrySelectAllGroups(workbook) );

            case GroupCommands.AddSelectedVerticesToGroup:

                return ( TryAddSelectedVerticesToGroup(workbook,
                    vertexWorksheet) );

            case GroupCommands.RemoveSelectedVerticesFromGroups:

                ICollection<String> oSelectedVertexNames;

                return ( TryRemoveSelectedVerticesFromGroups(workbook,
                    vertexWorksheet, out oSelectedVertexNames) );

            case GroupCommands.RemoveSelectedGroups:

                return ( TryRemoveSelectedGroups(workbook, groupWorksheet) );

            case GroupCommands.RemoveAllGroups:

                return ( TryRemoveAllGroups(workbook) );

            default:

                Debug.Assert(false);
                return (false);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
0
        TryAddSelectedVerticesToGroup
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);

            AddSelectedVerticesToGroupDialog oAddSelectedVerticesToGroupDialog =
                new AddSelectedVerticesToGroupDialog(oWorkbook);

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

            // First, remove the selected vertices from any groups they belong to.

            ListObject           oGroupTable, oGroupVertexTable;
            ICollection <String> oSelectedVertexNames;

            if (
                !TryRemoveSelectedVerticesFromGroups(oWorkbook, oVertexWorksheet,
                                                     out oSelectedVertexNames)
                ||
                !ExcelUtil.TryGetTable(oWorkbook, WorksheetNames.Groups,
                                       TableNames.Groups, out oGroupTable)
                ||
                !ExcelUtil.TryGetTable(oWorkbook, WorksheetNames.GroupVertices,
                                       TableNames.GroupVertices, out oGroupVertexTable)
                )
            {
                return(false);
            }

            String sGroupName = oAddSelectedVerticesToGroupDialog.GroupName;

            if (oAddSelectedVerticesToGroupDialog.IsNewGroup)
            {
                // Add the new group to the group table.

                ExcelUtil.TryAddTableRow(oGroupTable,

                                         GroupTableColumnNames.Name,
                                         sGroupName
                                         );

                SetVertexAttributesForAllGroups(oGroupTable);
            }

            // Add the selected vertices to the group-vertex table.

            foreach (String sSelectedVertexName in oSelectedVertexNames)
            {
                ExcelUtil.TryAddTableRow(oGroupVertexTable,

                                         GroupVertexTableColumnNames.GroupName,
                                         sGroupName,

                                         GroupVertexTableColumnNames.VertexName,
                                         sSelectedVertexName,

                                         GroupVertexTableColumnNames.VertexID,
                                         GetExcelFormulaForVertexID()
                                         );
            }

            return(true);
        }
Beispiel #9
0
        TryRunGroupCommand
        (
            GroupCommands groupCommand,
            Microsoft.Office.Interop.Excel.Workbook workbook,
            Sheet2 vertexWorksheet,
            Sheet5 groupWorksheet
        )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(vertexWorksheet != null);
            Debug.Assert(groupWorksheet != null);

            switch (groupCommand)
            {
            case GroupCommands.None:

                return(true);

            case GroupCommands.CollapseSelectedGroups:

                return(TryCollapseOrExpandSelectedGroups(workbook, true));

            case GroupCommands.ExpandSelectedGroups:

                return(TryCollapseOrExpandSelectedGroups(workbook, false));

            case GroupCommands.CollapseAllGroups:

                return(TryCollapseOrExpandAllGroups(workbook, true));

            case GroupCommands.ExpandAllGroups:

                return(TryCollapseOrExpandAllGroups(workbook, false));

            case GroupCommands.SelectGroupsWithSelectedVertices:

                return(TrySelectGroupsWithSelectedVertices(workbook,
                                                           vertexWorksheet, groupWorksheet));

            case GroupCommands.SelectAllGroups:

                return(TrySelectAllGroups(workbook));

            case GroupCommands.AddSelectedVerticesToGroup:

                return(TryAddSelectedVerticesToGroup(workbook,
                                                     vertexWorksheet));

            case GroupCommands.RemoveSelectedVerticesFromGroups:

                ICollection <String> oSelectedVertexNames;

                return(TryRemoveSelectedVerticesFromGroups(workbook,
                                                           vertexWorksheet, out oSelectedVertexNames));

            case GroupCommands.RemoveSelectedGroups:

                return(TryRemoveSelectedGroups(workbook, groupWorksheet));

            case GroupCommands.RemoveAllGroups:

                return(TryRemoveAllGroups(workbook));

            default:

                Debug.Assert(false);
                return(false);
            }
        }