예제 #1
0
        internal void ProcessMouseDoubleClick(MouseEventArgs e)
        {
            if (CategoryRectangle.Contains(e.Location))
            {
                IsExpanded = !IsExpanded;
                Parent.RecalcSizeRequired = true;
            }
            if (IsExpanded)
            {
                for (int i = Properties.Count - 1; i >= 0; i--)
                {
                    RawProperty prop = Properties[i];

                    if (prop.Bounds.Contains(e.Location))
                    {
                        prop.ProcessMouseDoubleClick(e);
                    }
                }
            }
        }
예제 #2
0
        private void Populate()
        {
            if (Table == null || BusyPopulating)
                return;

            try
            {
                BusyPopulating = true;
                Slyce.Common.Utility.SuspendPainting(this);
                bool hasMultiSchemas = Table.Database.GetSchemas().Count() > 1;
                //HideAllFloatingToolstrips();
                Cursor = Cursors.WaitCursor;
                Font boldFont = new Font(Font, FontStyle.Bold);
                Font subTextFont = new Font(Font.FontFamily, Font.Size - 0.6F, FontStyle.Regular);
                MainShape = new RawTable(shapeCanvas1, Table.Name, boldFont, CategoryFont, PropertyFont, Table);

                if (hasMultiSchemas)
                    MainShape.SubText = string.Format("  ({0}) ", Table.Schema);

                MainShape.FontSubText = subTextFont;
                MainShape.Icon = Table.IsView ? ViewImage : TableImage;
                //MainShape.Enter += new EventHandler(centreShape_Enter);
                //MainShape.Leave += new EventHandler(centreShape_Leave);
                MainShape.MouseClick += new MouseEventHandler(centreShape_MouseClick);
                CategoryColumns.Parent = MainShape;
                CategoryColumns.Properties.Clear();

                MainShape.Categories.Add(CategoryColumns);

                if (Table.Columns.Count > 0)
                {
                    foreach (var column in Table.Columns)
                    {
                        RawProperty prop = new RawProperty(column.Name, column);

                        if (column.InPrimaryKey)
                        {
                            prop.ImageColor = Color.OrangeRed;
                            prop.ImageType = RawProperty.ImageTypes.Key;
                        }
                        prop.Click += new MouseEventHandler(Column_Click);
                        prop.DoubleClick += new MouseEventHandler(Column_DoubleClick);
                        CategoryColumns.Properties.Add(prop);
                    }
                }

                List<RawShape> bottomLevelShapes = new List<RawShape>();
                List<RawShape> rightAlignedShapes = new List<RawShape>();
                Font boldUnderlineFont = new Font(Font, FontStyle.Bold | FontStyle.Underline);

                //TheEntity.Discriminator.RootGrouping.
                #region Mapped Entities

                if (ShowMappedEntities)
                {
                    foreach (EntityImpl entity in MappedEntities.OrderBy(e => e.Name))
                    {
                        RawEntity entityShape = new RawEntity(shapeCanvas1, entity.Name, boldFont, entity);

                        CustomLineCap startCap = LineCaps.None;//.SolidArrow;
                        CustomLineCap endCap = LineCaps.None;
                        entityShape.OriginatingLineStyle.LineStyle = DashStyle.Solid;
                        entityShape.Cursor = Cursors.Hand;
                        //entityShape.OriginatingLineStyle.MiddleText = GetDiscriminatorText(entityShape);
                        entityShape.OriginatingLineStyle.StartCap = startCap;
                        entityShape.OriginatingLineStyle.EndCap = endCap;
                        //entityShape.BackColor1 = Color.Blue;
                        //entityShape.BackColor2 = Color.DarkBlue;
                        //entityShape.RoundedCorners = false;
                        entityShape.Tag = entity;
                        entityShape.Icon = EntityImage;
                        string discriminatorText = GetDiscriminatorText(entity);
                        entityShape.OriginatingLineStyle.MiddleText = discriminatorText;

                        if (string.IsNullOrEmpty(discriminatorText))
                        {
                            entityShape.OriginatingLineStyle.MiddleImage = FilterImageDisabled;
                            entityShape.OriginatingLineStyle.MiddleImageFocused = FilterImageDisabled;
                        }
                        else
                        {
                            entityShape.OriginatingLineStyle.MiddleImage = FilterImage;
                            entityShape.OriginatingLineStyle.MiddleImageFocused = FilterImageFocused;
                        }
                        entityShape.OriginatingLineStyle.MouseClick += new MouseEventHandler(OriginatingLineStyle_MouseClick);
                        entityShape.MouseClick += new MouseEventHandler(entityShape_MouseClick);
                        entityShape.OriginatingLineStyle.MiddleImageClick += new MouseEventHandler(MapLine_MiddleImageClick);
                        entityShape.OriginatingLineStyle.ForeColor = Color.White;
                        entityShape.OriginatingLineStyle.DataObject = entity;
                        entityShape.OriginatingLineStyle.ShowMiddleTextOnlyWhenFocused = true;
                        //entityShape.Enter += new EventHandler(entityShape_Enter);
                        //entityShape.Leave += new EventHandler(entityShape_Leave);
                        entityShape.MouseDoubleClick += new MouseEventHandler(entityShape_MouseDoubleClick);

                        //#region Setup discriminator
                        //if (Table.Discriminator != null && Table.Discriminator.RootGrouping != null)
                        //{
                        //    ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Condition firstCondition = Table.Discriminator.RootGrouping.Conditions.ElementAtOrDefault(0);

                        //    if (firstCondition != null)
                        //    {
                        //        IColumn column = firstCondition.Column;
                        //        ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = firstCondition.Operator;
                        //        string exprText = firstCondition.ExpressionValue.Value;
                        //    }
                        //}
                        //#endregion

                        //tableShape.OriginatingLineStyle.MiddleImageMouseOver += new EventHandler(OriginatingLineStyle_MiddleImageMouseOver);
                        rightAlignedShapes.Add(entityShape);
                    }
                    #region Add empty entity
                    Slyce.Common.Controls.Diagramming.Shapes.RawShape emptyEntity = new Slyce.Common.Controls.Diagramming.Shapes.RawShape(shapeCanvas1, "Map entity...", boldUnderlineFont)
                    {
                        BackColor1 = Color.White,
                        BackColor2 = Color.White,
                        BorderColor = Color.Gray,
                        ForeColor = Color.Gray,
                        FocusForeColor = Color.Blue,
                        FocusBackColor1 = Color.WhiteSmoke,
                        FocusBackColor2 = Color.White,
                        FocusBorderColor = Color.DarkGray,
                        Cursor = Cursors.Hand,
                        Tag = null,
                        RoundedCorners = false,
                        OriginatingLineStyle = null //new LinkLine(boldFont, DashStyle.Dot, "", "", "", LineCaps.None, LineCaps.SolidArrow)
                    };
                    emptyEntity.MouseClick += new MouseEventHandler(emptyEntity_MouseClick);
                    //emptyTable.OriginatingLineStyle.MouseClick += new MouseEventHandler(OriginatingLineStyle_MouseClick);
                    rightAlignedShapes.Add(emptyEntity);
                    #endregion
                }
                #endregion

                #region Relationships
                if (ShowRelatedtables)
                {
                    foreach (Relationship relationship in Table.Relationships.OrderBy(r => r.PrimaryTable == Table ? r.ForeignTable.Name : r.PrimaryTable.Name))
                    {
                        RawShape relatedTableShape;
                        CustomLineCap startCap;
                        CustomLineCap endCap;

                        if (relationship.PrimaryTable == Table)
                        {
                            relatedTableShape = new RawTable(shapeCanvas1, relationship.ForeignTable.Name, boldFont, relationship.ForeignTable);

                            if (hasMultiSchemas)
                                relatedTableShape.SubText = string.Format("  ({0}) ", relationship.ForeignTable.Schema);

                            string end1 = relationship.PrimaryKey.IsUnique ? "1" : "m";
                            endCap = relationship.ForeignKey.IsUnique ? LineCaps.One : LineCaps.Many;
                            startCap = relationship.PrimaryKey.IsUnique ? LineCaps.One : LineCaps.Many;
                            relatedTableShape.OriginatingLineStyle.MiddleImageClick += new MouseEventHandler(OriginatingLineStyle_MiddleImageClick2);
                            relatedTableShape.Icon = relationship.ForeignTable.IsView ? ViewImage : TableImage;
                        }
                        else if (relationship.ForeignTable == Table)
                        {
                            relatedTableShape = new RawTable(shapeCanvas1, relationship.PrimaryTable.Name, boldFont, relationship.PrimaryTable);

                            if (hasMultiSchemas)
                                relatedTableShape.SubText = string.Format("  ({0}) ", relationship.PrimaryTable.Schema);

                            string end1 = relationship.ForeignKey.IsUnique ? "1" : "m";
                            endCap = relationship.PrimaryKey.IsUnique ? LineCaps.One : LineCaps.Many;
                            startCap = relationship.ForeignKey.IsUnique ? LineCaps.One : LineCaps.Many;
                            relatedTableShape.OriginatingLineStyle.MiddleImageClick += new MouseEventHandler(OriginatingLineStyle_MiddleImageClick2);
                            relatedTableShape.Icon = relationship.PrimaryTable.IsView ? ViewImage : TableImage;
                        }
                        else
                            throw new Exception("What the...??!");

                        relatedTableShape.FontSubText = subTextFont;

                        if (relationship.IsUserDefined)
                        {
                            relatedTableShape.OriginatingLineStyle.LineStyle = DashStyle.Dash;
                            relatedTableShape.OriginatingLineStyle.LineColor = Color.Yellow;
                        }
                        else
                        {
                            relatedTableShape.OriginatingLineStyle.LineStyle = DashStyle.Solid;
                        }
                        relatedTableShape.Cursor = Cursors.Hand;
                        relatedTableShape.OriginatingLineStyle.StartCap = startCap;
                        relatedTableShape.OriginatingLineStyle.EndCap = endCap;
                        relatedTableShape.OriginatingLineStyle.DataObject = relationship;
                        relatedTableShape.OriginatingLineStyle.ForeColor = Color.White;
                        relatedTableShape.OriginatingLineStyle.MiddleImage = InfoImage;
                        relatedTableShape.MouseClick += new MouseEventHandler(referencedEntityShape_MouseClick);
                        relatedTableShape.MouseDoubleClick += new MouseEventHandler(referencedEntityShape_MouseDoubleClick);
                        bottomLevelShapes.Add(relatedTableShape);
                    }
                    // Add empty relationship
                    RawShape emptyTable = new RawShape(shapeCanvas1, "Add relationship...", boldUnderlineFont)
                    {
                        BackColor1 = Color.White,
                        BackColor2 = Color.White,
                        BorderColor = Color.Gray,
                        ForeColor = Color.Gray,
                        FocusForeColor = Color.Blue,
                        FocusBackColor1 = Color.WhiteSmoke,
                        FocusBackColor2 = Color.White,
                        FocusBorderColor = Color.DarkGray,
                        Cursor = Cursors.Hand,
                        OriginatingLineStyle = null,
                        Tag = null
                    };
                    emptyTable.MouseClick += new MouseEventHandler(emptyTable_MouseClick);
                    bottomLevelShapes.Add(emptyTable);
                }
                #endregion

                shapeCanvas1.SwimLane1 = new ShapeCanvas.SwimLaneStyle(Color.FromArgb(79, 124, 205), Color.Black, Color.White, 0F, "Related Tables", ShapeCanvas.SwimLaneStyle.Styles.Fill);
                shapeCanvas1.SwimLane3 = new ShapeCanvas.SwimLaneStyle(Color.FromArgb(79, 124, 205), Color.Black, Color.White, 180F, "Mapped Entities", ShapeCanvas.SwimLaneStyle.Styles.Fill);
                shapeCanvas1.SwimLane4 = new ShapeCanvas.SwimLaneStyle(Color.FromArgb(79, 124, 205), Color.Black, Color.White, 90F, "Mapped Entities", ShapeCanvas.SwimLaneStyle.Styles.Fill);

                shapeCanvas1.BackColor = this.BackColor;
                //shapeCanvas1.DrawStar(centreShape, outerShapes);
                //shapeCanvas1.DrawThreeLayerHorizontal(centreShape, null, outerShapes, false);
                shapeCanvas1.Height = this.Height;
                //shapeCanvas1.DrawThreeLayerVertical(centreShape, null, bottomLevelShapes, rightAlignedShapes);
                shapeCanvas1.KeepMainShapeCentered = true;
                shapeCanvas1.DrawThreeLayerHorizontal(MainShape, bottomLevelShapes, rightAlignedShapes, KeepMainShapeFull);
                //shapeCanvas1.Focus();
            }
            finally
            {
                this.AutoScrollPosition = ScrollPosition;
                Slyce.Common.Utility.ResumePainting(this);
                Cursor = Cursors.Default;
                BusyPopulating = false;
                this.Focus();
                shapeCanvas1.Focus();
            }
        }
