/// <summary>
 /// Stop the DSLTools framework from placing a shape that has a non-empty location
 /// </summary>
 protected override void OnChildConfigured(ShapeElement child, bool childWasPlaced, bool createdDuringViewFixup)
 {
     if (!childWasPlaced)
     {
         TableShape shape = child as TableShape;
         if (shape != null && shape.Location != BoundsRules.GetCompliantBounds(child, RectangleD.Empty).Location)
         {
             IDictionary unplacedShapes = UnplacedShapesContext.GetUnplacedShapesMap(Store.TransactionManager.CurrentTransaction.TopLevelTransaction, this.Id);
             if (unplacedShapes.Contains(child))
             {
                 unplacedShapes.Remove(child);
             }
         }
     }
     base.OnChildConfigured(child, childWasPlaced, createdDuringViewFixup);
 }
Example #2
0
 void IModelingEventSubscriber.ManageModelingEventHandlers(ModelingEventManager eventManager, EventSubscriberReasons reasons, EventHandlerAction action)
 {
     if (action == EventHandlerAction.Add && 0 != (reasons & EventSubscriberReasons.DocumentLoading))
     {
         // Hack implementation to turn on the FixupDiagram rules before the model loads.
         // Normally this would be done with a coordinated fixup listener. However, we
         // have no control over the DSL-generated FixupDiagram rule without jumping through
         // a lot of hoops, so we do it here, which fires after the rules are created and
         // before the model loads.
         Store.RuleManager.EnableRule(typeof(FixUpDiagram));
     }
     if (0 != (reasons & EventSubscriberReasons.DocumentLoaded))
     {
         Store store = Store;
         TableShape.ManageEventHandlers(store, eventManager, action);
         RelationalDiagram.ManageEventHandlers(store, eventManager, action);
     }
 }
        private SizeD CalculateSize()
        {
            ListField  listField  = ListField;
            int        count      = this.GetItemCount(listField);
            double     height     = HeaderBounds.Height + listField.GetItemHeight(this) * count;
            double     width      = 0;
            TableShape tableShape = ParentShape as TableShape;

            string   tableName     = tableShape.AccessibleName;
            StyleSet styleSet      = StyleSet;
            Font     defaultFont   = styleSet.GetFont(listField.NormalFontId);
            Font     alternateFont = styleSet.GetFont(listField.AlternateFontId);
            Font     tableNameFont = tableShape.StyleSet.GetFont(new StyleSetResourceId(string.Empty, "ShapeTextBold10"));

            using (Graphics g = Graphics.FromHwnd(GetDesktopWindow()))
            {
                double tableNameWidth = (double)g.MeasureString(tableName, tableNameFont, int.MaxValue, DefaultStringFormat).Width + TableExtraWidth;

                // Changes the width if the current width is less than the width of the table name.
                if (width < tableNameWidth)
                {
                    width = tableNameWidth;
                }
                // 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 Column).IsNullable;
                    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 + ColumnExtraWidth;

                    // 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>
        /// Correctly connect a <see cref="ForeignKeyConnector"/>
        /// </summary>
        protected override void OnChildConfiguring(ShapeElement child, bool createdDuringViewFixup)
        {
            ForeignKeyConnector foreignKeyConnector;

            if (null != (foreignKeyConnector = child as ForeignKeyConnector))
            {
                ReferenceConstraintTargetsTable link = (ReferenceConstraintTargetsTable)child.ModelElement;
                TableShape sourceShape = null;
                Table      sourceTable;
                if (null != (sourceTable = link.ReferenceConstraint.SourceTable))
                {
                    foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(sourceTable))
                    {
                        TableShape testShape = pel as TableShape;
                        if (testShape != null && testShape.Diagram == this)
                        {
                            sourceShape = testShape;
                            break;
                        }
                    }
                }
                if (null != sourceShape)
                {
                    foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(link.TargetTable))
                    {
                        TableShape targetShape = pel as TableShape;
                        if (targetShape != null && targetShape.Diagram == this)
                        {
                            foreignKeyConnector.Connect(sourceShape, targetShape);
                            return;
                        }
                    }
                }
            }
            base.OnChildConfiguring(child, createdDuringViewFixup);
        }