public FiberSpliceCommand()
        {
            try
            {
                if (ArcMap.Editor == null)
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Editor License not found.", "FiberSpliceConnectionCommand()");
                    return;
                }

                // -----------------------------------
                // Construct a new hook helper and a
                // splice helper that does all the
                // cable to cable splice work
                // -----------------------------------
                _hookHelper = HookHelperExt.Instance(this.Hook);
                _spliceHelper = new FiberSpliceHelper(_hookHelper, ArcMap.Editor as IEditor3);

                // -----------------------------------
                // Always hide splice window on
                // any initialization
                // -----------------------------------
                UID dockWinID = new UIDClass();
                dockWinID.Value = @"esriTelcoTools_FiberSpliceWindow";
                IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID);
                dockWindow.Show(false);

                // -----------------------------------
                // Track the start and stop of editing
                // -----------------------------------
                Events.OnStartEditing += new IEditEvents_OnStartEditingEventHandler(Events_OnStartEditing);
                Events.OnStopEditing += new IEditEvents_OnStopEditingEventHandler(Events_OnStopEditing);
            }
            catch (Exception ex)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "FiberSpliceCommand()", ex.Message);
            }
        }
        public FiberEditorExtension()
        {
            try
            {
                // --------------------------------------
                // Initialize log window with log helper
                // --------------------------------------
                _logHelper = LogHelper.Instance();
                TelecomToolsLogWindow.AddinImpl winImpl =
                    AddIn.FromID<TelecomToolsLogWindow.AddinImpl>(
                    ThisAddIn.IDs.Esri_Telecom_Tools_Windows_TelecomToolsLogWindow);
                TelecomToolsLogWindow logWindow = winImpl.UI;
                logWindow.InitLog(_logHelper);

                // --------------------
                // Build a hook helper
                // --------------------
                _hookHelper = HookHelperExt.Instance(this.Hook);

                // -------------------------------------------
                // Initialize telecom workspace helper.
                //
                // Listen to ActiveViewChanged event.
                //
                // If this happens the focus map more than
                // likely changed. Since the tools go after
                // layers in the TOC we probably need to close
                // the current telecom workspace since
                // editing etc could not longer be done.
                // Should add code to ask for saving changes.
                // -------------------------------------------
                _wkspHelper = TelecomWorkspaceHelper.Instance();
                _wkspHelper.ActiveViewChanged += new EventHandler(_wkspHelper_ActiveViewChanged);

                // -------------------------------------------
                // Build helpers that actually do all object
                // creation work for special feature types
                // -------------------------------------------
                _fiberCableHelper = new FiberCableConfigHelper(_hookHelper, ArcMap.Editor as IEditor3);
                _fiberDeviceHelper = new FiberDeviceConfigHelper(_hookHelper, ArcMap.Editor as IEditor3);

                // --------------------------------------------
                // Splice and Connection helpers
                // --------------------------------------------
                _spliceHelper = new FiberSpliceHelper(_hookHelper, ArcMap.Editor as IEditor3);
                _connectionHelper = new FiberDeviceConnectionHelper(_hookHelper, ArcMap.Editor as IEditor3);

                _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Telecom Extension Constructed.");
            }
            catch (Exception ex)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "General error.", ex.ToString());
            }
        }
        /// <summary>
        /// Load the drop down of selected splice closures
        /// </summary>
        /// <param name="helper">SpliceEditorHelper</param>
        private void PopulateSpliceClosures(FiberSpliceHelper helper)
        {
            try
            {
                // Clear anything that is dependent on what we are about to load
                ClearGrid();
                cboCableA.Items.Clear();
                cboCableB.Items.Clear();
                cboSpliceClosure.Items.Clear();
                lblAvailableA.Text = "";
                lblAvailableB.Text = "";

                // Find the layer
                ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = _hookHelper.FindFeatureLayer(ConfigUtil.SpliceClosureFtClassName);
                if (ftLayer == null)
                {
                    ArcMap.Application.StatusBar.set_Message(0, "Telecom Tools error occurred. Check log for details.");
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Could not find Feature Layer:.", ConfigUtil.SpliceClosureFtClassName);
                    return;
                }
                int displayIdx = ftLayer.FeatureClass.FindField(ftLayer.DisplayField);

                // Get the selection on this layer
                List<ESRI.ArcGIS.Geodatabase.IFeature> selectedSplices = _hookHelper.GetSelectedFeatures(ftLayer);

                for (int i = 0; i < selectedSplices.Count; i++)
                {
                    SpliceClosureWrapper w = new SpliceClosureWrapper(selectedSplices[i], displayIdx);
                    cboSpliceClosure.Items.Add(w);
                }

                if (0 < cboSpliceClosure.Items.Count)
                {
                    cboSpliceClosure.SelectedItem = cboSpliceClosure.Items[0];
                }
            }
            catch (Exception e)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Splice Connection Window (PopulateSpliceClosures): ", e.Message);
            }
        }
        /// <summary>
        /// Load the B dropdown with spliceable cables
        /// </summary>
        /// <param name="helper">SpliceEditorHelper</param>
        /// <param name="cableA">A Cable</param>
        private void PopulateBCables(FiberSpliceHelper helper, FiberCableWrapper cableA)
        {
            try
            {
                // Clear anything that is dependent on what we are about to load
                ClearGrid();
                cboCableB.Items.Clear();
                lblAvailableA.Text = "";
                lblAvailableB.Text = "";

                SpliceClosureWrapper splice = cboSpliceClosure.SelectedItem as SpliceClosureWrapper;
                if (null != splice)
                {
                    List<SpliceableCableWrapper> spliceableCables = _spliceHelper.GetSpliceableCables(cableA, splice);
                    for (int i = 0; i < spliceableCables.Count; i++)
                    {
                        cboCableB.Items.Add(spliceableCables[i]);
                    }

                    if (0 < cboCableB.Items.Count)
                    {
                        cboCableB.SelectedItem = cboCableB.Items[0];
                    }
                }
            }
            catch (Exception e)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Splice Connection Window (PopulateBCables): ", e.Message);
            }
        }
        /// <summary>
        /// Load the A dropdown with selected cables
        /// </summary>
        /// <param name="helper">SpliceEditorHelper</param>
        private void PopulateACables(FiberSpliceHelper helper, SpliceClosureWrapper spliceWrapper)
        {
            try
            {
                // Clear anything that is dependent on what we are about to load
                ClearGrid();
                cboCableA.Items.Clear();
                cboCableB.Items.Clear();
                lblAvailableA.Text = "";
                lblAvailableB.Text = "";

                List<ESRI.ArcGIS.Geodatabase.IFeature> selectedCables = helper.GetConnectedCables(spliceWrapper);
                ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = _hookHelper.FindFeatureLayer(ConfigUtil.FiberCableFtClassName);
                int displayIdx = ftLayer.FeatureClass.FindField(ftLayer.DisplayField);

                for (int i = 0; i < selectedCables.Count; i++)
                {
                    FiberCableWrapper w = new FiberCableWrapper(selectedCables[i], displayIdx);
                    cboCableA.Items.Add(w);
                }

                if (0 < cboCableA.Items.Count)
                {
                    cboCableA.SelectedItem = cboCableA.Items[0];
                }
            }
            catch (Exception e)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Splice Connection Window (PopulateACables): ", e.Message);
            }
        }
        /// <summary>
        /// Checks the database to see if the splice Type field has a domain; if it does load the choices, otherwise
        /// enable free text editing on the column
        /// </summary>
        /// <param name="helper">Helper class</param>
        private void LoadTypeDropdown(FiberSpliceHelper helper)
        {
            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass =   _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
            //                ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass = helper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName);
            //                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(ftClass, ConfigUtil.FiberSpliceTableName);
                ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(fiberSpliceTable.FindField(ConfigUtil.TypeFieldName));

                ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain = typeField.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain;
                if (null != domain)
                {
                    colType.Items.Clear();
                    colType.Items.Add(string.Empty); // For DBNull

                    for (int codeIdx = 0; codeIdx < domain.CodeCount; codeIdx++)
                    {
                        colType.Items.Add(domain.get_Name(codeIdx));
                    }
                }
                else
                {
                    // Change to a text column
                    System.Windows.Forms.DataGridViewTextBoxColumn colTypeText = new DataGridViewTextBoxColumn();
                    colTypeText.HeaderText = colType.HeaderText;
                    colTypeText.Name = colType.Name;
                    grdSplices.Columns.Remove(colType);
                    grdSplices.Columns.Add(colTypeText);
                }
            }
            catch (Exception e)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Splice Connection Window (LoadTypeDropdown): ", e.Message);
            }
        }
        /// <summary>
        /// To prepare and display the form to the user
        /// </summary>
        /// <param name="spliceHelper">Class providing helper methods for splicing</param>
        public void DisplaySplices(FiberSpliceHelper spliceHelper)
        {
            _spliceHelper = spliceHelper;

            // Get splice type domain information
            LoadTypeDropdown(_spliceHelper);

            // Changes the GUI appropriately
            SetEditState(_isEditing);

            // Load the dropdowns with the selected splice closure info.
            PopulateSpliceClosures(_spliceHelper);
        }