Beispiel #1
0
        ThisWorkbook_AttributesEditedInGraph
        (
            Object sender,
            AttributesEditedEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            // The key is the row ID stored in the table's ID column and the value
            // is the one-based row number relative to the worksheet.

            Dictionary <Int32, Int32> oRowIDDictionary;

            if (
                e.EditedVertexAttributes == null
                ||
                !m_oSheets1And2Helper.TableExists
                ||
                !m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary)
                )
            {
                return;
            }

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
                Vertices.InnerObject;

            Globals.ThisWorkbook.ShowWaitCursor = true;

            // Get the columns that might need to be updated.  These columns are
            // not required.

            Microsoft.Office.Interop.Excel.Range oColorColumnData,
                                                 oShapeColumnData, oRadiusColumnData, oAlphaColumnData,
                                                 oVisibilityColumnData, oLabelColumnData, oLabelFillColorColumnData,
                                                 oLabelPositionColumnData, oToolTipColumnData, oLockedColumnData,
                                                 oMarkedColumnData;

            Object [,] aoColorValues          = null;
            Object [,] aoShapeValues          = null;
            Object [,] aoRadiusValues         = null;
            Object [,] aoAlphaValues          = null;
            Object [,] aoVisibilityValues     = null;
            Object [,] aoLabelValues          = null;
            Object [,] aoLabelFillColorValues = null;
            Object [,] aoLabelPositionValues  = null;
            Object [,] aoToolTipValues        = null;
            Object [,] aoLockedValues         = null;
            Object [,] aoMarkedValues         = null;

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.Color, out oColorColumnData,
                                                          out aoColorValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.Shape, out oShapeColumnData,
                                                          out aoShapeValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.Radius, out oRadiusColumnData,
                                                          out aoRadiusValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          CommonTableColumnNames.Alpha, out oAlphaColumnData,
                                                          out aoAlphaValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          CommonTableColumnNames.Visibility, out oVisibilityColumnData,
                                                          out aoVisibilityValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.Label, out oLabelColumnData,
                                                          out aoLabelValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.LabelFillColor,
                                                          out oLabelFillColorColumnData, out aoLabelFillColorValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.LabelPosition, out oLabelPositionColumnData,
                                                          out aoLabelPositionValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.ToolTip, out oToolTipColumnData,
                                                          out aoToolTipValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                          VertexTableColumnNames.Locked, out oLockedColumnData,
                                                          out aoLockedValues);

            if (TryGetMarkedColumnData(out oMarkedColumnData))
            {
                aoMarkedValues = ExcelUtil.GetRangeValues(oMarkedColumnData);
            }

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            VertexVisibilityConverter oVertexVisibilityConverter =
                new VertexVisibilityConverter();

            VertexLabelPositionConverter oVertexLabelPositionConverter =
                new VertexLabelPositionConverter();

            BooleanConverter oBooleanConverter = new BooleanConverter();

            // Loop through the IDs of the vertices whose attributes were edited
            // in the graph.

            EditedVertexAttributes oEditedVertexAttributes =
                e.EditedVertexAttributes;

            foreach (Int32 iID in e.VertexIDs)
            {
                // Look for the row that contains the ID.

                Int32 iRowOneBased;

                if (!oRowIDDictionary.TryGetValue(iID, out iRowOneBased))
                {
                    continue;
                }

                iRowOneBased -= oVertexTable.Range.Row;

                if (oEditedVertexAttributes.Color.HasValue &&
                    aoColorValues != null)
                {
                    aoColorValues[iRowOneBased, 1] =
                        oColorConverter2.GraphToWorkbook(
                            oEditedVertexAttributes.Color.Value);
                }

                if (oEditedVertexAttributes.Shape.HasValue &&
                    aoShapeValues != null)
                {
                    aoShapeValues[iRowOneBased, 1] =
                        oVertexShapeConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Shape.Value);
                }

                if (oEditedVertexAttributes.Radius.HasValue &&
                    aoRadiusValues != null)
                {
                    aoRadiusValues[iRowOneBased, 1] =
                        oEditedVertexAttributes.Radius.Value.ToString();
                }

                if (oEditedVertexAttributes.Alpha.HasValue &&
                    aoAlphaValues != null)
                {
                    aoAlphaValues[iRowOneBased, 1] =
                        oEditedVertexAttributes.Alpha.Value.ToString();
                }

                if (oEditedVertexAttributes.Visibility.HasValue &&
                    aoVisibilityValues != null)
                {
                    aoVisibilityValues[iRowOneBased, 1] =
                        oVertexVisibilityConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Visibility.Value);
                }

                if (!String.IsNullOrEmpty(oEditedVertexAttributes.Label))
                {
                    aoLabelValues[iRowOneBased, 1] = oEditedVertexAttributes.Label;
                }

                if (oEditedVertexAttributes.LabelFillColor.HasValue &&
                    aoLabelFillColorValues != null)
                {
                    aoLabelFillColorValues[iRowOneBased, 1] =
                        oColorConverter2.GraphToWorkbook(
                            oEditedVertexAttributes.LabelFillColor.Value);
                }

                if (oEditedVertexAttributes.LabelPosition.HasValue &&
                    aoLabelPositionValues != null)
                {
                    aoLabelPositionValues[iRowOneBased, 1] =
                        oVertexLabelPositionConverter.GraphToWorkbook(
                            oEditedVertexAttributes.LabelPosition.Value);
                }

                if (!String.IsNullOrEmpty(oEditedVertexAttributes.ToolTip))
                {
                    aoToolTipValues[iRowOneBased, 1] =
                        oEditedVertexAttributes.ToolTip;
                }

                if (oEditedVertexAttributes.Locked.HasValue &&
                    aoLockedValues != null)
                {
                    aoLockedValues[iRowOneBased, 1] =
                        oBooleanConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Locked.Value);
                }

                if (oEditedVertexAttributes.Marked.HasValue &&
                    aoMarkedValues != null)
                {
                    aoMarkedValues[iRowOneBased, 1] =
                        oBooleanConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Marked.Value);
                }
            }

            // Activate this worksheet first, because writing to an inactive
            // worksheet causes problems with the selection in Excel.

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                m_oSheets1And2Helper.GetExcelActiveWorksheetRestorer();

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
                oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject);

            try
            {
                m_oSheets1And2Helper.SetColumnDataValues(
                    oColorColumnData, aoColorValues,
                    oShapeColumnData, aoShapeValues,
                    oRadiusColumnData, aoRadiusValues,
                    oAlphaColumnData, aoAlphaValues,
                    oVisibilityColumnData, aoVisibilityValues,
                    oLabelColumnData, aoLabelValues,
                    oLabelFillColorColumnData, aoLabelFillColorValues,
                    oLabelPositionColumnData, aoLabelPositionValues,
                    oToolTipColumnData, aoToolTipValues,
                    oLockedColumnData, aoLockedValues,
                    oMarkedColumnData, aoMarkedValues
                    );
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            Globals.ThisWorkbook.ShowWaitCursor = false;
        }
        //*************************************************************************
        //  Constructor: VertexAttributesDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="VertexAttributesDialog" />
        /// class.
        /// </summary>
        ///
        /// <param name="nodeXLControl">
        /// NodeXLControl whose vertex attributes need to be edited.
        /// </param>
        //*************************************************************************

        public VertexAttributesDialog
        (
            NodeXLControl nodeXLControl
        )
            : base(nodeXLControl)
        {
            InitializeComponent();

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

            m_oVertexAttributesDialogUserSettings =
                new VertexAttributesDialogUserSettings(this);

            m_oEditedVertexAttributes = GetInitialVertexAttributes();

            (new VertexShapeConverter()).PopulateComboBox(cbxShape, true);

            nudRadius.Minimum =
                (Decimal)VertexRadiusConverter.MinimumRadiusWorkbook;

            nudRadius.Maximum =
                (Decimal)VertexRadiusConverter.MaximumRadiusWorkbook;

            nudAlpha.Minimum = (Decimal)AlphaConverter.MinimumAlphaWorkbook;
            nudAlpha.Maximum = (Decimal)AlphaConverter.MaximumAlphaWorkbook;

            VertexVisibilityConverter oVertexVisibilityConverter =
                new VertexVisibilityConverter();

            String sHide = oVertexVisibilityConverter.GraphToWorkbook(
                VertexWorksheetReader.Visibility.Hide);

            cbxVisibility.PopulateWithObjectsAndText(

                NotEditedMarker, String.Empty,

                VertexWorksheetReader.Visibility.ShowIfInAnEdge,
                oVertexVisibilityConverter.GraphToWorkbook(
                    VertexWorksheetReader.Visibility.ShowIfInAnEdge),

                VertexWorksheetReader.Visibility.Skip,
                oVertexVisibilityConverter.GraphToWorkbook(
                    VertexWorksheetReader.Visibility.Skip),

                VertexWorksheetReader.Visibility.Hide,
                sHide,

                VertexWorksheetReader.Visibility.Show,
                oVertexVisibilityConverter.GraphToWorkbook(
                    VertexWorksheetReader.Visibility.Show)
                );

            SetVisibilityHelpText(lnkVisibility, sHide);

            (new VertexLabelPositionConverter()).PopulateComboBox(
                cbxLabelPosition, true);

            BooleanConverter oBooleanConverter = new BooleanConverter();

            oBooleanConverter.PopulateComboBox(cbxLocked, true);
            oBooleanConverter.PopulateComboBox(cbxMarked, true);

            DoDataExchange(false);

            AssertValid();
        }