Exemplo n.º 1
0
        private void UpdateSize(SizeD newSize)
        {
            Size = newSize;
            BarkerEntityShape parent = (BarkerEntityShape)ParentShape;

            parent.Size = new SizeD(newSize.Width, parent.Size.Height + newSize.Height);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes this <see cref="BarkerERDiagram"/>.
        /// </summary>
        /// <param name="writer">A <see cref="T:System.Xml.XmlWriter"/> that will write the custom serialization contents.</param>
        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            string rvNamespace = BarkerERShapeDomainModel.XmlNamespace;
            // <BarkerERDiagram>
            //    <BarkerEntityShape ObjectTypeRef="" Location="x, y" />
            //    ...
            // </BarkerERDiagram>
            ISerializationContext serializationContext = ((ISerializationContextHost)Store).SerializationContext;

            writer.WriteStartElement(BarkerERDiagramElementName, rvNamespace);
            writer.WriteAttributeString(IdAttributeName, serializationContext.GetIdentifierString(Id));
            writer.WriteAttributeString(SubjectRefAttributeName, serializationContext.GetIdentifierString(this.ModelElement.Id));
            TypeConverter typeConverter = TypeDescriptor.GetConverter(typeof(PointD));

            foreach (ShapeElement shapeElement in this.NestedChildShapes)
            {
                BarkerEntityShape barkerEntityShape = shapeElement as BarkerEntityShape;
                if (barkerEntityShape != null)
                {
                    ConceptType conceptType;
                    ObjectType  objectType;
                    if (null != (conceptType = EntityTypeIsPrimarilyForConceptType.GetConceptType((EntityType)barkerEntityShape.ModelElement)) &&
                        null != (objectType = ConceptTypeIsForObjectType.GetObjectType(conceptType)))
                    {
                        writer.WriteStartElement(BarkerEntityShapeElementName, rvNamespace);
                        writer.WriteAttributeString(ObjectTypeRefAttributeName, serializationContext.GetIdentifierString(objectType.Id));
                        writer.WriteAttributeString(LocationAttributeName, typeConverter.ConvertToInvariantString(barkerEntityShape.Location));
                        writer.WriteEndElement();
                    }
                }
            }
            writer.WriteEndElement();
        }
Exemplo n.º 3
0
        protected static void UpdateShapeEvent(object sender, ElementPropertyChangedEventArgs e)
        {
            BarkerEntityShape shape = (BarkerEntityShape)e.ModelElement;

            if (!shape.IsDeleted)
            {
                //shape.BeforeInvalidate();
                shape.Invalidate(Math.Abs(unchecked ((long)e.OldValue - (long)e.NewValue)) != 1L);
            }
        }
Exemplo n.º 4
0
 /// <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)
     {
         BarkerEntityShape shape = child as BarkerEntityShape;
         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);
 }
Exemplo n.º 5
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;
         BarkerEntityShape.ManageEventHandlers(store, eventManager, action);
         BarkerERDiagram.ManageEventHandlers(store, eventManager, action);
     }
 }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Cache the location of any entity shape associated with the provided <see cref="ObjectType"/> and <see cref="EntityType"/>
 /// </summary>
 private static void RememberBarkerEntityShapeLocations(ObjectType objectType, EntityType entity)
 {
     foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(entity))
     {
         BarkerEntityShape shape = pel as BarkerEntityShape;
         if (pel != null)
         {
             Dictionary <object, object> context = objectType.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
             object tablePositionsObject;
             Dictionary <Guid, PointD> barkerEntityPositions;
             if (!context.TryGetValue(BarkerEntityPositionDictionaryKey, out tablePositionsObject) ||
                 (barkerEntityPositions = tablePositionsObject as Dictionary <Guid, PointD>) == null)
             {
                 context[BarkerEntityPositionDictionaryKey] = barkerEntityPositions = new Dictionary <Guid, PointD>();
             }
             barkerEntityPositions[objectType.Id] = shape.Location;
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Correctly connect a <see cref="AssociationConnector"/>
        /// </summary>
        protected override void OnChildConfiguring(ShapeElement child, bool createdDuringViewFixup)
        {
            AssociationConnector connector;

            if (null != (connector = child as AssociationConnector))
            {
                BarkerErModelContainsBinaryAssociation link = (BarkerErModelContainsBinaryAssociation)child.ModelElement;
                BarkerEntityShape sourceShape = null;
                EntityType        sourceEntity;
                if (null != (sourceEntity = link.BinaryAssociation.RoleCollection[0].EntityType))
                {
                    foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(sourceEntity))
                    {
                        BarkerEntityShape testShape = pel as BarkerEntityShape;
                        if (testShape != null && testShape.Diagram == this)
                        {
                            sourceShape = testShape;
                            break;
                        }
                    }
                }
                if (null != sourceShape)
                {
                    foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(link.BinaryAssociation.RoleCollection[1].EntityType))
                    {
                        BarkerEntityShape targetShape = pel as BarkerEntityShape;
                        if (targetShape != null && targetShape.Diagram == this)
                        {
                            connector.Connect(sourceShape, targetShape);
                            return;
                        }
                    }
                }
            }
            base.OnChildConfiguring(child, createdDuringViewFixup);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Reorder compartment items when a attribute is renamed.
        /// </summary>
        private static void AttributeRenamedEvent(object sender, ElementPropertyChangedEventArgs e)
        {
            Barker.Attribute attribute = (Barker.Attribute)e.ModelElement;
            EntityType       barkerEntity;

            if (!attribute.IsDeleted &&
                null != (barkerEntity = attribute.EntityType))
            {
                foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(barkerEntity))
                {
                    BarkerEntityShape shape = pel as BarkerEntityShape;
                    if (shape != null)
                    {
                        foreach (ShapeElement childShape in shape.NestedChildShapes)
                        {
                            AttributeElementListCompartment compartment;
                            OrderedElementList <Barker.Attribute, AttributeElementListCompartment> attributeList;
                            int oldIndex;
                            int newIndex;
                            if (null != (compartment = childShape as AttributeElementListCompartment) &&
                                null != (attributeList = compartment.Items as OrderedElementList <Barker.Attribute, AttributeElementListCompartment>))

                            {
                                if (attributeList.OnElementReorder(attribute, out oldIndex, out newIndex))
                                {
                                    Diagram     diagram;
                                    DiagramView view;
                                    SelectedShapesCollection selection;
                                    if (null != (diagram = shape.Diagram) &&
                                        null != (view = diagram.ActiveDiagramView) &&
                                        null != (selection = view.Selection))
                                    {
                                        ShapeField testField = compartment.ListField;
                                        foreach (DiagramItem selectedItem in selection)
                                        {
                                            ListItemSubField testSubField;
                                            if (selectedItem.Shape == compartment &&
                                                selectedItem.Field == testField &&
                                                null != (testSubField = selectedItem.SubField as ListItemSubField))
                                            {
                                                int testRow = testSubField.Row;
                                                if (testRow == oldIndex)
                                                {
                                                    testSubField.Row = newIndex;
                                                }
                                                else
                                                {
                                                    int adjustRow = testRow;
                                                    if (testRow > oldIndex)
                                                    {
                                                        --adjustRow;
                                                    }
                                                    if (adjustRow >= newIndex)
                                                    {
                                                        ++adjustRow;
                                                    }
                                                    if (adjustRow != testRow)
                                                    {
                                                        testSubField.Row = adjustRow;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }