Example #1
0
        private Label CreateOrRemoveLabel(ref Label currentLabel, LabelViewHelper viewHelper, string name, string cardinality, Action selectedChanged, Action <DragDeltaEventArgs> positionChanged, ContextMenu contextMenu, ConnectorPoint snapPoint = null, Connector snapConnector = null, EPlacementCenter placementCenter = EPlacementCenter.TopLeftCorner)
        {
            if (string.IsNullOrEmpty(name) && (cardinality == "1" || string.IsNullOrEmpty(cardinality)))
            {
                if (currentLabel != null)
                {
                    if (selectedChanged != null)
                    {
                        currentLabel.SelectedChanged -= selectedChanged;
                    }
                    if (positionChanged != null)
                    {
                        currentLabel.PositionChanged -= positionChanged;
                    }
                    if (snapPoint != null)
                    {
                        currentLabel.UnSnap();
                    }
                    if (snapConnector != null)
                    {
                        currentLabel.UnSnap();
                    }
                    CreatedControls.Remove(currentLabel);
                    DiagramView.ExolutioCanvas.RemoveNode(currentLabel);
                }
                return(null);
            }

            if (currentLabel == null)
            {
                Point tmpPosition = viewHelper.Position;
                currentLabel = new Label();
                CreatedControls.Add(currentLabel);
                DiagramView.ExolutioCanvas.AddNode(currentLabel);
                currentLabel.PlacementCenter = placementCenter;
                if (snapPoint != null)
                {
                    currentLabel.SnapTo(snapPoint, true);
                }
                if (snapConnector != null)
                {
                    snapConnector.SnapNodeToConnector(currentLabel);
                }
                currentLabel.X = viewHelper.X;
                currentLabel.Y = viewHelper.Y;
                if (selectedChanged != null)
                {
                    currentLabel.SelectedChanged += selectedChanged;
                }
                if (positionChanged != null)
                {
                    currentLabel.PositionChanged += positionChanged;
                }
                currentLabel.ContextMenu = contextMenu;
                //UpdateView();
                //viewHelper.SetPositionSilent(tmpPosition.X, tmpPosition.Y);
                //currentLabel.X =
            }
            return(currentLabel);
        }
Example #2
0
        public override void PutInDiagram(DiagramView diagramView, ViewHelper viewHelper)
        {
            base.PutInDiagram(diagramView, viewHelper);
            if (parentChildUpdateBound)
            {
                PSMAssociation.PropertyChanged -= PSMAssociation_PropertyChanged_ForParentChildUpdate;
                parentChildUpdateBound          = false;
            }
#if SILVERLIGHT
            Connector = new Connector();
#else
            Connector = new Connector()
            {
                EndCapStyle = EConnectorCapStyle.Arrow
            };
#endif
            NameLabel        = new Label();
            CardinalityLabel = new Label();
            CreatedControls.Add(Connector);
            CreatedControls.Add(NameLabel);
            CreatedControls.Add(CardinalityLabel);
            DiagramView.ExolutioCanvas.AddConnector(Connector);
            Connector.Connect(SourceClassView.MainNode, TargetClassView.MainNode);
            DiagramView.ExolutioCanvas.AddNode(NameLabel);
            DiagramView.ExolutioCanvas.AddNode(CardinalityLabel);
            NameLabel.PlacementCenter = EPlacementCenter.Center;
            Connector.SnapNodeToConnector(NameLabel);
            CardinalityLabel.SnapTo(Connector.EndPoint, true);
            BindModelView();

            NameLabel.SelectedChanged        += NameLabel_SelectedChanged;
            NameLabel.PositionChanged        += NameLabel_PositionChanged;
            CardinalityLabel.PositionChanged += CardinalityLabel_PositionChanged;
            Connector.SelectedChanged        += Connector_SelectedChanged;
            Connector.MouseEnter             += Connector_MouseEnter;
            Connector.MouseLeave             += Connector_MouseLeave;
        }