Ejemplo n.º 1
0
        /// <summary>
        /// Gets the drawing information for a particular element in the compartment.
        /// </summary>
        /// <param name="listField">The <see cref="ShapeField"/> of this <see cref="AttributeElementListCompartment"/> which
        /// paints the items in this compartment.</param>
        /// <param name="row">The index of the array of items whose item drawing information is of interest.</param>
        /// <param name="itemDrawInfo">A previously initialized <see cref="ItemDrawInfo"/> object whose properties will be modified.</param>
        public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
        {
            base.GetItemDrawInfo(listField, row, itemDrawInfo);
            Barker.Attribute currentAttribute = this.Items[row] as Barker.Attribute;
            Debug.Assert(currentAttribute != null, "An item in the AttributeElementListCompartment is not an attribute.");

            if (currentAttribute.IsMandatory)
            {
                itemDrawInfo.AlternateFont = true;
            }

            StringBuilder attributeText = new StringBuilder();

            if (currentAttribute.IsPrimaryIdComponent)
            {
                attributeText.Append(PrimaryIdentifierString);
            }
            else
            {
                attributeText.Append(BlankString);
            }
            attributeText.Append(BlankString);

            if (currentAttribute.IsMandatory)
            {
                attributeText.Append(MandatoryString);
            }
            else
            {
                attributeText.Append(OptionalString);
            }
            attributeText.Append(BlankString);
            attributeText.Append(currentAttribute.Name);
            itemDrawInfo.Text = attributeText.ToString();
        }
