コード例 #1
0
        public override void InvokeHandler(CommandSetState state)
        {
            var store = state.CurrentDocView.CurrentDiagram.Store;

            ModelerTransaction.Enter(() =>
            {
                using (Transaction tx = store.TransactionManager.BeginTransaction())
                {
                    var addAssociationForm = new AddAssociationForm(state.CurrentDocView.CurrentDiagram.Store);
                    if (state.CurrentSelection.Count == 1)
                    {
                        var selection = state.CurrentSelection.Cast<object>().First();
                        if (selection is ClassShape)
                        {
                            var modelClass = ((ClassShape)selection).ModelElement as ModelClass;
                            addAssociationForm.SetSelectedClasses(modelClass);
                        }
                    }
                    addAssociationForm.ShowDialog();

                    tx.Commit();
                }
            });

            /*
            MenuCommand command = sender as MenuCommand;

            StringBuilder sb = new StringBuilder();
            sb.Append("Command: " + Commands.Values.First(x => x.CommandGuid == command.CommandID.Guid).Type.ToString() + "\n");
            foreach (object selectedObject in this.CurrentSelection)
            {
                sb.AppendLine("Selected Shape: " + selectedObject.ToString());

                if (selectedObject is ClassShape)
                {
                    ModelClass modelClass = (ModelClass)(selectedObject as ClassShape).ModelElement;
                    sb.AppendLine("*** Related Domain Class: " + modelClass.ToString());
                }

                if (selectedObject is ClassDiagram)
                {
                }
            }


            */
        }
コード例 #2
0
ファイル: AgileModelerDocData.cs プロジェクト: jeswin/AgileFx
        public void HandleElementAdded(object sender, ElementAddedEventArgs e)
        {
            if (ModelerTransaction.IsInTransaction) return;
         
            ModelerTransaction.Enter(() =>
                {
                    using (Transaction tx = (sender as Store).TransactionManager.BeginTransaction())
                    {
                        if (e.ModelElement is ModelClass)
                        {
                            e.ModelElement.Delete();
                            var dlg = new AddEntityForm(sender as Store);
                            dlg.ShowDialog();
                        }
                        else if (e.ModelElement is Inheritance)
                        {
                            var inheritance = e.ModelElement as Inheritance;
                            var baseClassName = inheritance.Superclass.Name;
                            var derivedClassName = inheritance.Subclass.Name;
                            inheritance.Delete();
                            InheritanceUtil.AddInheritance(sender as Store, baseClassName, derivedClassName);
                        }
                        else if (e.ModelElement is Association)
                        {
                            var assoc = e.ModelElement as Association;
                            var dlg = new AddAssociationForm(sender as Store);
                            dlg.SetSelectedClasses(assoc.Source, assoc.Target);
                            assoc.Delete();
                            dlg.ShowDialog();
                        }
                        else if (e.ModelElement is NavigationProperty)
                        {
                            var parentClass = (e.ModelElement as NavigationProperty).ModelClass;
                            e.ModelElement.Delete();
                            var addAssociationForm = new AddAssociationForm(sender as Store);
                            addAssociationForm.SetSelectedClasses(parentClass);
                            addAssociationForm.ShowDialog();
                        }

                        if (tx.HasPendingChanges) tx.Commit();
                    }
                });
        }