public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context == null) { return(null); } if (context.Instance == null) { return(null); } // FeatureClass::ShapeFieldName, AreaFieldName, LengthFieldName, ShapeFieldName // GeometricNetworkControllerMembership::EnabledFieldName, AncillaryRoleFieldName // IndexField::Name // ObjectClass::OIDFieldName, GlobalIDFieldName, RasterFieldName, SubtypeFieldName, OIDFieldName, GlobalIDFieldName // RelationshipClass::OriginPrimary, OriginForeign, DestinationPrimary, DestinationForeign // SubtypeField::FieldName // NetWeightAssociation::FieldName // TerrainDataSource::HeightField, TagValueField // Create List List <string> list = new List <string>(); DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default; SchemaModel schemaModel = diagrammerEnvironment.SchemaModel; if (context.PropertyDescriptor.ComponentType == typeof(IndexField)) { IndexField indexField = (IndexField)context.Instance; ObjectClass objectClass = (ObjectClass)indexField.Table; foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(GeometricNetworkControllerMembership)) { GeometricNetworkControllerMembership geometricNetworkControllerMembership = (GeometricNetworkControllerMembership)context.Instance; ObjectClass objectClass = schemaModel.FindParent(geometricNetworkControllerMembership); foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(SubtypeField)) { SubtypeField subtypeField = (SubtypeField)context.Instance; Subtype subtype = (Subtype)subtypeField.Table; ObjectClass objectClass = subtype.GetParent(); foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(ObjectClass)) { ObjectClass objectClass = (ObjectClass)context.Instance; foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass)) { RelationshipClass relationshipClass = (RelationshipClass)context.Instance; if (relationshipClass.IsAttributed) { switch (context.PropertyDescriptor.Name) { case "OIDFieldName": case "GlobalIDFieldName": case "RasterFieldName": case "SubtypeFieldName": foreach (Field field in relationshipClass.GetFields()) { list.Add(field.Name); } break; case "OriginPrimary": ObjectClass objectClass1 = schemaModel.FindObjectClass(relationshipClass.OriginClassName); foreach (Field field in objectClass1.GetFields()) { list.Add(field.Name); } break; case "OriginForeign": case "DestinationForeign": foreach (Field field in relationshipClass.GetFields()) { list.Add(field.Name); } break; case "DestinationPrimary": ObjectClass objectClass2 = schemaModel.FindObjectClass(relationshipClass.DestinationClassName); foreach (Field field in objectClass2.GetFields()) { list.Add(field.Name); } break; } } else { switch (context.PropertyDescriptor.Name) { case "OIDFieldName": case "GlobalIDFieldName": case "RasterFieldName": case "SubtypeFieldName": foreach (Field field in relationshipClass.GetFields()) { list.Add(field.Name); } break; case "OriginPrimary": ObjectClass objectClass1 = schemaModel.FindObjectClass(relationshipClass.OriginClassName); foreach (Field field in objectClass1.GetFields()) { list.Add(field.Name); } break; case "OriginForeign": ObjectClass objectClass2 = schemaModel.FindObjectClass(relationshipClass.DestinationClassName); foreach (Field field in objectClass2.GetFields()) { list.Add(field.Name); } break; case "DestinationPrimary": case "DestinationForeign": break; } } } else if ( context.PropertyDescriptor.ComponentType == typeof(FeatureClass) || context.PropertyDescriptor.ComponentType == typeof(RasterCatalog)) { FeatureClass featureClass = (FeatureClass)context.Instance; foreach (Field field in featureClass.GetFields()) { list.Add(field.Name); } } else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation)) { NetWeightAssociation netWeightAssociation = (NetWeightAssociation)context.Instance; if (netWeightAssociation != null) { if (!string.IsNullOrEmpty(netWeightAssociation.TableName)) { ObjectClass objectClass = schemaModel.FindObjectClass(netWeightAssociation.TableName); if (objectClass != null) { foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } } } } else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource)) { TerrainDataSource terrainDataSource = (TerrainDataSource)context.Instance; if (terrainDataSource != null) { if (!string.IsNullOrEmpty(terrainDataSource.FeatureClassName)) { ObjectClass objectClass = schemaModel.FindObjectClass(terrainDataSource.FeatureClassName); if (objectClass != null) { foreach (Field field in objectClass.GetFields()) { list.Add(field.Name); } } } } } // Sort field name list and insert "None" item list.Sort(); list.Insert(0, Resources.TEXT_NONE_BR); // Return sort field name list StandardValuesCollection svc = new StandardValuesCollection(list); return(svc); }
public override void Errors(List <Error> list) { // Get Parent ObjectClass ObjectClass objectClass = (ObjectClass)this.Table; // Get ObjectClass Fields List <Field> fields = objectClass.GetFields(); // Get Schema Model SchemaModel model = (SchemaModel)objectClass.Container; // Add GeometryDef Errors if (this._geometryDef != null) { this._geometryDef.Errors(list, (EsriTable)this.Table); } // GeometryDef only valid for Geometry Fields switch (this._fieldType) { case esriFieldType.esriFieldTypeGeometry: if (this._geometryDef == null) { list.Add(new ErrorTableRow(this, "Geometry Fields Must have a GeometryDef defined.", ErrorType.Error)); } break; case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeGlobalID: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeRaster: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: case esriFieldType.esriFieldTypeXML: if (this._geometryDef != null) { list.Add(new ErrorTableRow(this, "Only Geometry Fields can have a GeometryDef defined.", ErrorType.Error)); } break; } // Raster Fields can have a RasterDef switch (this._fieldType) { case esriFieldType.esriFieldTypeRaster: if (this._rasterDef == null) { string message = string.Format("The raster field [{0}] does not have a RasterDef assigned", this._name); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } break; case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: case esriFieldType.esriFieldTypeGlobalID: case esriFieldType.esriFieldTypeXML: if (this._rasterDef != null) { string message = string.Format("The field [{0}] is invalid. Only raster fields can have a RasterDef", this._name); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } break; } // Field Name Null or Empty if (string.IsNullOrEmpty(this._name)) { list.Add(new ErrorTableRow(this, "Field names cannot be empty", ErrorType.Error)); } // Validate Field Name if (!string.IsNullOrEmpty(this._name)) { // Get Validator Validator validator = WorkspaceValidator.Default.Validator; string message = null; if (!validator.ValidateFieldName(this._name, out message)) { string message2 = string.Format("Field [{0}] {1}", this._name, message); list.Add(new ErrorTableRow(this, message2, ErrorType.Error)); } } // Alias name more than 255 characters long if (!string.IsNullOrEmpty(this._aliasName)) { if (this._aliasName.Length > 255) { string message = string.Format("Field [{0}]. Alias name cannot be longer than 255 characters", this._name); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } } // Find Domain Domain domain = null; if (!string.IsNullOrEmpty(this._domain)) { domain = model.FindDomain(this._domain); if (domain == null) { // Domain does not exit string message = string.Format("The domain [{0}] for field [{1}] does not exist", this._domain, this._name); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } else { // Compare domain and field types if (this._fieldType != domain.FieldType) { string message = string.Format("The field [{0}] and assigned domain [{1}] do not have matching field types", this._name, this._domain); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } // Check Default Value if (!string.IsNullOrEmpty(this._defaultValue)) { string message = null; if (!domain.IsValid(this._defaultValue, out message)) { list.Add(new ErrorTableRow(this, message, ErrorType.Warning)); } } // Check if a domain value is too long for the text field if (this._fieldType == esriFieldType.esriFieldTypeString && domain.FieldType == esriFieldType.esriFieldTypeString && domain.GetType() == typeof(DomainCodedValue)) { DomainCodedValue domain2 = (DomainCodedValue)domain; foreach (DomainCodedValueRow x in domain2.CodedValues) { if (string.IsNullOrEmpty(x.Code)) { continue; } if (x.Code.Length > this._length) { string message = string.Format("The domain [{0}] has a value [{1}] that is too long for the field [{2}]", this._domain, x, this._name); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); } } } } } // Check validity of default value against field type if (!string.IsNullOrEmpty(this._defaultValue)) { string message; if (!GeodatabaseUtility.IsValidateValue(this._fieldType, this._defaultValue, out message)) { string message2 = string.Format("Default value '{0}' {1}", this._defaultValue, message); list.Add(new ErrorTableRow(this, message2, ErrorType.Error)); } } // Check for unsupported field types switch (this._fieldType) { case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeRaster: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: case esriFieldType.esriFieldTypeGlobalID: break; case esriFieldType.esriFieldTypeXML: string message = string.Format("Field type '{0}' is unsupported", this._fieldType.ToString()); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); break; } // Length must be > 0 if (this._length < 0) { list.Add(new ErrorTableRow(this, "Field length cannot be less than zero", ErrorType.Error)); } // ModelName cannot be longer than 255 characters if (!(string.IsNullOrEmpty(this._modelName))) { if (this._modelName.Length > 255) { list.Add(new ErrorTableRow(this, "Model name cannot be greater than 255 characters long", ErrorType.Error)); } } // Precision must be > 0 if (this._precision < 0) { list.Add(new ErrorTableRow(this, "Field precision cannot be less than zero", ErrorType.Error)); } // Scale must be > 0 if (this._scale < 0) { list.Add(new ErrorTableRow(this, "Field scake cannot be less than zero", ErrorType.Error)); } // IsNullable if (this._isNullable) { switch (this._fieldType) { case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeRaster: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: case esriFieldType.esriFieldTypeXML: break; case esriFieldType.esriFieldTypeGlobalID: case esriFieldType.esriFieldTypeOID: string message = string.Format("Field type '{0}' cannot have IsNullable = True", this._fieldType.ToString()); list.Add(new ErrorTableRow(this, message, ErrorType.Error)); break; } } }