Ejemplo n.º 2
0
        private SizeD CalculateSize()
        {
            ListField         listField   = ListField;
            int               count       = this.GetItemCount(listField);
            double            height      = HeaderBounds.Height + listField.GetItemHeight(this) * count;
            double            width       = 0;
            BarkerEntityShape entityShape = ParentShape as BarkerEntityShape;

            string   entityName     = entityShape.AccessibleName;
            StyleSet styleSet       = StyleSet;
            Font     defaultFont    = styleSet.GetFont(listField.NormalFontId);
            Font     alternateFont  = styleSet.GetFont(listField.AlternateFontId);
            Font     entityNameFont = entityShape.StyleSet.GetFont(new StyleSetResourceId(string.Empty, "ShapeTextBold10"));

            using (Graphics g = Graphics.FromHwnd(GetDesktopWindow()))
            {
                double entityNameWidth = (double)g.MeasureString(entityName, entityNameFont, int.MaxValue, DefaultStringFormat).Width + BarkerEntityExtraWidth;

                // Changes the width if the current width is less than the width of the table name.
                if (width < entityNameWidth)
                {
                    width = entityNameWidth;
                }
                // Iterates through the column list to check the widths of the column names.
                for (int i = 0; i < count; ++i)
                {
                    ItemDrawInfo itemDrawInfo = new ItemDrawInfo();
                    GetItemDrawInfo(listField, i, itemDrawInfo);
                    bool   isMandatory = (this.Items[i] as Barker.Attribute).IsMandatory;
                    string text        = itemDrawInfo.Text;

                    // Gets the size of the column name in the context of the compartment
                    double stringWidth = (double)g.MeasureString(text, isMandatory ? alternateFont : defaultFont, int.MaxValue, DefaultStringFormat).Width + AttributeExtraWidth;

                    // Changes the width if the current width is less than the width of the column name.
                    if (width < stringWidth)
                    {
                        width = stringWidth;
                    }
                }
            }
            return(new SizeD(width, height));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Gets drawing information for a single list item in the list field.
        /// </summary>
        /// <param name="listField">The child list field requesting the drawing information.</param>
        /// <param name="row">The zero-based row number of the list item to draw.</param>
        /// <param name="itemDrawInfo">An ItemDrawInfo that receives the drawing information.</param>
        public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
        {
            base.GetItemDrawInfo(listField, row, itemDrawInfo);
            Debug.Assert(ParentShape != null, "ElementListCompartment should be contained in another shape.");
            if (ParentShape != null)
            {
                var ets = ParentShape as EntityTypeShape;
                Debug.Assert(
                    ets != null, "Expected ElementListCompartment's parent type:EntityTypeShape , Actual:" + ParentShape.GetType().Name);

                if (ets != null &&
                    ets.Diagram != null)
                {
                    //  if the compartment list item is in the EmphasizedShapes list, then set the flag so that the item will be drawn in alternate font.
                    // (The list item's font will be bolded and underlined).
                    if (ets.Diagram.EmphasizedShapes.Contains(new DiagramItem(this, ListField, new ListItemSubField(row))))
                    {
                        itemDrawInfo.AlternateFont = true;
                    }
                }
            }
        }
        /// <summary>
        ///     Gets drawing information for a single list item in the list field.
        /// </summary>
        /// <param name="listField">The child list field requesting the drawing information.</param>
        /// <param name="row">The zero-based row number of the list item to draw.</param>
        /// <param name="itemDrawInfo">An ItemDrawInfo that receives the drawing information.</param>
        public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
        {
            base.GetItemDrawInfo(listField, row, itemDrawInfo);
            Debug.Assert(ParentShape != null, "ElementListCompartment should be contained in another shape.");
            if (ParentShape != null)
            {
                var ets = ParentShape as EntityTypeShape;
                Debug.Assert(
                    ets != null, "Expected ElementListCompartment's parent type:EntityTypeShape , Actual:" + ParentShape.GetType().Name);

                if (ets != null
                    && ets.Diagram != null)
                {
                    //  if the compartment list item is in the EmphasizedShapes list, then set the flag so that the item will be drawn in alternate font.
                    // (The list item's font will be bolded and underlined).
                    if (ets.Diagram.EmphasizedShapes.Contains(new DiagramItem(this, ListField, new ListItemSubField(row))))
                    {
                        itemDrawInfo.AlternateFont = true;
                    }
                }
            }
        }
        /// <summary>
        /// Gets the drawing information for a particular element in the compartment.
        /// </summary>
        /// <param name="listField">The <see cref="ShapeField"/> of this <see cref="ColumnElementListCompartment"/> which
        /// paints the items in this compartment.</param>
        /// <param name="row">The index of the array of items whose item drawing information is of interest.</param>
        /// <param name="itemDrawInfo">A previously initialized <see cref="ItemDrawInfo"/> object whose properties will be modified.</param>
        public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
        {
            base.GetItemDrawInfo(listField, row, itemDrawInfo);
            Column currentColumn = this.Items[row] as Column;

            Debug.Assert(currentColumn != null, "An item in the ColumnElementListCompartment is not a column.");

            if (!currentColumn.IsNullable)
            {
                itemDrawInfo.AlternateFont = true;
            }

            StringBuilder columnText     = new StringBuilder();
            bool          seenConstraint = false;
            LinkedElementCollection <UniquenessConstraint> tableUniquenessConstraints = null;
            Table currentTable = null;

            foreach (UniquenessConstraint constraint in UniquenessConstraintIncludesColumn.GetUniquenessConstraints(currentColumn))
            {
                if (seenConstraint)
                {
                    columnText.Append(CommaString);
                }
                if (constraint.IsPrimary)
                {
                    columnText.Append(PrimaryKeyString);
                }
                else
                {
                    if (tableUniquenessConstraints == null)
                    {
                        currentTable = currentColumn.Table;
                        tableUniquenessConstraints = currentTable.UniquenessConstraintCollection;
                    }
                    int constraintNumber = 0;
                    foreach (UniquenessConstraint tableConstraint in tableUniquenessConstraints)
                    {
                        if (!tableConstraint.IsPrimary)
                        {
                            ++constraintNumber;
                            if (tableConstraint == constraint)
                            {
                                break;
                            }
                        }
                    }
                    columnText.AppendFormat(AlternateKeyString, constraintNumber);
                }
                seenConstraint = true;
            }
            LinkedElementCollection <ReferenceConstraint> tableReferenceConstraints = null;

            foreach (ColumnReference columnReference in ColumnReference.GetLinksToTargetColumnCollection(currentColumn))
            {
                if (seenConstraint)
                {
                    columnText.Append(CommaString);
                }
                if (tableReferenceConstraints == null)
                {
                    if (currentTable == null)
                    {
                        currentTable = currentColumn.Table;
                    }
                    tableReferenceConstraints = currentTable.ReferenceConstraintCollection;
                }
                columnText.AppendFormat(ForeignKeyString, tableReferenceConstraints.IndexOf(columnReference.ReferenceConstraint) + 1);
                seenConstraint = true;
            }
            if (seenConstraint)
            {
                columnText.Append(ColonString);
            }
            columnText.Append(currentColumn.Name);
            if (((RelationalDiagram)this.Diagram).DisplayDataTypes)
            {
                columnText.Append(ColonString);
                columnText.Append(GetDataType(currentColumn.AssociatedValueType));
            }
            itemDrawInfo.Text = columnText.ToString();
        }
		private SizeD CalculateSize()
		{
			ListField listField = ListField;
			int count = this.GetItemCount(listField);
			double height = HeaderBounds.Height + listField.GetItemHeight(this) * count;
			double width = 0;
			BarkerEntityShape entityShape = ParentShape as BarkerEntityShape;

			string entityName = entityShape.AccessibleName;
			StyleSet styleSet = StyleSet;
			Font defaultFont = styleSet.GetFont(listField.NormalFontId);
			Font alternateFont = styleSet.GetFont(listField.AlternateFontId);
			Font entityNameFont = entityShape.StyleSet.GetFont(new StyleSetResourceId(string.Empty, "ShapeTextBold10"));

			using (Graphics g = Graphics.FromHwnd(GetDesktopWindow()))
			{
				double entityNameWidth = (double)g.MeasureString(entityName, entityNameFont, int.MaxValue, DefaultStringFormat).Width + BarkerEntityExtraWidth;

				// Changes the width if the current width is less than the width of the table name.
				if (width < entityNameWidth)
				{
					width = entityNameWidth;
				}
				// Iterates through the column list to check the widths of the column names.
				for (int i = 0; i < count; ++i)
				{
					ItemDrawInfo itemDrawInfo = new ItemDrawInfo();
					GetItemDrawInfo(listField, i, itemDrawInfo);
					bool isMandatory = (this.Items[i] as Barker.Attribute).IsMandatory;
					string text = itemDrawInfo.Text;

					// Gets the size of the column name in the context of the compartment
					double stringWidth = (double)g.MeasureString(text, isMandatory ? alternateFont : defaultFont, int.MaxValue, DefaultStringFormat).Width + AttributeExtraWidth;

					// Changes the width if the current width is less than the width of the column name.
					if (width < stringWidth)
					{
						width = stringWidth;
					}
				}
			}
			return new SizeD(width, height);
		}
		/// <summary>
		/// Gets the drawing information for a particular element in the compartment.
		/// </summary>
		/// <param name="listField">The <see cref="ShapeField"/> of this <see cref="AttributeElementListCompartment"/> which
		/// paints the items in this compartment.</param>
		/// <param name="row">The index of the array of items whose item drawing information is of interest.</param>
		/// <param name="itemDrawInfo">A previously initialized <see cref="ItemDrawInfo"/> object whose properties will be modified.</param>
		public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
		{
			base.GetItemDrawInfo(listField, row, itemDrawInfo);
			Barker.Attribute currentAttribute = this.Items[row] as Barker.Attribute;
			Debug.Assert(currentAttribute != null, "An item in the AttributeElementListCompartment is not an attribute.");

			if (currentAttribute.IsMandatory)
			{
				itemDrawInfo.AlternateFont = true;
			}

			StringBuilder attributeText = new StringBuilder();

			if (currentAttribute.IsPrimaryIdComponent)
			{
				attributeText.Append(PrimaryIdentifierString);
			}
			else
			{
				attributeText.Append(BlankString);
			}
			attributeText.Append(BlankString);

			if (currentAttribute.IsMandatory)
			{
				attributeText.Append(MandatoryString);
			}
			else
			{
				attributeText.Append(OptionalString);
			}
			attributeText.Append(BlankString);
			attributeText.Append(currentAttribute.Name);
			itemDrawInfo.Text = attributeText.ToString();
		}
Ejemplo n.º 8
0
        // Methods
        public override void DoPaint(DiagramPaintEventArgs e, ShapeElement parentShape)
        {
            base.DoPaint(e, parentShape);
            Font          font        = this.GetFont(e.View);
            CDCompartment compartment = parentShape as CDCompartment;

            if (compartment != null)
            {
                ListField listField = null;
                foreach (ShapeField field2 in compartment.ShapeFields)
                {
                    if (field2 is ListField)
                    {
                        listField = field2 as ListField;
                        break;
                    }
                }
                float MemberLineHeight  = (float)listField.GetItemHeight(parentShape);
                float MemberStartMargin = 0f;
                float stringMargin      = 0.02f;
                if (listField != null)
                {
                    int itemCount = compartment.GetItemCount(listField);
                    for (int i = 0; i < itemCount; i++)
                    {
                        ItemDrawInfo itemDrawInfo = new ItemDrawInfo();
                        MemberStartMargin = (float)listField.GetItemRectangle(parentShape, i, 0).Y;
                        compartment.GetItemDrawInfo(listField, i, itemDrawInfo);
                        if (itemDrawInfo.Disabled)
                        {
                            continue;
                        }
                        string[] strArray = itemDrawInfo.Text.Split(new char[] { ':', '(', '{', '<' });

                        Member menberByName = this.GetMenberByName(parentShape.ParentShape, strArray[0].Trim());
                        if ((menberByName == null))
                        {
                            continue;
                        }
                        string docSummary      = menberByName.DocSummary;
                        string genericTypeName = "";

                        genericTypeName = menberByName.MemberTypeShortName;

                        BackBrush.Color     = Color.White;
                        VarBrush.Color      = Color.Blue;
                        ModifierBrush.Color = Color.Blue;
                        NameBrush.Color     = Color.Black;
                        SummaryBrush.Color  = Color.Green;
                        SelectedShapesCollection seleShapes = this._FromAddin.SelectedShapes;
                        if (seleShapes != null)
                        {
                            foreach (DiagramItem item in seleShapes)
                            {
                                if (((item.Shape == compartment) && (item.Field == listField)) && (item.SubField.SubFieldHashCode == i))
                                {
                                    this.BackBrush.Color = SystemColors.Highlight;
                                    VarBrush.Color       = Color.White;
                                    NameBrush.Color      = Color.White;
                                    SummaryBrush.Color   = Color.White;
                                    ModifierBrush.Color  = Color.White;
                                    break;
                                }
                            }
                        }



                        float      recX  = (float)itemDrawInfo.ImageMargin;//0.16435f
                        RectangleD bound = parentShape.BoundingBox;

                        float width = (float)bound.Width;
                        //float MemberStartMargin = 0.26f;


                        e.Graphics.FillRectangle(this.BackBrush, VSConfigManager.CurConfig.MemberMarginX,
                                                 MemberStartMargin, width,
                                                 MemberLineHeight);

                        float curX = VSConfigManager.CurConfig.MemberMarginX;

                        string memberTypeName = menberByName.MemberTypeName.TrimEnd('?', '[', ']');
                        if (BackBrush.Color == Color.White)//非选中状态
                        {
                            if ((memberTypeName != "void") && (menberByName.MemberTypeLookupName == memberTypeName))
                            {
                                VarBrush.Color = Color.DodgerBlue;
                            }
                            //if (!menberByName.IsSpecialName)
                            //{
                            //    VarBrush.Color = Color.DodgerBlue;
                            //}
                        }
                        string curStr = null;

                        if (EnumUnit.ContainerValue((int)_summaryShowInfo, (int)SummaryShowItem.TypeName))
                        {
                            if (menberByName.IsStatic)
                            {
                                curStr = "static";
                                e.Graphics.DrawString(curStr, font, ModifierBrush, curX,
                                                      MemberStartMargin + stringMargin);
                                curX += e.Graphics.MeasureString(curStr, font).Width;
                            }


                            curStr = genericTypeName + " ";
                            e.Graphics.DrawString(curStr, font, this.VarBrush, curX,
                                                  MemberStartMargin + stringMargin);
                            curX += e.Graphics.MeasureString(curStr, font).Width;
                        }
                        if (EnumUnit.ContainerValue((int)_summaryShowInfo, (int)SummaryShowItem.MemberName))
                        {
                            curStr = menberByName.Name;
                            if (menberByName is ClrMethod)
                            {
                                curStr += "()";
                            }


                            e.Graphics.DrawString(curStr, font, this.NameBrush, curX,
                                                  MemberStartMargin + stringMargin);
                            curX += e.Graphics.MeasureString(curStr, font).Width;
                        }
                        if (EnumUnit.ContainerValue((int)_summaryShowInfo, (int)SummaryShowItem.Summary))
                        {
                            if (!string.IsNullOrEmpty(curStr))
                            {
                                curStr = ":";
                            }
                            else
                            {
                                curStr = "";
                            }
                            curStr += HttpUtility.HtmlDecode(docSummary);
                            e.Graphics.DrawString(curStr, font, this.SummaryBrush, curX,
                                                  MemberStartMargin + stringMargin);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        // Methods
        public override void DoPaint(DiagramPaintEventArgs e, ShapeElement parentShape)
        {
            base.DoPaint(e, parentShape);
            Font          font        = this.GetFont(e.View);
            CDCompartment compartment = parentShape as CDCompartment;

            if (compartment != null)
            {
                ListField listField = null;
                foreach (ShapeField field2 in compartment.ShapeFields)
                {
                    if (field2 is ListField)
                    {
                        listField = field2 as ListField;
                        break;
                    }
                }
                float MemberLineHeight = (float)listField.GetItemHeight(parentShape);
                if (listField != null)
                {
                    int itemCount = compartment.GetItemCount(listField);
                    for (int i = 0; i < itemCount; i++)
                    {
                        ItemDrawInfo itemDrawInfo = new ItemDrawInfo();
                        compartment.GetItemDrawInfo(listField, i, itemDrawInfo);
                        if (!itemDrawInfo.Disabled)
                        {
                            string[] strArray     = itemDrawInfo.Text.Split(new char[] { ':', '(', '{' });
                            Member   menberByName = this.GetMenberByName(parentShape.ParentShape, strArray[0].Trim());
                            if ((menberByName != null))
                            {
                                string docSummary = menberByName.DocSummary;
                                this.BackBrush.Color    = Color.White;
                                this.SummaryBrush.Color = Color.Green;
                                this.NameBrush.Color    = Color.Black;
                                SelectedShapesCollection seleShapes = this._FromAddin.SelectedShapes;
                                if (seleShapes != null)
                                {
                                    foreach (DiagramItem item in seleShapes)
                                    {
                                        if (((item.Shape == compartment) && (item.Field == listField)) && (item.SubField.SubFieldHashCode == i))
                                        {
                                            this.BackBrush.Color    = SystemColors.Highlight;
                                            this.SummaryBrush.Color = Color.White;
                                            this.NameBrush.Color    = Color.White;
                                            break;
                                        }
                                    }
                                }
                                float      height = 0.19f;
                                float      recX   = (float)itemDrawInfo.ImageMargin;//0.16435f
                                RectangleD bound  = parentShape.BoundingBox;
                                float      width  = (float)bound.Width;



                                e.Graphics.FillRectangle(this.BackBrush, 0f,
                                                         (0f + MemberLineHeight * (float)i),
                                                         width, MemberLineHeight);

                                DBConfigInfo dbInfo = DBConfigInfo.LoadInfo(_FromAddin.GetDesignerInfo());

                                string curStr = null;
                                float  curX   = 0f;
                                if (EnumUnit.ContainerValue((int)_summaryShowInfo, (int)SummaryShowItem.MemberName))
                                {
                                    curStr = menberByName.Name;

                                    e.Graphics.DrawString(curStr, font, this.NameBrush, curX,
                                                          (0f + MemberLineHeight * (float)i + 0.02f));
                                    curX += e.Graphics.MeasureString(curStr, font).Width;
                                }
                                if (EnumUnit.ContainerValue((int)_summaryShowInfo, (int)SummaryShowItem.Summary))
                                {
                                    if (!string.IsNullOrEmpty(curStr))
                                    {
                                        curStr = ":";
                                    }
                                    else
                                    {
                                        curStr = "";
                                    }
                                    curStr += HttpUtility.HtmlDecode(menberByName.DocSummary);
                                    e.Graphics.DrawString(curStr, font, this.SummaryBrush, curX,
                                                          (0f + MemberLineHeight * (float)i + 0.02f));
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
		/// <summary>
		/// Gets the drawing information for a particular element in the compartment.
		/// </summary>
		/// <param name="listField">The <see cref="ShapeField"/> of this <see cref="ColumnElementListCompartment"/> which
		/// paints the items in this compartment.</param>
		/// <param name="row">The index of the array of items whose item drawing information is of interest.</param>
		/// <param name="itemDrawInfo">A previously initialized <see cref="ItemDrawInfo"/> object whose properties will be modified.</param>
		public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
		{
			base.GetItemDrawInfo(listField, row, itemDrawInfo);
			Column currentColumn = this.Items[row] as Column;
			Debug.Assert(currentColumn != null, "An item in the ColumnElementListCompartment is not a column.");

			if (!currentColumn.IsNullable)
			{
				itemDrawInfo.AlternateFont = true;
			}

			StringBuilder columnText = new StringBuilder();
			bool seenConstraint = false;
			LinkedElementCollection<UniquenessConstraint> tableUniquenessConstraints = null;
			Table currentTable = null;
			foreach (UniquenessConstraint constraint in UniquenessConstraintIncludesColumn.GetUniquenessConstraints(currentColumn))
			{
				if (seenConstraint)
				{
					columnText.Append(CommaString);
				}
				if (constraint.IsPrimary)
				{
					columnText.Append(PrimaryKeyString);
				}
				else
				{
					if (tableUniquenessConstraints == null)
					{
						currentTable = currentColumn.Table;
						tableUniquenessConstraints = currentTable.UniquenessConstraintCollection;
					}
					int constraintNumber = 0;
					foreach (UniquenessConstraint tableConstraint in tableUniquenessConstraints)
					{
						if (!tableConstraint.IsPrimary)
						{
							++constraintNumber;
							if (tableConstraint == constraint)
							{
								break;
							}
						}
					}
					columnText.AppendFormat(AlternateKeyString, constraintNumber);
				}
				seenConstraint = true;
			}
			LinkedElementCollection<ReferenceConstraint> tableReferenceConstraints = null;
			foreach (ColumnReference columnReference in ColumnReference.GetLinksToTargetColumnCollection(currentColumn))
			{
				if (seenConstraint)
				{
					columnText.Append(CommaString);
				}
				if (tableReferenceConstraints == null)
				{
					if (currentTable == null)
					{
						currentTable = currentColumn.Table;
					}
					tableReferenceConstraints = currentTable.ReferenceConstraintCollection;
				}
				columnText.AppendFormat(ForeignKeyString, tableReferenceConstraints.IndexOf(columnReference.ReferenceConstraint) + 1);
				seenConstraint = true;
			}
			if (seenConstraint)
			{
				columnText.Append(ColonString);
			}
			columnText.Append(currentColumn.Name);
			if (((RelationalDiagram)this.Diagram).DisplayDataTypes)
			{
				columnText.Append(ColonString);
				columnText.Append(GetDataType(currentColumn.AssociatedValueType));
			}
			itemDrawInfo.Text = columnText.ToString();
		}