private void buttonAttributeType_Click(object sender, EventArgs e)
{
using (FormSelectEntity form = new FormSelectEntity(null, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
{
if (form.ShowDialog(this) == DialogResult.OK && form.SelectedEntity != null)
{
// find existing type or reference type in schema
DocSchema docSchema = (DocSchema)this.m_path[1];
DocDefinition docDef = docSchema.GetDefinition(form.SelectedEntity.Name);
if (docDef == null)
{
// generate link to schema
foreach(DocSection docSection in this.m_project.Sections)
{
foreach (DocSchema docOtherSchema in docSection.Schemas)
{
docDef = docOtherSchema.GetDefinition(form.SelectedEntity.Name);
if (docDef is DocType || docDef is DocEntity)
{
DocSchemaRef docSchemaReference = null;
foreach(DocSchemaRef docSchemaRef in docSchema.SchemaRefs)
{
if (String.Equals(docSchemaRef.Name, docOtherSchema.Name, StringComparison.OrdinalIgnoreCase))
{
docSchemaReference = docSchemaRef;
break;
}
}
if (docSchemaReference == null)
{
docSchemaReference = new DocSchemaRef();
docSchemaReference.Name = docOtherSchema.Name;
docSchema.SchemaRefs.Add(docSchemaReference);
}
docDef = new DocDefinitionRef();
docDef.Name = form.SelectedEntity.Name;
docSchemaReference.Definitions.Add((DocDefinitionRef)docDef);
break;
}
}
if (docDef != null)
break;
}
}
if (this.m_target is DocAttribute)
{
DocAttribute docAttr = (DocAttribute)this.m_target;
if (docAttr.Definition != null && docAttr.Definition.DiagramRectangle != null)
{
// find page target, make page reference
if(docDef is DocDefinitionRef)
{
DocDefinitionRef ddr = (DocDefinitionRef)docDef;
// find existing page target
foreach(DocPageTarget docPageTarget in docSchema.PageTargets)
{
if(docPageTarget.Definition == ddr)
{
// found it -- make page source
DocPageSource docPageSource = new DocPageSource();
docPageTarget.Sources.Add(docPageSource);
docDef = docPageSource;
break;
}
}
}
if (docDef.DiagramRectangle == null)
{
docDef.DiagramRectangle = new DocRectangle();
docDef.DiagramNumber = docAttr.Definition.DiagramNumber;
docDef.DiagramRectangle.X = docAttr.Definition.DiagramRectangle.X;
docDef.DiagramRectangle.Y = docAttr.Definition.DiagramRectangle.Y;
docDef.DiagramRectangle.Width = docAttr.Definition.DiagramRectangle.Width;
docDef.DiagramRectangle.Height = docAttr.Definition.DiagramRectangle.Height;
}
}
docAttr.Definition = docDef;
docAttr.DefinedType = form.SelectedEntity.Name;
this.textBoxAttributeType.Text = docAttr.DefinedType;
}
else if(this.m_target is DocDefined)
{
DocDefined docDefined = (DocDefined)this.m_target;
if (docDefined.Definition.DiagramRectangle != null)
{
docDef.DiagramRectangle = new DocRectangle();
docDef.DiagramNumber = docDefined.Definition.DiagramNumber;
docDef.DiagramRectangle.X = docDefined.Definition.DiagramRectangle.X;
docDef.DiagramRectangle.Y = docDefined.Definition.DiagramRectangle.Y;
docDef.DiagramRectangle.Width = docDefined.Definition.DiagramRectangle.Width;
docDef.DiagramRectangle.Height = docDefined.Definition.DiagramRectangle.Height;
}
docDefined.Definition = docDef;
docDefined.DefinedType = form.SelectedEntity.Name;
this.textBoxAttributeType.Text = docDefined.DefinedType;
}
}
}
}