public TabbedInspector()
 {
     InitializeComponent();
     if (m_inspector == null)
     {
         //this is the default inspector shipped with the editor
         m_inspector = new FeatureInspector();
     }
 }
Example #2
0
        /// <summary>
        /// Initializes the cache with the provided configuration.
        /// </summary>
        /// <param name="configuration">The configuration for the cache.</param>
        public Cache(CacheConfiguration configuration)
        {
            Check.NotNull(configuration, "configuration");

            _configuration   = configuration;
            _cache           = configuration.Cache;
            _keyCreator      = new KeyCreator(configuration);
            _objectInspector = new ObjectInspector();
        }
        public OSMFeatureInspectorUI()
        {
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            resourceManager = new ResourceManager("ESRI.ArcGIS.OSM.Editor.OSMFeatureInspectorStrings", this.GetType().Assembly);
            _osmUtility = new OSMUtility();

            m_inspector = new FeatureInspectorClass();
        }
        public void prepareGrid4Feature(IFeature currentFeature)
        {
            if (m_inspector == null)
            {
                //this is the default inspector shipped with the editor
                m_inspector = new FeatureInspector();

                SetParent(dataGridView1.Handle.ToInt32(), this.Handle.ToInt32());
            }

            DataGridView featureGridView = this.dataGridView1;

            string featureString = String.Empty;

            //let's get the first domain entry and use it as the main feature theme

            for (int fieldIndex = 0; fieldIndex < currentFeature.Fields.FieldCount; fieldIndex++)
            {
                if (String.IsNullOrEmpty(featureString))
                {
                    if (currentFeature.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString)
                    {
                        System.Object attributeValue = currentFeature.get_Value(fieldIndex);

                        if (attributeValue != System.DBNull.Value)
                        {
                            foreach (string lookingforDomain in m_domainDictionary.Keys)
                            {
                                if (currentFeature.Fields.get_Field(fieldIndex).Name == lookingforDomain)
                                {
                                    featureString = lookingforDomain + "=" + attributeValue.ToString();
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            ESRI.ArcGIS.OSM.OSMClassExtension.osmfeature currentFeatureType = null;

            if (m_editFeatures.Keys.Contains(featureString))
            {
                currentFeatureType = m_editFeatures[featureString];
            }


            // reset the feature grid
            featureGridView.Rows.Clear();


            // rehydrate the tag from the container field
            Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tag> tagList = new Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tag>();
            ESRI.ArcGIS.OSM.OSMClassExtension.tag[] storedTags = null;

            Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tagkey> localTags = new Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tagkey>();

            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tagkey tagKeyItem in m_editTags.Values)
            {
                localTags.Add(tagKeyItem.name, tagKeyItem);
            }

            int tagCollectionFieldIndex = currentFeature.Fields.FindField("osmTags");

            storedTags = _osmUtility.retrieveOSMTags((IRow)currentFeature, tagCollectionFieldIndex, m_editor.EditWorkspace);

            if (storedTags != null)
            {
                foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tag currenttag in storedTags)
                {
                    tagList.Add(currenttag.k, currenttag);
                }
            }

            // if we have a known entity of tag - OSM map feature that is
            if (currentFeatureType != null)
            {
                DataGridViewRow currentRow = new DataGridViewRow();

                // the feature itself is the main osm key value pair
                string[] osmkeyvalue = null;

                try
                {
                    osmkeyvalue = currentFeatureType.name.Split("=".ToCharArray());
                }
                catch { }


                if (osmkeyvalue != null && osmkeyvalue.Length > 1)
                {
                    // name of the tag - tag type
                    DataGridViewCell currentTagCell = new DataGridViewTextBoxCell();
                    currentTagCell.Value = osmkeyvalue[0];

                    // for localization include the translated language into a tooltip
                    if (m_editTags.ContainsKey(osmkeyvalue[0]))
                    {
                        if (!String.IsNullOrEmpty(m_editTags[osmkeyvalue[0]].displayname))
                        {
                            currentTagCell.ToolTipText = m_editTags[osmkeyvalue[0]].displayname;
                        }
                    }

                    currentRow.Cells.Insert(0, currentTagCell);
                    currentRow.Cells[0].ReadOnly = true;

                    // value of the tag
                    DataGridViewCell currentValueCell = null;
                    currentValueCell = new DataGridViewComboBoxCell();
                    foreach (var domainvalue in m_domainDictionary[osmkeyvalue[0]].domainvalue)
                    {
                        if (IsGeometryTypeEqual(currentFeature.Shape.GeometryType, domainvalue.geometrytype))
                        {
                            ((DataGridViewComboBoxCell)currentValueCell).Items.Add(domainvalue.value);
                        }
                    }
                    currentValueCell.Value = osmkeyvalue[1];

                    // for localization include the translated language into a tooltip
                    if (m_editTags.ContainsKey(osmkeyvalue[0]))
                    {
                        ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue[] possibleValues = m_editTags[osmkeyvalue[0]].tagvalue;

                        if (possibleValues != null)
                        {
                            for (int valueIndex = 0; valueIndex < possibleValues.Length; valueIndex++)
                            {
                                if (osmkeyvalue[1].Equals(possibleValues[valueIndex].name) == true)
                                {
                                    if (!String.IsNullOrEmpty(possibleValues[valueIndex].displayname))
                                    {
                                        currentValueCell.ToolTipText = possibleValues[valueIndex].displayname;
                                    }
                                }
                            }
                        }
                    }

                    currentRow.Cells.Insert(1, currentValueCell);
                    currentRow.Cells[1].ReadOnly = false;


                    DataGridViewLinkCell currentInfoCell = new DataGridViewLinkCell();
                    currentInfoCell.LinkBehavior = LinkBehavior.SystemDefault;
                    currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Tag:" + currentFeatureType.name));
                    currentRow.Cells.Insert(2, currentInfoCell);

                    featureGridView.Rows.Add(currentRow);

                    if (tagList.Keys.Contains(osmkeyvalue[0]))
                    {
                        tagList.Remove(osmkeyvalue[0]);
                    }

                    if (localTags.ContainsKey(osmkeyvalue[0]))
                    {
                        localTags.Remove(osmkeyvalue[0]);
                    }
                }

                if (currentFeatureType.tag != null)
                {
                    foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tag osmTagValuePair in currentFeatureType.tag)
                    {
                        try
                        {
                            currentRow = new DataGridViewRow();

                            // name of the tag - tag type
                            DataGridViewCell currentTagCell = new DataGridViewTextBoxCell();
                            currentTagCell.Value = osmTagValuePair.@ref;

                            // for localization include the translated language into a tooltip
                            if (m_editTags.ContainsKey(osmTagValuePair.@ref))
                            {
                                if (!String.IsNullOrEmpty(m_editTags[osmTagValuePair.@ref].displayname))
                                {
                                    currentTagCell.ToolTipText = m_editTags[osmTagValuePair.@ref].displayname;
                                }
                            }

                            currentRow.Cells.Insert(0, currentTagCell);

                            // the default case is not to allow the user change the key field
                            bool canEdit = false;

                            if (m_editTags.ContainsKey(osmTagValuePair.@ref))
                            {
                                if (m_editTags[osmTagValuePair.@ref].editableSpecified)
                                {
                                    canEdit = m_editTags[osmTagValuePair.@ref].editable;
                                }
                            }

                            currentRow.Cells[0].ReadOnly = !canEdit;

                            // value of the tag
                            // depending on the tag type we'll need to create a different cell type
                            DataGridViewCell currentValueCell = null;

                            if (m_editTags.ContainsKey(osmTagValuePair.@ref))
                            {
                                switch (m_editTags[osmTagValuePair.@ref].tagtype)
                                {
                                    case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_list:
                                        currentValueCell = new DataGridViewComboBoxCell();
                                        try
                                        {
                                            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue value in m_editTags[osmTagValuePair.@ref].tagvalue)
                                            {
                                                ((DataGridViewComboBoxCell)currentValueCell).Items.Add(value.name);
                                            }
                                        }

                                        catch (Exception ex)
                                        {
                                            System.Diagnostics.Debug.WriteLine(ex.Message);
                                        }
                                        break;
                                    case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_integer:
                                        currentValueCell = new DataGridViewTextBoxCell();
                                        break;
                                    case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_double:
                                        currentValueCell = new DataGridViewTextBoxCell();
                                        break;
                                    case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_string:
                                        currentValueCell = new DataGridViewTextBoxCell();
                                        break;
                                    default:
                                        currentValueCell = new DataGridViewTextBoxCell();
                                        break;
                                }
                            }
                            else
                            { // unkown keys are treated as strings
                                currentValueCell = new DataGridViewTextBoxCell();
                            }

                            if (tagList.Keys.Contains(osmTagValuePair.@ref))
                            {
                                currentValueCell.Value = tagList[osmTagValuePair.@ref].v;
                            }
                            else
                            {
                                if (osmTagValuePair.value != null)
                                {
                                    currentValueCell.Value = osmTagValuePair.value;
                                }
                            }

                            // for localization include the translated language into a tooltip
                            if (m_editTags.ContainsKey((string)currentTagCell.Value))
                            {
                                if (!String.IsNullOrEmpty((string)currentValueCell.Value))
                                {
                                    ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue[] possibleValues = m_editTags[(string)currentTagCell.Value].tagvalue;

                                    if (possibleValues != null)
                                    {
                                        for (int valueIndex = 0; valueIndex < possibleValues.Length; valueIndex++)
                                        {
                                            if (currentValueCell.Value.Equals(possibleValues[valueIndex].name) == true)
                                            {
                                                if (!String.IsNullOrEmpty(possibleValues[valueIndex].displayname))
                                                {
                                                    currentValueCell.ToolTipText = possibleValues[valueIndex].displayname;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            currentRow.Cells.Insert(1, currentValueCell);

                            // the assumption here is that values are usually open to user edits
                            canEdit = true;
                            currentRow.Cells[1].ReadOnly = !canEdit;

                            DataGridViewLinkCell currentInfoCell = new DataGridViewLinkCell();
                            currentInfoCell.LinkBehavior = LinkBehavior.SystemDefault;

                            if (m_editTags.ContainsKey(osmTagValuePair.@ref))
                            {
                                if (String.IsNullOrEmpty(m_editTags[osmTagValuePair.@ref].infoURL))
                                {
                                    currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Key:" + osmTagValuePair.@ref));
                                }
                                else
                                {
                                    currentInfoCell.Value = new Uri(m_editTags[osmTagValuePair.@ref].infoURL);
                                }
                                currentRow.Cells.Insert(2, currentInfoCell);
                            }
                            else
                            {
                                currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Key:" + osmTagValuePair.@ref));
                            }

                            featureGridView.Rows.Add(currentRow);

                            tagList.Remove(osmTagValuePair.@ref);

                            if (localTags.ContainsKey(osmTagValuePair.@ref))
                            {
                                localTags.Remove(osmTagValuePair.@ref);
                            }
                        }
                        catch { }
                    }
                }
            }


            // for all the remaining tags of whatever is passed into this function - known or unkown
            // list the remaining tag key/value pairs
            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tag currentTag in tagList.Values)
            {
                DataGridViewRow currentRow = new DataGridViewRow();

                DataGridViewCell currentTagCell = new DataGridViewTextBoxCell();
                currentTagCell.Value = currentTag.k;


                // for localization include the translated language into a tooltip
                if (m_editTags.ContainsKey(currentTag.k))
                {
                    if (!String.IsNullOrEmpty(m_editTags[currentTag.k].displayname))
                    {
                        currentTagCell.ToolTipText = m_editTags[currentTag.k].displayname;
                    }
                }


                currentRow.Cells.Insert(0, currentTagCell);

                DataGridViewCell currentValueCell = null;
                if (m_editTags.ContainsKey(currentTag.k))
                {
                    switch (m_editTags[currentTag.k].tagtype)
                    {
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_list:
                            currentValueCell = new DataGridViewComboBoxCell();
                            try
                            {
                                foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue value in m_editTags[currentTag.k].tagvalue)
                                {
                                    ((DataGridViewComboBoxCell)currentValueCell).Items.Add(value.name);
                                }

                                currentValueCell.Value = currentTag.v;
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine(ex.Message);
                            }
                            break;
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_integer:
                            currentValueCell = new DataGridViewTextBoxCell();
                            currentValueCell.Value = Convert.ToInt32(currentTag.v);
                            break;
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_double:
                            currentValueCell = new DataGridViewTextBoxCell();
                            currentValueCell.Value = Convert.ToDouble(currentTag.v);
                            break;
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_string:
                            currentValueCell = new DataGridViewTextBoxCell();
                            currentValueCell.Value = Convert.ToString(currentTag.v);
                            break;
                        default:
                            currentValueCell = new DataGridViewTextBoxCell();
                            break;
                    }
                }
                else
                {
                    currentValueCell = new DataGridViewTextBoxCell();
                    currentValueCell.Value = Convert.ToString(currentTag.v);
                }

                try
                {
                    // for localization include the translated language into a tooltip
                    if (m_editTags.ContainsKey(currentTag.k))
                    {
                        if (!String.IsNullOrEmpty(Convert.ToString(currentValueCell.Value)))
                        {
                            ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue[] possibleValues = m_editTags[currentTag.k].tagvalue;

                            if (possibleValues != null)
                            {
                                for (int valueIndex = 0; valueIndex < possibleValues.Length; valueIndex++)
                                {
                                    if (currentTag.v.Equals(possibleValues[valueIndex].name) == true)
                                    {
                                        if (!String.IsNullOrEmpty(possibleValues[valueIndex].displayname))
                                        {
                                            currentValueCell.ToolTipText = possibleValues[valueIndex].displayname;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch { }

                currentRow.Cells.Insert(1, currentValueCell);

                DataGridViewLinkCell currentInfoCell = new DataGridViewLinkCell();
                currentInfoCell.LinkBehavior = LinkBehavior.SystemDefault;

                if (m_editTags.ContainsKey(currentTag.k))
                {
                    if (String.IsNullOrEmpty(m_editTags[currentTag.k].infoURL))
                    {
                        currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Key:" + currentTag.k));
                    }
                    else
                    {
                        currentInfoCell.Value = new Uri(m_editTags[currentTag.k].infoURL);
                    }
                    currentRow.Cells.Insert(2, currentInfoCell);
                }
                else
                {
                    currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Key:" + currentTag.k));
                }

                featureGridView.Rows.Add(currentRow);

                if (localTags.ContainsKey(currentTag.k))
                {
                    localTags.Remove(currentTag.k);
                }
            }

            // add the list of remaning known tags in the first column of the last row in ascending order
            DataGridViewRow lastRow = new DataGridViewRow();
            DataGridViewComboBoxCell currentKeyCell = new DataGridViewComboBoxCell();
            try
            {
                // show a sorted list of tags to the user
                IEnumerable<string> sortedKeys = localTags.Keys.OrderBy(myKey => myKey);

                foreach (string currentKey in sortedKeys)
                {
                    currentKeyCell.Items.Add(currentKey);
                }

            }
            catch { }

            lastRow.Cells.Insert(0, currentKeyCell);

            featureGridView.Rows.Add(lastRow);

        }
        public void prepareGrid4Features(IEnumRow currentFeatures)
        {
            if (m_inspector == null)
            {
                //this is the default inspector shipped with the editor
                m_inspector = new FeatureInspector();

                SetParent(dataGridView1.Handle.ToInt32(), this.Handle.ToInt32());
            }


            DataGridView featureGridView = this.dataGridView1;

            // reset the feature grid
            featureGridView.Rows.Clear();


            if (currentFeatures == null)
            {
                return;
            }

            currentFeatures.Reset();

            IFeature currentFeature = currentFeatures.Next() as IFeature;

            Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tagkey> potentialTags = new Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tagkey>();


            // determine a unique collection of proposed and existing tags
            List<string> uniqueListofTags = new List<string>();
            Dictionary<string, string> commonTags = new Dictionary<string, string>();
            Geometry.esriGeometryType currentGeometryType = esriGeometryType.esriGeometryNull;
            IEnumerable<ESRI.ArcGIS.OSM.OSMClassExtension.tag> sameTags = null;

            while (currentFeature != null)
            {
                int osmTagsFieldIndex = currentFeature.Fields.FindField("osmTags");
                currentGeometryType = currentFeature.Shape.GeometryType;

                if (osmTagsFieldIndex != -1)
                {
                    ESRI.ArcGIS.OSM.OSMClassExtension.tag[] tagsOnCurrentFeature = _osmUtility.retrieveOSMTags((IRow)currentFeature, osmTagsFieldIndex, m_editor.EditWorkspace);

                    if (sameTags == null && tagsOnCurrentFeature != null)
                    {
                        sameTags = tagsOnCurrentFeature.ToArray<ESRI.ArcGIS.OSM.OSMClassExtension.tag>();
                    }
                    else if (sameTags != null && tagsOnCurrentFeature != null)
                    {
                        IEnumerable<ESRI.ArcGIS.OSM.OSMClassExtension.tag> both = tagsOnCurrentFeature.Intersect(sameTags, new ESRI.ArcGIS.OSM.OSMClassExtension.TagKeyComparer());
                        sameTags = both.ToArray<ESRI.ArcGIS.OSM.OSMClassExtension.tag>();
                    }

                    if (tagsOnCurrentFeature != null)
                    {
                        for (int index = 0; index < tagsOnCurrentFeature.Length; index++)
                        {
                            if (uniqueListofTags.Contains(tagsOnCurrentFeature[index].k) == false)
                            {
                                uniqueListofTags.Add(tagsOnCurrentFeature[index].k);
                            }

                            // check if the tag key already exists
                            if (commonTags.ContainsKey(tagsOnCurrentFeature[index].k) == true)
                            {
                                if (commonTags[tagsOnCurrentFeature[index].k] == tagsOnCurrentFeature[index].v)
                                {
                                    // the tag values still match - don't do anything
                                }
                                else
                                {
                                    // the values are different - purge the existing value
                                    commonTags[tagsOnCurrentFeature[index].k] = String.Empty;
                                }
                            }
                            else
                            {
                                // the tag doesn't exist yet in the overall collection, 
                                // add the first entry
                                commonTags.Add(tagsOnCurrentFeature[index].k, tagsOnCurrentFeature[index].v);
                            }
                        }
                    }
                }

                // determine potential tag candidates based on the osmfeature schema
                string featureString = String.Empty;

                //let's get the first domain entry and use it as the main feature theme

                for (int fieldIndex = 0; fieldIndex < currentFeature.Fields.FieldCount; fieldIndex++)
                {
                    if (String.IsNullOrEmpty(featureString))
                    {
                        if (currentFeature.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString)
                        {
                            System.Object attributeValue = currentFeature.get_Value(fieldIndex);

                            if (attributeValue != System.DBNull.Value)
                            {
                                foreach (string lookingforDomain in m_domainDictionary.Keys)
                                {
                                    if (currentFeature.Fields.get_Field(fieldIndex).Name == lookingforDomain)
                                    {
                                        featureString = lookingforDomain + "=" + attributeValue.ToString();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                ESRI.ArcGIS.OSM.OSMClassExtension.osmfeature OSMInspectorFeatureType = null;

                if (m_editFeatures.Keys.Contains(featureString))
                {
                    OSMInspectorFeatureType = m_editFeatures[featureString];
                }

                if (OSMInspectorFeatureType != null)
                {
                    if (OSMInspectorFeatureType.tag != null)
                    {
                        for (int index = 0; index < OSMInspectorFeatureType.tag.Length; index++)
                        {
                            if (commonTags.ContainsKey(OSMInspectorFeatureType.tag[index].@ref) == false)
                            {
                                commonTags.Add(OSMInspectorFeatureType.tag[index].@ref, String.Empty);
                            }
                        }
                    }
                }

                currentFeature = currentFeatures.Next() as IFeature;
            }


            // get a listing of all possible tags
            Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tagkey> localTags = new Dictionary<string, ESRI.ArcGIS.OSM.OSMClassExtension.tagkey>();

            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tagkey tagKeyItem in m_editTags.Values)
            {
                localTags.Add(tagKeyItem.name, tagKeyItem);
            }


            // now let's go through our unique list of proposed and existing tags
            // and fill the grid accordingly

            DataGridViewRow currentRow = null;

            foreach (KeyValuePair<string, string> osmTagValuePair in commonTags)
            {
                currentRow = new DataGridViewRow();

                // name of the tag - tag type
                DataGridViewCell currentTagCell = new DataGridViewTextBoxCell();
                currentTagCell.Value = osmTagValuePair.Key;

                // for localization include the translated language into a tooltip
                if (m_editTags.ContainsKey(osmTagValuePair.Key))
                {
                    if (!String.IsNullOrEmpty(m_editTags[osmTagValuePair.Key].displayname))
                    {
                        currentTagCell.ToolTipText = m_editTags[osmTagValuePair.Key].displayname;
                    }
                }


                currentRow.Cells.Insert(0, currentTagCell);

                // the default case is not to allow the user change the key field
                bool canEdit = false;

                if (m_editTags.ContainsKey(osmTagValuePair.Key))
                {
                    if (m_editTags[osmTagValuePair.Key].editableSpecified)
                    {
                        canEdit = m_editTags[osmTagValuePair.Key].editable;
                    }
                }

                currentRow.Cells[0].ReadOnly = !canEdit;

                // value of the tag
                // depending on the tag type we'll need to create a different cell type
                DataGridViewCell currentValueCell = null;

                if (m_editTags.ContainsKey(osmTagValuePair.Key))
                {
                    switch (m_editTags[osmTagValuePair.Key].tagtype)
                    {
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_list:
                            currentValueCell = new DataGridViewComboBoxCell();
                            try
                            {
                                foreach (ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue value in m_editTags[osmTagValuePair.Key].tagvalue)
                                {
                                    ((DataGridViewComboBoxCell)currentValueCell).Items.Add(value.name);
                                }
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine(ex.Message);
                            }
                            break;
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_integer:
                            currentValueCell = new DataGridViewTextBoxCell();
                            break;
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_double:
                            currentValueCell = new DataGridViewTextBoxCell();
                            break;
                        case ESRI.ArcGIS.OSM.OSMClassExtension.tagkeyTagtype.tag_string:
                            currentValueCell = new DataGridViewTextBoxCell();
                            break;
                        default:
                            currentValueCell = new DataGridViewTextBoxCell();
                            break;
                    }
                }
                else if (m_domainDictionary.ContainsKey(osmTagValuePair.Key))
                {
                    currentValueCell = new DataGridViewComboBoxCell();
                    ESRI.ArcGIS.OSM.OSMClassExtension.domain currentDomain = null;

                    switch (currentGeometryType)
                    {
                        case esriGeometryType.esriGeometryAny:
                            break;
                        case esriGeometryType.esriGeometryBag:
                            break;
                        case esriGeometryType.esriGeometryBezier3Curve:
                            break;
                        case esriGeometryType.esriGeometryCircularArc:
                            break;
                        case esriGeometryType.esriGeometryEllipticArc:
                            break;
                        case esriGeometryType.esriGeometryEnvelope:
                            break;
                        case esriGeometryType.esriGeometryLine:
                            break;
                        case esriGeometryType.esriGeometryMultiPatch:
                            break;
                        case esriGeometryType.esriGeometryMultipoint:
                            break;
                        case esriGeometryType.esriGeometryNull:
                            break;
                        case esriGeometryType.esriGeometryPath:
                            break;
                        case esriGeometryType.esriGeometryPoint:
                            currentDomain = m_domainDictionary[osmTagValuePair.Key];

                            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.domainvalue item in currentDomain.domainvalue)
                            {
                                for (int geometryIndex = 0; geometryIndex < item.geometrytype.Length; geometryIndex++)
                                {
                                    if (item.geometrytype[geometryIndex] == ESRI.ArcGIS.OSM.OSMClassExtension.geometrytype.point)
                                    {
                                        try
                                        {
                                            ((DataGridViewComboBoxCell)currentValueCell).Items.Add(item.value);
                                        }
                                        catch (Exception ex)
                                        {
                                            System.Diagnostics.Debug.WriteLine(ex.Message);
                                        }
                                    }
                                }
                            }
                            break;
                        case esriGeometryType.esriGeometryPolygon:
                            currentDomain = m_domainDictionary[osmTagValuePair.Key];

                            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.domainvalue item in currentDomain.domainvalue)
                            {
                                for (int geometryIndex = 0; geometryIndex < item.geometrytype.Length; geometryIndex++)
                                {
                                    if (item.geometrytype[geometryIndex] == ESRI.ArcGIS.OSM.OSMClassExtension.geometrytype.polygon)
                                    {
                                        try
                                        {
                                            ((DataGridViewComboBoxCell)currentValueCell).Items.Add(item.value);
                                        }
                                        catch (Exception ex)
                                        {
                                            System.Diagnostics.Debug.WriteLine(ex.Message);
                                        }
                                    }
                                }
                            }
                            break;
                        case esriGeometryType.esriGeometryPolyline:
                            currentDomain = m_domainDictionary[osmTagValuePair.Key];

                            foreach (ESRI.ArcGIS.OSM.OSMClassExtension.domainvalue item in currentDomain.domainvalue)
                            {
                                for (int geometryIndex = 0; geometryIndex < item.geometrytype.Length; geometryIndex++)
                                {
                                    if (item.geometrytype[geometryIndex] == ESRI.ArcGIS.OSM.OSMClassExtension.geometrytype.line)
                                    {
                                        try
                                        {
                                            ((DataGridViewComboBoxCell)currentValueCell).Items.Add(item.value);
                                        }
                                        catch (Exception ex)
                                        {
                                            System.Diagnostics.Debug.WriteLine(ex.Message);
                                        }
                                    }
                                }
                            }
                            break;
                        case esriGeometryType.esriGeometryRay:
                            break;
                        case esriGeometryType.esriGeometryRing:
                            break;
                        case esriGeometryType.esriGeometrySphere:
                            break;
                        case esriGeometryType.esriGeometryTriangleFan:
                            break;
                        case esriGeometryType.esriGeometryTriangleStrip:
                            break;
                        case esriGeometryType.esriGeometryTriangles:
                            break;
                        default:
                            break;
                    }
                }
                else
                { // unkown keys are treated as strings
                    currentValueCell = new DataGridViewTextBoxCell();
                }

                // add the value only we have a value and if the tag is common among all features
                if (String.IsNullOrEmpty(osmTagValuePair.Value) == false)
                {
                    ESRI.ArcGIS.OSM.OSMClassExtension.tag compareTag = new ESRI.ArcGIS.OSM.OSMClassExtension.tag();
                    compareTag.k = osmTagValuePair.Key;

                    if (sameTags.Contains(compareTag, new ESRI.ArcGIS.OSM.OSMClassExtension.TagKeyComparer()))
                    {
                        currentValueCell.Value = osmTagValuePair.Value;
                    }
                }

                // for localization include the translated language into a tooltip
                if (m_editTags.ContainsKey((string)currentTagCell.Value))
                {
                    if (!String.IsNullOrEmpty((string)currentValueCell.Value))
                    {
                        ESRI.ArcGIS.OSM.OSMClassExtension.tagvalue[] possibleValues = m_editTags[(string)currentTagCell.Value].tagvalue;

                        if (possibleValues != null)
                        {
                            for (int valueIndex = 0; valueIndex < possibleValues.Length; valueIndex++)
                            {
                                if (currentValueCell.Value.Equals(possibleValues[valueIndex].name) == true)
                                {
                                    if (!String.IsNullOrEmpty(possibleValues[valueIndex].displayname))
                                    {
                                        currentValueCell.ToolTipText = possibleValues[valueIndex].displayname;
                                    }
                                }
                            }
                        }
                    }
                }

                currentRow.Cells.Insert(1, currentValueCell);

                // the assumption here is that values are usually open to user edits
                canEdit = true;
                currentRow.Cells[1].ReadOnly = !canEdit;

                DataGridViewLinkCell currentInfoCell = new DataGridViewLinkCell();
                currentInfoCell.LinkBehavior = LinkBehavior.SystemDefault;

                if (m_editTags.ContainsKey(osmTagValuePair.Key))
                {
                    if (String.IsNullOrEmpty(m_editTags[osmTagValuePair.Key].infoURL))
                    {
                        currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Key:" + osmTagValuePair.Key));
                    }
                    else
                    {
                        currentInfoCell.Value = new Uri(m_editTags[osmTagValuePair.Key].infoURL);
                    }
                    currentRow.Cells.Insert(2, currentInfoCell);
                }
                else
                {
                    currentInfoCell.Value = new Uri(m_baseInfoURI + HttpUtility.UrlEncode("Key:" + osmTagValuePair.Key));
                }

                featureGridView.Rows.Add(currentRow);

                if (localTags.ContainsKey(osmTagValuePair.Key))
                {
                    localTags.Remove(osmTagValuePair.Key);
                }
            }

            // add the list in the first column of the last row
            DataGridViewRow lastRow = new DataGridViewRow();
            DataGridViewComboBoxCell currentKeyCell = new DataGridViewComboBoxCell();
            try
            {
                // show a sorted list of tags to the user
                IEnumerable<string> sortedKeys = localTags.Keys.OrderBy(myKey => myKey);

                foreach (string currentKey in sortedKeys)
                {
                    currentKeyCell.Items.Add(currentKey);
                }
            }
            catch { }

            lastRow.Cells.Insert(0, currentKeyCell);

            featureGridView.Rows.Add(lastRow);

        }
        void IObjectInspector.Inspect(IEnumRow objects, IEditor Editor)
        {
            try
            {
                if (m_inspector == null)
                {
                    m_inspector = new FeatureInspectorClass();
                }

                //SetParent(m_inspector.HWND, this.Handle.ToInt32());
                ShowWindow(m_inspector.HWND, SW_SHOW);

                m_inspector.Inspect(objects, Editor);

                if (Editor == null)
                {
                    return;
                }

                if (objects == null)
                {
                    return;
                }

                if (IsInitialized == false)
                    Init(Editor);

                m_editor = Editor;
                m_enumRow = objects;

                IEnumFeature enumFeatures = Editor.EditSelection;
                enumFeatures.Reset();

                int featureCount = 0;

                while (enumFeatures.Next() != null)
                {
                    featureCount = featureCount + 1;
                }

                IEnumRow enumRow = objects;
                enumRow.Reset();
                IRow row = enumRow.Next();

                IFeature inspFeature = (IFeature)row;

                //user selected the layer name instead of a feature.
                if (objects.Count > 1)
                {
                    prepareGrid4Features(objects);
                }
                else
                {
                    prepareGrid4Feature(inspFeature);
                }

                currentlyEditedRows = enumRow;
            }
            catch (Exception ex)
            {
                ClearGrid();

                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        void IObjectInspector.Copy(IRow srcRow)
        {
            if (m_inspector == null)
            {
                m_inspector = new FeatureInspectorClass();
            }

            if (m_inspector != null)
            {
                m_inspector.Copy(srcRow);
            }
        }
        //#region IObjectInspector Members

        //public void Clear()
        //{
        //    throw new NotImplementedException();
        //}

        //public void Copy(IRow srcRow)
        //{
        //    throw new NotImplementedException();
        //}

        //public int HWND
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //public void Inspect(IEnumRow objects, IEditor Editor)
        //{
        //    try
        //    {
        //        if (m_inspector == null)
        //        {
        //            m_inspector = new FeatureInspectorClass();
        //        }

        //        ShowWindow(m_inspector.HWND, SW_SHOW);
        //        m_inspector.Inspect(objects, Editor);

        //        if (Editor == null)
        //        {
        //            return;
        //        }

        //        if (objects == null)
        //        {
        //            return;
        //        }

        //        if (IsInitialized == false)
        //            Init(Editor);

        //        m_editor = Editor;
        //        m_enumRow = objects;

        //        IEnumFeature enumFeatures = Editor.EditSelection;
        //        enumFeatures.Reset();

        //        int featureCount = 0;

        //        while (enumFeatures.Next() != null)
        //        {
        //            featureCount = featureCount + 1;
        //        }

        //        IEnumRow enumRow = objects;
        //        enumRow.Reset();
        //        IRow row = enumRow.Next();

        //        IFeature inspFeature = (IFeature)row;

        //        //user selected the layer name instead of a feature.
        //        if (objects.Count > 1)
        //        {
        //            prepareGrid4Features(objects);
        //        }
        //        else
        //        {
        //            prepareGrid4Feature(inspFeature);
        //        }

        //        currentlyEditedRows = enumRow;
        //    }
        //    catch (Exception ex)
        //    {
        //        ClearGrid();

        //        System.Diagnostics.Debug.WriteLine(ex.Message);
        //    }


        //}

        //#endregion

        #region

        void IObjectInspector.Clear()
        {
            if (m_inspector == null)
            {
                m_inspector = new FeatureInspectorClass();
            }

            if (m_inspector != null)
            {
                ClearGrid();
                m_inspector.Clear();
            }
        }
        public void Init(IEditor Editor)
        {
            if (m_inspector == null)
            {
                //this is the default inspector shipped with the editor
                m_inspector = new FeatureInspector();

                SetParent(dataGridView1.Handle.ToInt32(), this.Handle.ToInt32());
            }

            m_editor = Editor;


            if (m_editor != null)
            {

                ReadOSMEditorSettings();

                try
                {
                    // populate the internal dictionary and rule set for the OSM features
                    loadOSMEditFeatures(m_osmFeaturePropertiesFilePath);

                    // populate the internal list of available OSM feature domains
                    loadOSMDomains(m_osmDomainsFilePath);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }

            m_isInitialized = true;
        }
 /// <summary>
 /// Informs the extension that its class helper is going away.
 /// </summary>
 public void Shutdown()
 {
     m_inspector   = null;
     m_classHelper = null;
 }
 public TabbedInspector()
 {
   InitializeComponent();
   if (m_inspector == null)
   {
     //this is the default inspector shipped with the editor
     m_inspector = new FeatureInspector();
   }
 }
 /// <summary>
 /// Informs the extension that its class helper is going away.
 /// </summary>
 public void Shutdown()
 {
   m_inspector = null;
   m_classHelper = null;
 }