public override void Errors(List <Error> list) { // Get Model DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default; SchemaModel schemaModel = diagrammerEnvironment.SchemaModel; // Domain Name if (string.IsNullOrEmpty(this._name)) { // Domain name cannot be null or empty list.Add(new ErrorTable(this, "Domain name cannot be empty", ErrorType.Error)); } else { // Get Validator Validator validator = WorkspaceValidator.Default.Validator; // Name must not contain invalid characters. Spaces are valid. string message = null; string name = this._name.Replace(" ", string.Empty); if (validator.ContainsInvalidCharacters(name, out message)) { list.Add(new ErrorTable(this, message, ErrorType.Error)); } // Domain name must be less thab 255 characters. if (this._name.Length > 255) { list.Add(new ErrorTable(this, "Domain name is more than 255 characters long", ErrorType.Error)); } } // Owner if (!string.IsNullOrEmpty(this._owner)) { // Owner must be less than 255 characters. if (this._owner.Length > 255) { list.Add(new ErrorTable(this, "Owner name is more than 255 characters long", ErrorType.Error)); } // Owner cannot contain spaces. if (this._owner.IndexOf(" ") != -1) { list.Add(new ErrorTable(this, "Owner name cannot contain spaces", ErrorType.Error)); } } // Description must be less than 255 characters. if (!string.IsNullOrEmpty(this._description)) { if (this._description.Length > 255) { list.Add(new ErrorTable(this, "Description is more than 255 characters long", ErrorType.Error)); } } // Is this domain unused? if (!string.IsNullOrEmpty(this._name)) { bool used = false; List <ObjectClass> objectClasses = schemaModel.GetObjectClasses(); foreach (ObjectClass objectClass in objectClasses) { List <Field> fields = objectClass.GetFields(); foreach (Field field in fields) { if (field.Domain == this._name) { used = true; break; } } List <Subtype> subtypes = objectClass.GetSubtypes(); foreach (Subtype subtype in subtypes) { List <SubtypeField> subtypeFields = subtype.GetSubtypeFields(); foreach (SubtypeField subtypeField in subtypeFields) { if (subtypeField.DomainName == this._name) { used = true; break; } } if (used) { break; } } } if (!used) { string message = string.Format("Domain [{0}] is not used by any Table or FeatureClass", this._name); list.Add(new ErrorTable(this, message, ErrorType.Warning)); } } }
// // PRIVATE METHODS // public override void OpenModel() { // Exit if invalid if (this.m_domain == null) { return; } // Suspend Model if (ModelSettings.Default.EnableUndoRedo) { this.UndoList.Suspend(); } this.Suspend(); this.SuspendEvents = true; // Get Schema Model SchemaModel model = (SchemaModel)this.m_domain.Container; // Add ObjectClasses that use the Domain List <ObjectClass> objectClasses = model.GetObjectClasses(); foreach (ObjectClass objectClass in objectClasses) { // Add Fields List <Field> fields = objectClass.GetFields(); List <Subtype> subtypes = objectClass.GetSubtypes(); // Check if Domain Used bool domainUsed = false; foreach (Field field in fields) { if (field.Domain == this.m_domain.Name) { domainUsed = true; break; } } if (!domainUsed) { foreach (Subtype subtype in subtypes) { // Loop for each subtype field List <SubtypeField> subtypeFields = subtype.GetSubtypeFields(); foreach (SubtypeField subtypeField in subtypeFields) { if (subtypeField.DomainName == this.m_domain.Name) { domainUsed = true; break; } } } } // Skip this ObjectClass if Domain not used if (!domainUsed) { continue; } // Add ObjectClass Shape shapeObjectClass = null; if (objectClass.GetType() == typeof(ObjectClass)) { shapeObjectClass = new EsriShape <ObjectClass>(objectClass); } else if (objectClass.GetType() == typeof(FeatureClass)) { shapeObjectClass = new EsriShape <FeatureClass>((FeatureClass)objectClass); } this.Shapes.Add(this.Shapes.CreateKey(), shapeObjectClass); // Add Fields foreach (Field field in fields) { if (field.Domain == this.m_domain.Name) { // Create Field EsriShape <Field> shapeField = new EsriShape <Field>(field); this.Shapes.Add(this.Shapes.CreateKey(), shapeField); // Create ObjectClass Link Arrow arrow = new Arrow(); arrow.BorderColor = ModelSettings.Default.DisabledLined; arrow.BorderStyle = DashStyle.Solid; arrow.BorderWidth = 1f; arrow.DrawBackground = false; Line line = new Line(shapeObjectClass, shapeField); line.BorderColor = ModelSettings.Default.DisabledLined; line.BorderStyle = DashStyle.Solid; line.BorderWidth = 1f; line.Start.AllowMove = false; line.End.AllowMove = false; line.End.Marker = arrow; this.Lines.Add(this.Lines.CreateKey(), line); } } // Add Subtypes foreach (Subtype subtype in subtypes) { // EsriShape <Subtype> shapeSubtype = null; List <SubtypeField> subtypeFields = subtype.GetSubtypeFields(); foreach (SubtypeField subtypeField in subtypeFields) { if (subtypeField.DomainName == this.m_domain.Name) { // Add Subtype if (shapeSubtype == null) { // Add Subtype Table shapeSubtype = new EsriShape <Subtype>(subtype); this.Shapes.Add(this.Shapes.CreateKey(), shapeSubtype); // Add ObjectClass to Subtype Line Arrow arrow = new Arrow(); arrow.BorderColor = ModelSettings.Default.DisabledLined; arrow.BorderStyle = DashStyle.Solid; arrow.BorderWidth = 1f; arrow.DrawBackground = false; Line line = new Line(shapeObjectClass, shapeSubtype); line.BorderColor = ModelSettings.Default.DisabledLined; line.BorderStyle = DashStyle.Solid; line.BorderWidth = 1f; line.Start.AllowMove = false; line.End.AllowMove = false; line.End.Marker = arrow; this.Lines.Add(this.Lines.CreateKey(), line); } // Create SubtypeField EsriShape <SubtypeField> shapeSubtypeField = new EsriShape <SubtypeField>(subtypeField); this.Shapes.Add(this.Shapes.CreateKey(), shapeSubtypeField); // Create SubtypeField Link Arrow arrow2 = new Arrow(); arrow2.BorderColor = ModelSettings.Default.DisabledLined; arrow2.BorderStyle = DashStyle.Solid; arrow2.BorderWidth = 1f; arrow2.DrawBackground = false; Line line2 = new Line(shapeSubtype, shapeSubtypeField); line2.BorderColor = ModelSettings.Default.DisabledLined; line2.BorderStyle = DashStyle.Solid; line2.BorderWidth = 1f; line2.Start.AllowMove = false; line2.End.AllowMove = false; line2.End.Marker = arrow2; this.Lines.Add(this.Lines.CreateKey(), line2); break; } } } } // Perform Layout this.ExecuteLayout(typeof(HierarchicalLayout), true); // Resume and Refresh Model this.SuspendEvents = false; this.Resume(); if (ModelSettings.Default.EnableUndoRedo) { this.UndoList.Resume(); } this.Refresh(); }
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context == null) { return(null); } if (context.Instance == null) { return(null); } // RelationshipClass: OriginClassName, DestinationClassName // EdgeConnectivityRule: DefaultJunctionID, FromClassID, ToClassID // JunctionSubtype: ClassID // RelationshipRule: OriginClass, DestinationClass // JunctionConnectivityRule: EdgeClassID, JunctionClassID // TopologyRule: OriginClassId, DestinationClassId // NetWeightAssociation: TableName // TerrainDataSource: FeatureClassName // Get Model DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default; if (diagrammerEnvironment == null) { return(null); } SchemaModel schemaModel = diagrammerEnvironment.SchemaModel; if (schemaModel == null) { return(null); } // Get ObjectClasses List <ObjectClass> objectClasses = schemaModel.GetObjectClasses(); // Create List List <string> list = new List <string>(); if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass)) { switch (context.PropertyDescriptor.Name) { case "OriginClassName": case "DestinationClassName": foreach (ObjectClass objectClass in objectClasses) { if (objectClass.GetType() == typeof(ObjectClass) || objectClass.GetType() == typeof(FeatureClass) || objectClass.GetType() == typeof(RasterCatalog)) { list.Add(objectClass.Name); } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(EdgeConnectivityRule)) { switch (context.PropertyDescriptor.Name) { case "DefaultJunctionID": foreach (ObjectClass objectClass in objectClasses) { FeatureClass featureClass = objectClass as FeatureClass; if (featureClass == null) { continue; } switch (featureClass.FeatureType) // (objectClass.CLSID) { { case esriFeatureType.esriFTSimpleJunction: // EsriRegistry.CLASS_SIMPLEJUNCTION: list.Add(objectClass.Name); break; } } break; case "FromClassID": case "ToClassID": foreach (ObjectClass objectClass in objectClasses) { FeatureClass featureClass = objectClass as FeatureClass; if (featureClass == null) { continue; } switch (featureClass.FeatureType) // (objectClass.CLSID) { { case esriFeatureType.esriFTComplexEdge: // EsriRegistry.CLASS_COMPLEXEDGE: case esriFeatureType.esriFTSimpleEdge: // EsriRegistry.CLASS_SIMPLEEDGE: list.Add(objectClass.Name); break; } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(JunctionSubtype)) { switch (context.PropertyDescriptor.Name) { case "ClassID": foreach (ObjectClass objectClass in objectClasses) { FeatureClass featureClass = objectClass as FeatureClass; if (featureClass == null) { continue; } switch (featureClass.FeatureType) // (objectClass.CLSID) { { case esriFeatureType.esriFTSimpleJunction: // EsriRegistry.CLASS_SIMPLEJUNCTION: list.Add(objectClass.Name); break; } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipRule)) { switch (context.PropertyDescriptor.Name) { case "OriginClass": case "DestinationClass": foreach (ObjectClass objectClass in objectClasses) { if (objectClass.GetType() == typeof(ObjectClass) || objectClass.GetType() == typeof(FeatureClass)) { list.Add(objectClass.Name); } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(JunctionConnectivityRule)) { switch (context.PropertyDescriptor.Name) { case "EdgeClassID": foreach (ObjectClass objectClass in objectClasses) { FeatureClass featureClass = objectClass as FeatureClass; if (featureClass == null) { continue; } switch (featureClass.FeatureType) // (objectClass.CLSID) { { case esriFeatureType.esriFTComplexEdge: // EsriRegistry.CLASS_COMPLEXEDGE: case esriFeatureType.esriFTSimpleEdge: // EsriRegistry.CLASS_SIMPLEEDGE: list.Add(objectClass.Name); break; } } break; case "JunctionClassID": foreach (ObjectClass objectClass in objectClasses) { FeatureClass featureClass = objectClass as FeatureClass; if (featureClass == null) { continue; } switch (featureClass.FeatureType) // (objectClass.CLSID) { { case esriFeatureType.esriFTSimpleJunction: // EsriRegistry.CLASS_SIMPLEJUNCTION: list.Add(objectClass.Name); break; } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule)) { switch (context.PropertyDescriptor.Name) { case "OriginClassId": case "DestinationClassId": foreach (ObjectClass objectClass in objectClasses) { if (objectClass.GetType() == typeof(FeatureClass)) { list.Add(objectClass.Name); } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation)) { switch (context.PropertyDescriptor.Name) { case "TableName": foreach (ObjectClass objectClass in objectClasses) { FeatureClass featureClass = objectClass as FeatureClass; if (featureClass == null) { continue; } switch (featureClass.FeatureType) // (objectClass.CLSID) { { case esriFeatureType.esriFTComplexEdge: // EsriRegistry.CLASS_COMPLEXEDGE: case esriFeatureType.esriFTSimpleEdge: // EsriRegistry.CLASS_SIMPLEEDGE: case esriFeatureType.esriFTSimpleJunction: // EsriRegistry.CLASS_SIMPLEJUNCTION: list.Add(objectClass.Name); break; } } break; } } else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource)) { switch (context.PropertyDescriptor.Name) { case "FeatureClassName": TerrainDataSource terrainDataSource = (TerrainDataSource)context.Instance; SchemaModel model = DiagrammerEnvironment.Default.SchemaModel; if (model == null) { break; } Terrain terrain = model.FindParent(terrainDataSource); FeatureDataset featureDataset = terrain.GetParent() as FeatureDataset; if (featureDataset == null) { break; } foreach (Dataset dataset in featureDataset.GetChildren()) { if (dataset.DatasetType == esriDatasetType.esriDTFeatureClass) { list.Add(dataset.Name); } } break; } } // Sort List list.Sort(); list.Insert(0, Resources.TEXT_NONE_BR); // Return List StandardValuesCollection svc = new StandardValuesCollection(list); return(svc); }