예제 #3
0
        private void Populate()
        {
            if (TheEntity == null || BusyPopulating)
                return;

            BusyPopulating = true;

            try
            {
                Slyce.Common.Utility.SuspendPainting(this);
                HideAllFloatingToolstrips();
                Cursor = Cursors.WaitCursor;
                Font boldFont = new Font(Font, FontStyle.Bold);
                MainShape = new RawEntity(shapeCanvas1, TheEntity.Name, boldFont, TheEntity);
                MainShape.AutoSizeWidth = true;
                MainShape.Icon = EntityImage;
                MainShape.Enter += new EventHandler(centreShape_Enter);
                MainShape.Leave += new EventHandler(centreShape_Leave);
                MainShape.MouseClick += new MouseEventHandler(MainShape_MouseClick);
                //CategoryComponents.Parent = MainShape;
                //CategoryComponents.Properties.Clear();

                CategoryProperties.Parent = MainShape;
                CategoryProperties.IsExpanded = true;
                CategoryProperties.Properties.Clear();

                CategoryNavigation.Parent = MainShape;
                CategoryNavigation.Properties.Clear();

                MainShape.Categories.Add(CategoryProperties);

                if (TheEntity.InheritedProperties.Count() > 0)
                {
                    CategoryInheritedProperties.Parent = MainShape;
                    CategoryInheritedProperties.IsExpanded = true;
                    CategoryInheritedProperties.Properties.Clear();
                    MainShape.Categories.Add(CategoryInheritedProperties);
                }
                //MainShape.Categories.Add(CategoryComponents);
                MainShape.Categories.Add(CategoryNavigation);

                List<IColumn> columnsInComponents = new List<IColumn>();

                if (TheEntity.Components.Count > 0)
                {
                    foreach (var component in TheEntity.Components)
                    {
                        RawProperty cat = new RawProperty(component.Name, component);
                        cat.Enter += new EventHandler(Component_Enter);
                        cat.Leave += new EventHandler(Component_Leave);
                        cat.Click += new MouseEventHandler(Component_Click);
                        CategoryProperties.Properties.Add(cat);

                        foreach (var componentProperty in component.Properties)
                        {
                            columnsInComponents.Add(componentProperty.MappedColumn());

                            RawProperty prop = new RawProperty(componentProperty.PropertyName, componentProperty);
                            //prop.Click += new MouseEventHandler(Component_Click);
                            //prop.DoubleClick += new MouseEventHandler(Component_DoubleClick);
                            //prop.Enter += new EventHandler(Component_Enter);
                            //prop.Leave += new EventHandler(Component_Leave);
                            cat.SubProperties.Add(prop);
                        }
                    }
                }
                int propCount = TheEntity.Properties.Count();

                if (TheEntity.Properties.Count() > 0)
                {
                    //foreach (var property in TheEntity.Properties.Except(TheEntity.ForeignKeyPropertiesToExclude))
                    foreach (var property in TheEntity.Properties.Except(TheEntity.ForeignKeyPropertiesToExclude).Except(TheEntity.InheritedProperties))
                    {
                        if (!columnsInComponents.Contains(property.MappedColumn()))
                        {
                            RawProperty prop = new RawProperty(property.Name, property);
                            prop.BackColorFocused = Color.FromArgb(245, 208, 18);
                            prop.AllowSelection = true;
                            prop.Click += new MouseEventHandler(Property_Click);
                            CategoryProperties.Properties.Add(prop);
                        }
                    }
                    foreach (var property in TheEntity.InheritedProperties)
                    {
                        if (!columnsInComponents.Contains(property.MappedColumn()))
                        {
                            RawProperty prop = new RawProperty(property.Name, property);
                            prop.BackColorFocused = Color.FromArgb(245, 208, 18);
                            prop.AllowSelection = true;
                            prop.Click += new MouseEventHandler(Property_Click);
                            CategoryInheritedProperties.Properties.Add(prop);
                        }
                    }
                }
                Font boldUnderlineFont = new Font(Font, FontStyle.Bold | FontStyle.Underline);
                Font subTextFont = new Font(Font.FontFamily, Font.Size - 0.6F, FontStyle.Regular);
                List<RawShape> bottomLevelShapes = new List<RawShape>();
                List<RawShape> rightAlignedShapes = new List<RawShape>();

                #region MappedTables

                if (ShowMappedTables)
                {
                    bool hasMultiSchemas = false;

                    if (TheEntity.EntitySet.MappingSet.Database != null)
                        hasMultiSchemas = TheEntity.EntitySet.MappingSet.Database.GetSchemas().Count() > 1;

                    foreach (ITable table in MappedTables.OrderBy(t => t.Name))
                    {
                        RawTable tableShape = new RawTable(shapeCanvas1, table.Name, boldFont, table);

                        if (hasMultiSchemas)
                        {
                            tableShape.SubText = string.Format("  ({0}) ", table.Schema);
                            tableShape.FontSubText = subTextFont;
                        }
                        CustomLineCap startCap = LineCaps.None;
                        CustomLineCap endCap = LineCaps.None;
                        tableShape.OriginatingLineStyle.LineStyle = DashStyle.Dot;
                        //tableShape.OriginatingLineStyle.StartText = "";
                        //tableShape.OriginatingLineStyle.EndText = "";
                        tableShape.OriginatingLineStyle.MiddleText = GetDiscriminatorText(table);// "LastName = 'Anderson'";
                        tableShape.OriginatingLineStyle.StartCap = startCap;
                        tableShape.OriginatingLineStyle.EndCap = endCap;
                        //tableShape.BackColor1 = Color.Blue;
                        //tableShape.BackColor2 = Color.DarkBlue;
                        tableShape.RoundedCorners = false;
                        tableShape.Cursor = Cursors.Hand;
                        tableShape.Tag = table;
                        tableShape.Icon = table.IsView ? ViewImage : TableImage;

                        if (string.IsNullOrEmpty(tableShape.OriginatingLineStyle.MiddleText))
                            tableShape.OriginatingLineStyle.MiddleImage = FilterImageDisabled;
                        else
                            tableShape.OriginatingLineStyle.MiddleImage = FilterImage;

                        tableShape.OriginatingLineStyle.MiddleImageFocused = EditImage;
                        tableShape.OriginatingLineStyle.MouseClick += new MouseEventHandler(OriginatingLineStyle_MouseClick);
                        tableShape.MouseClick += new MouseEventHandler(tableShape_MouseClick);
                        tableShape.OriginatingLineStyle.MiddleImageClick += new MouseEventHandler(OriginatingLineStyle_MiddleImageClick);
                        tableShape.OriginatingLineStyle.DataObject = table;
                        tableShape.OriginatingLineStyle.ForeColor = Color.White;
                        tableShape.MouseDoubleClick += new MouseEventHandler(tableShape_MouseDoubleClick);

                        #region Setup discriminator
                        //throw new NotImplementedException("TODO: ddiscriminator stuff");
                        //if (TheEntity.Discriminator != null && TheEntity.Discriminator.RootGrouping != null)
                        //{
                        //    ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Condition firstCondition = TheEntity.Discriminator.RootGrouping.Conditions.ElementAtOrDefault(0);

                        //    if (firstCondition != null)
                        //    {
                        //        IColumn column = firstCondition.Column;
                        //        ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = firstCondition.Operator;
                        //        string exprText = firstCondition.ExpressionValue.Value;
                        //    }
                        //}
                        #endregion

                        //tableShape.OriginatingLineStyle.MiddleImageMouseOver += new EventHandler(OriginatingLineStyle_MiddleImageMouseOver);
                        rightAlignedShapes.Add(tableShape);
                    }
                    #region Add empty table
                    Slyce.Common.Controls.Diagramming.Shapes.RawShape emptyTable = new Slyce.Common.Controls.Diagramming.Shapes.RawShape(shapeCanvas1, "Add table...", boldUnderlineFont)
                    {
                        BackColor1 = Color.White,
                        BackColor2 = Color.White,
                        BorderColor = Color.Gray,
                        ForeColor = Color.Gray,
                        FocusForeColor = Color.Blue,
                        FocusBackColor1 = Color.WhiteSmoke,
                        FocusBackColor2 = Color.White,
                        FocusBorderColor = Color.DarkGray,
                        Cursor = Cursors.Hand,
                        Tag = null,
                        RoundedCorners = false,
                        OriginatingLineStyle = null //new LinkLine(boldFont, DashStyle.Dot, "", "", "", LineCaps.None, LineCaps.SolidArrow)
                    };
                    emptyTable.MouseClick += new MouseEventHandler(emptyTable_MouseClick);
                    emptyTable.Cursor = Cursors.Hand;
                    //emptyTable.OriginatingLineStyle.MouseClick += new MouseEventHandler(OriginatingLineStyle_MouseClick);
                    rightAlignedShapes.Add(emptyTable);
                    #endregion
                }
                #endregion

                #region References
                if (ShowReferencedEntities)
                {
                    foreach (ReferenceImpl reference in TheEntity.References.OrderBy(r => r.Entity1 == TheEntity ? r.Entity2.Name : r.Entity1.Name))
                    {
                        RawEntity referencedEntityShape;
                        CustomLineCap startCap;
                        CustomLineCap endCap;

                        if (reference.Entity1 == TheEntity)
                        {
                            referencedEntityShape = new RawEntity(shapeCanvas1, reference.Entity2.Name, boldFont, reference.Entity2);
                            referencedEntityShape.OriginatingLineStyle.DataObject = reference;

                            if (ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality2))
                                startCap = LineCaps.One;
                            else if (ArchAngel.Interfaces.Cardinality.Many.Equals(reference.Cardinality2))
                                startCap = LineCaps.Many;
                            else if (ArchAngel.Interfaces.Cardinality.Zero.Equals(reference.Cardinality2))
                                startCap = LineCaps.Zero;
                            else
                                throw new NotImplementedException("Unexpected cardinality.");

                            if (ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality1))
                                endCap = LineCaps.One;
                            else if (ArchAngel.Interfaces.Cardinality.Many.Equals(reference.Cardinality1))
                                endCap = LineCaps.Many;
                            else if (ArchAngel.Interfaces.Cardinality.Zero.Equals(reference.Cardinality1))
                                endCap = LineCaps.Zero;
                            else
                                throw new NotImplementedException("Unexpected cardinality.");

                            referencedEntityShape.OriginatingLineStyle.StartTextDataMember = "End1Name";
                            referencedEntityShape.OriginatingLineStyle.EndTextDataMember = "End2Name";
                            referencedEntityShape.OriginatingLineStyle.StartImageClick += new LinkLine.MouseEndDelegate(OriginatingLineStyle_StartImageClick);
                            referencedEntityShape.OriginatingLineStyle.EndImageClick += new LinkLine.MouseEndDelegate(OriginatingLineStyle_EndImageClick);
                            referencedEntityShape.MouseClick += new MouseEventHandler(referencedEntityShape_MouseClick);
                            //referencedEntityShape.OriginatingLineStyle.MouseOverEnd1 += new LinkLine.MouseOverEndDelegate(OriginatingLineStyle_MouseOverEnd2);
                            //referencedEntityShape.OriginatingLineStyle.MouseOverEnd2 += new LinkLine.MouseOverEndDelegate(OriginatingLineStyle_MouseOverEnd1);
                            //reference..GetMappingSet().ReferenceMappings[0].

                            //RawCategory categoryNav = new RawCategory("Navigation", CategoryFont, referencedEntityShape);
                            //RawProperty navProp = new RawProperty(referencedEntityShape.OriginatingLineStyle.EndText, reference);
                            //navProp.Click += new MouseEventHandler(NavigationProperty_Click);
                            //categoryNav.Properties.Add(navProp);
                            //referencedEntityShape.Categories.Add(categoryNav);

                            RawProperty prop = new RawProperty(referencedEntityShape.OriginatingLineStyle.StartText, reference);
                            prop.DoubleClick += new MouseEventHandler(prop1_DoubleClick);
                            CategoryNavigation.Properties.Add(prop);
                        }
                        else if (reference.Entity2 == TheEntity)
                        {
                            referencedEntityShape = new RawEntity(shapeCanvas1, reference.Entity1.Name, boldFont, reference.Entity1);
                            referencedEntityShape.OriginatingLineStyle.DataObject = reference;

                            if (ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality1))
                                startCap = LineCaps.One;
                            else if (ArchAngel.Interfaces.Cardinality.Many.Equals(reference.Cardinality1))
                                startCap = LineCaps.Many;
                            else if (ArchAngel.Interfaces.Cardinality.Zero.Equals(reference.Cardinality1))
                                startCap = LineCaps.Zero;
                            else
                                throw new NotImplementedException("Unexpected cardinality.");

                            if (ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality2))
                                endCap = LineCaps.One;
                            else if (ArchAngel.Interfaces.Cardinality.Many.Equals(reference.Cardinality2))
                                endCap = LineCaps.Many;
                            else if (ArchAngel.Interfaces.Cardinality.Zero.Equals(reference.Cardinality2))
                                endCap = LineCaps.Zero;
                            else
                                throw new NotImplementedException("Unexpected cardinality.");

                            referencedEntityShape.OriginatingLineStyle.StartTextDataMember = "End2Name";
                            referencedEntityShape.OriginatingLineStyle.EndTextDataMember = "End1Name";
                            referencedEntityShape.OriginatingLineStyle.StartImageClick += new LinkLine.MouseEndDelegate(OriginatingLineStyle_EndImageClick);
                            referencedEntityShape.OriginatingLineStyle.EndImageClick += new LinkLine.MouseEndDelegate(OriginatingLineStyle_StartImageClick);
                            referencedEntityShape.MouseClick += new MouseEventHandler(referencedEntityShape_MouseClick);
                            //referencedEntityShape.OriginatingLineStyle.MouseOverEnd1 += new LinkLine.MouseOverEndDelegate(OriginatingLineStyle_MouseOverEnd1);
                            //referencedEntityShape.OriginatingLineStyle.MouseOverEnd2 += new LinkLine.MouseOverEndDelegate(OriginatingLineStyle_MouseOverEnd2);

                            //RawCategory categoryNav = new RawCategory("Navigation", CategoryFont, referencedEntityShape);
                            //RawProperty navProp = new RawProperty(referencedEntityShape.OriginatingLineStyle.EndText, reference);
                            //navProp.Click += new MouseEventHandler(NavigationProperty_Click);
                            //categoryNav.Properties.Add(navProp);
                            //referencedEntityShape.Categories.Add(categoryNav);

                            RawProperty prop = new RawProperty(referencedEntityShape.OriginatingLineStyle.StartText, reference);
                            prop.DoubleClick += new MouseEventHandler(prop2_DoubleClick);
                            CategoryNavigation.Properties.Add(prop);
                        }
                        else
                            throw new Exception("What the...??!");

                        referencedEntityShape.Cursor = Cursors.Hand;
                        referencedEntityShape.Icon = EntityImage;
                        referencedEntityShape.OriginatingLineStyle.LineStyle = DashStyle.Solid;
                        referencedEntityShape.OriginatingLineStyle.StartCap = startCap;
                        referencedEntityShape.OriginatingLineStyle.EndCap = endCap;

                        referencedEntityShape.OriginatingLineStyle.ForeColor = Color.White;
                        referencedEntityShape.OriginatingLineStyle.DefaultEndText = "not set";
                        referencedEntityShape.OriginatingLineStyle.StartImage = EditImage;
                        referencedEntityShape.OriginatingLineStyle.EndImage = EditImage;
                        referencedEntityShape.MouseDoubleClick += new MouseEventHandler(referencedEntityShape_MouseDoubleClick);
                        referencedEntityShape.Enter += new EventHandler(referencedEntityShape_Enter);
                        referencedEntityShape.Leave += new EventHandler(referencedEntityShape_Leave);
                        //referencedEntityShape.AutoSizeWidth = true;
                        bottomLevelShapes.Add(referencedEntityShape);
                    }
                    // Add empty reference
                    RawShape emptyReference = new RawShape(shapeCanvas1, "Add entity...", boldUnderlineFont)
                    {
                        BackColor1 = Color.White,
                        BackColor2 = Color.White,
                        BorderColor = Color.Gray,
                        ForeColor = Color.Gray,
                        FocusForeColor = Color.Blue,
                        FocusBackColor1 = Color.WhiteSmoke,
                        FocusBackColor2 = Color.White,
                        FocusBorderColor = Color.DarkGray,
                        Cursor = Cursors.Hand,
                        OriginatingLineStyle = null,// new LinkLine(boldFont, DashStyle.Dot, "", "", "", LineCaps.None, LineCaps.SolidArrow),
                        Tag = null
                    };
                    //emptyReference.OriginatingLineStyle.ForeColor = Color.White;
                    emptyReference.MouseClick += new MouseEventHandler(emptyReference_MouseClick);
                    emptyReference.Cursor = Cursors.Hand;
                    bottomLevelShapes.Add(emptyReference);
                }
                #endregion

                //shapeCanvas1.BackColor = this.BackColor;
                ////shapeCanvas1.DrawStar(centreShape, outerShapes);
                ////shapeCanvas1.DrawThreeLayerHorizontal(centreShape, null, outerShapes, false);
                //shapeCanvas1.Height = this.Height;
                //shapeCanvas1.DrawThreeLayerVertical(centreShape, null, outerShapes);
                //Cursor = Cursors.Default;

                shapeCanvas1.SwimLane1 = new ShapeCanvas.SwimLaneStyle(Color.FromArgb(79, 124, 205), Color.Black, Color.White, 180F, "Referenced Entities", ShapeCanvas.SwimLaneStyle.Styles.Fill);
                shapeCanvas1.SwimLane3 = new ShapeCanvas.SwimLaneStyle(Color.FromArgb(79, 124, 205), Color.Black, Color.White, 0F, "Mapped Tables", ShapeCanvas.SwimLaneStyle.Styles.Fill);

                shapeCanvas1.BackColor = this.BackColor;
                //shapeCanvas1.DrawStar(centreShape, outerShapes);
                //shapeCanvas1.DrawThreeLayerHorizontal(centreShape, null, outerShapes, false);
                shapeCanvas1.Height = this.Height;
                //shapeCanvas1.DrawThreeLayerVertical(centreShape, null, bottomLevelShapes, rightAlignedShapes);
                shapeCanvas1.KeepMainShapeCentered = true;
                MainShape.RecalcSizeRequired = true;
                shapeCanvas1.DrawThreeLayerHorizontal(MainShape, bottomLevelShapes, rightAlignedShapes, KeepMainShapeFull);
                this.Focus();
                shapeCanvas1.Focus();
            }
            finally
            {
                this.AutoScrollPosition = ScrollPosition;
                Slyce.Common.Utility.ResumePainting(this);
                Cursor = Cursors.Default;
                BusyPopulating = false;
            }
        }
        private void Draw()
        {
            if (ComponentSpecification == null)
                return;

            Cursor = Cursors.WaitCursor;
            Font boldFont = new Font(Font, FontStyle.Bold);
            MainShape = new RawComponent(shapeCanvas1, ComponentSpecification.Name, boldFont, ComponentSpecification);
            MainShape.Categories.Clear();

            RawCategory cat = new RawCategory("Properties", Font, MainShape);
            MainShape.Categories.Add(cat);

            foreach (var x in ComponentSpecification.Properties)
            {
                //RawProperty prop = new RawProperty(string.Format("{0} [{1}]", x.Name, x.Type), x);
                RawProperty prop = new RawProperty(x.Name, x);
                cat.Properties.Add(prop);
            }

            //centreShape.Icon = EntityImage;
            //centreShape.Enter += new EventHandler(centreShape_Enter);
            //centreShape.Leave += new EventHandler(centreShape_Leave);
            Font boldUnderlineFont = new Font(Font, FontStyle.Bold | FontStyle.Underline);
            List<RawShape> topLevelShapes = new List<RawShape>();
            List<RawShape> rightAlignedShapes = new List<RawShape>();

            #region References

            foreach (ComponentImpl component in ComponentSpecification.ImplementedComponents)
            {
                RawEntity referencedEntityShape;
                CustomLineCap startCap;
                CustomLineCap endCap;

                referencedEntityShape = new RawEntity(shapeCanvas1, component.ParentEntity.Name, boldFont, component.ParentEntity);
                //string end1 = ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality2) ? "1" : "m";
                //startCap = ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality2) ? LineCaps.One : LineCaps.Many;
                //endCap = ArchAngel.Interfaces.Cardinality.One.Equals(reference.Cardinality1) ? LineCaps.One : LineCaps.Many;
                referencedEntityShape.OriginatingLineStyle.EndTextDataMember = "Name";
                //referencedEntityShape.OriginatingLineStyle.EndTextDataMember = "End2Name";
                //referencedEntityShape.OriginatingLineStyle.StartImageClick += new LinkLine.MouseEndDelegate(OriginatingLineStyle_StartImageClick);
                //referencedEntityShape.OriginatingLineStyle.EndImageClick += new LinkLine.MouseEndDelegate(OriginatingLineStyle_EndImageClick);
                //referencedEntityShape.OriginatingLineStyle.MouseOverEnd1 += new LinkLine.MouseOverEndDelegate(OriginatingLineStyle_MouseOverEnd2);
                //referencedEntityShape.OriginatingLineStyle.MouseOverEnd2 += new LinkLine.MouseOverEndDelegate(OriginatingLineStyle_MouseOverEnd1);

                referencedEntityShape.Icon = EntityImage;
                referencedEntityShape.OriginatingLineStyle.LineStyle = DashStyle.Solid;
                //referencedEntityShape.OriginatingLineStyle.StartCap = startCap;
                //referencedEntityShape.OriginatingLineStyle.EndCap = endCap;
                referencedEntityShape.OriginatingLineStyle.DataObject = component;
                referencedEntityShape.OriginatingLineStyle.ForeColor = Color.White;
                referencedEntityShape.OriginatingLineStyle.DefaultEndText = "";
                //referencedEntityShape.OriginatingLineStyle.StartImage = EditImage;
                //referencedEntityShape.OriginatingLineStyle.EndImage = EditImage;
                referencedEntityShape.OriginatingLineStyle.MiddleImage = InfoImage;
                referencedEntityShape.OriginatingLineStyle.MiddleImageClick += new MouseEventHandler(OriginatingLineStyle_MiddleImageClick);
                referencedEntityShape.MouseDoubleClick += new MouseEventHandler(referencedEntityShape_MouseDoubleClick);
                referencedEntityShape.MouseClick += new MouseEventHandler(referencedEntityShape_MouseClick);
                referencedEntityShape.Cursor = Cursors.Hand;
                topLevelShapes.Add(referencedEntityShape);
            }
            // Add empty reference
            RawShape emptyReference = new RawShape(shapeCanvas1, "Add entity...", boldUnderlineFont)
            {
                BackColor1 = Color.White,
                BackColor2 = Color.White,
                BorderColor = Color.Gray,
                ForeColor = Color.Gray,
                FocusForeColor = Color.Blue,
                FocusBackColor1 = Color.WhiteSmoke,
                FocusBackColor2 = Color.White,
                FocusBorderColor = Color.DarkGray,
                Cursor = Cursors.Hand,
                OriginatingLineStyle = null,// new LinkLine(boldFont, DashStyle.Dot, "", "", "", LineCaps.None, LineCaps.SolidArrow),
                Tag = null
            };
            //emptyReference.OriginatingLineStyle.ForeColor = Color.White;
            emptyReference.MouseClick += new MouseEventHandler(emptyReference_MouseClick);
            topLevelShapes.Add(emptyReference);
            #endregion

            shapeCanvas1.SwimLane1 = new ShapeCanvas.SwimLaneStyle(Color.Gray, Color.Black, Color.White, 180F, "Used By (Entities)", ShapeCanvas.SwimLaneStyle.Styles.Fill);
            //shapeCanvas1.SwimLane3 = new ShapeCanvas.SwimLaneStyle(Color.FromArgb(79, 124, 205), Color.Black, Color.White, 0F, "Mapped Tables", ShapeCanvas.SwimLaneStyle.Styles.Fill);

            shapeCanvas1.BackColor = this.BackColor;
            shapeCanvas1.Height = this.Height;
            shapeCanvas1.KeepMainShapeCentered = true;
            shapeCanvas1.DrawThreeLayerHorizontal(MainShape, topLevelShapes, rightAlignedShapes, KeepMainShapeFull);
            Cursor = Cursors.Default;
        }