public void Execute(Shape changedShape, string identifier)
        {
            RationallyModel       model = Globals.RationallyAddIn.Model;
            StakeholdersContainer stakeholdersContainer = (StakeholdersContainer)Globals.RationallyAddIn.View.Children.First(c => c is StakeholdersContainer);

            VisioShape toChangeComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape);
            int        currentIndex      = toChangeComponent.Index;

            StakeholderContainer toChange = (StakeholderContainer)stakeholdersContainer.Children.First(c => c.Index == currentIndex);
            //locate the stakeholder that we are going to swap with
            StakeholderContainer other = (StakeholderContainer)stakeholdersContainer.Children.First(c => c.Index == currentIndex + 1);

            Stakeholder one = model.Stakeholders[currentIndex];

            model.Stakeholders[currentIndex]     = model.Stakeholders[currentIndex + 1];
            model.Stakeholders[currentIndex + 1] = one;

            //update the index of the component and his children
            toChange.SetStakeholderIndex(currentIndex + 1);

            //same, for the other component
            other.SetStakeholderIndex(currentIndex);

            //swap the elements in the view tree
            VisioShape temp = stakeholdersContainer.Children[currentIndex];

            stakeholdersContainer.Children[currentIndex]     = stakeholdersContainer.Children[currentIndex + 1];
            stakeholdersContainer.Children[currentIndex + 1] = temp;


            RepaintHandler.Repaint();
        }
        public void Execute(Shape changedShape, string identifier)
        {
            RationallyModel model = Globals.RationallyAddIn.Model;
            //locate the stakeholder(component) to move
            VisioShape toChangeComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape);
            int        currentIndex      = toChangeComponent.Index;
            //locate the stakeholder to swap with
            StakeholdersContainer stakeholdersContainer = (StakeholdersContainer)Globals.RationallyAddIn.View.Children.First(c => c is StakeholdersContainer);
            StakeholderContainer  toChange = (StakeholderContainer)stakeholdersContainer.Children.First(c => (int)c.Shape.CellsU[VisioFormulas.Cell_Index].ResultIU == currentIndex);
            StakeholderContainer  other    = (StakeholderContainer)stakeholdersContainer.Children.First(c => (int)c.Shape.CellsU[VisioFormulas.Cell_Index].ResultIU == currentIndex - 1);

            //swap
            Stakeholder one = model.Stakeholders[currentIndex];

            model.Stakeholders[currentIndex]     = model.Stakeholders[currentIndex - 1];
            model.Stakeholders[currentIndex - 1] = one;

            //update the index of the component and his children
            toChange.SetStakeholderIndex(currentIndex - 1);
            //same, for the other component
            other.SetStakeholderIndex(currentIndex);
            //swap the elements
            VisioShape temp = stakeholdersContainer.Children[currentIndex];

            stakeholdersContainer.Children[currentIndex]     = stakeholdersContainer.Children[currentIndex - 1];
            stakeholdersContainer.Children[currentIndex - 1] = temp;


            RepaintHandler.Repaint();
        }
        public void Execute(Shape s, string identifier)
        {
            RationallyModel model     = Globals.RationallyAddIn.Model;
            VisioShape      component = new VisioShape(Globals.RationallyAddIn.Application.ActivePage)
            {
                Shape = s
            };

            int          index         = component.Index;
            Stakeholder  stakeholder   = model.Stakeholders[index];
            DialogResult confirmResult = MessageBox.Show("Are you sure you want to remove " + stakeholder.Name + "?", "Confirm Deletion", MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                Shape shapeToPass;

                if (StakeholderContainer.IsStakeholderContainer(s.Name))
                {
                    shapeToPass = s;
                }
                else //subpart of stakeholder container
                {
                    //trace stakeholders container
                    StakeholdersContainer stakeholdersContainer = (StakeholdersContainer)Globals.RationallyAddIn.View.Children.First(c => c is StakeholdersContainer);
                    //trace the correct stakeholder container
                    StakeholderContainer stakeholderContainer = (StakeholderContainer)stakeholdersContainer.Children.First(c => c is StakeholderContainer && (component.Index == c.Index));

                    shapeToPass = stakeholderContainer.Shape;
                }
                //initiate a delete handler with the container's shape
                shapeToPass.Delete();
            }
        }
        public void RegenerateStakeholderIdentifiers()
        {
            int i = 0;
            StakeholdersContainer stakeholdersContainer = (StakeholdersContainer)Globals.RationallyAddIn.View.Children.First(c => c is StakeholdersContainer);

            stakeholdersContainer.Children.Where(c => c is StakeholderContainer).ToList().ForEach(c => ((StakeholderContainer)c).SetStakeholderIndex(i++));
        }
Exemplo n.º 5
0
        public void Execute(RationallyView view, Shape changedShape)
        {
            StakeholdersContainer cont = (StakeholdersContainer)view.Children.First(x => x is StakeholdersContainer);

            foreach (StakeholderContainer stakeholderContainer in cont.Children.Where(c => c is StakeholderContainer).Cast <StakeholderContainer>().ToList())
            {
                if ((stakeholderContainer.Children.Where(c => c.Shape.Equals(changedShape)).ToList().Count > 0) && !stakeholderContainer.Deleted) //check if this stakeholder contains the to be deleted component and is not already deleted
                {
                    stakeholderContainer.Deleted = true;
                    stakeholderContainer.Shape.Delete(); //delete the parent wrapper of s
                }
            }
        }
Exemplo n.º 6
0
        public void Execute(RationallyModel model, Shape changedShape)
        {
            Log.Debug("Entered delete stakeholder event handler.");
            //store the rationally type of the last shape, which is responsible for ending the undo scope
            if (string.IsNullOrEmpty(Globals.RationallyAddIn.LastDelete) && (Globals.RationallyAddIn.StartedUndoState == 0) && !Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
            {
                Log.Debug("Starting undo scope.");
                Globals.RationallyAddIn.LastDelete       = changedShape.Name;
                Globals.RationallyAddIn.StartedUndoState = Globals.RationallyAddIn.Application.BeginUndoScope(DeleteUndoScope);
            }

            //trace stakeholder container in view tree
            VisioShape stakeholderComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape);

            StakeholderContainer delete = stakeholderComponent as StakeholderContainer;

            if (delete != null)
            {
                StakeholderContainer containerToDelete = delete;
                if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
                {
                    Log.Debug("killing children of the stakeholder to kill");
                    containerToDelete.Children.Where(c => !c.Deleted).ToList().ForEach(c =>
                    {
                        c.Deleted = true;
                        c.Shape.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
                    }); //schedule the missing delete events (children not selected during the manual delete)
                }
                StakeholdersContainer stakeholdersContainer = (StakeholdersContainer)Globals.RationallyAddIn.View.Children.First(c => c is StakeholdersContainer);
                //update model
                model.Stakeholders.RemoveAll(sth => sth.Id == containerToDelete.Id);
                Log.Debug("stakeholder removed from stakeholders container.");
                //update view tree
                stakeholdersContainer.Children.Remove(containerToDelete);

                model.RegenerateStakeholderIdentifiers();
                if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
                {
                    stakeholdersContainer.MsvSdContainerLocked = true;
                }
                RepaintHandler.Repaint();
            }
        }
        private void Application_ShapeAddedEvent(Shape s)
        {
            Log.Debug("Shape added with name: " + s.Name);
            if (s.Document.Template.Contains(Information.TemplateName) && (s.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists) && !View.ExistsInTree(s))
            {
                try
                {
                    switch (s.CellsU[VisioFormulas.Cell_RationallyType].ResultStr[VisioFormulas.Value])
                    {
                    case "alternativeAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddAlternative);
                            s.Delete();
                            AlternativesContainer alternativesContainer = Globals.RationallyAddIn.View.Children.FirstOrDefault(ch => ch is AlternativesContainer) as AlternativesContainer;
                            alternativesContainer?.AddAlternative("Title", default(AlternativeState).GetName());

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "forceAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddForce);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("forces.add", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "relatedDocumentAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddFile);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedFile", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "relatedUrlAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddUrl);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedUrl", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "stakeholderAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddStakeholder);
                            s.Delete();
                            StakeholdersContainer stakeholdersContainer = View.Children.FirstOrDefault(ch => ch is StakeholdersContainer) as StakeholdersContainer;
                            stakeholdersContainer?.AddStakeholder("<<name>>", "<<role>>");

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "planningItemStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddPlanningItem);
                            s.Delete();
                            PlanningContainer planningContainer = View.Children.FirstOrDefault(ch => ch is PlanningContainer) as PlanningContainer;
                            planningContainer?.AddPlanningItem();

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    default:
                        View.AddToTree(s, true);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex);
#if DEBUG
                    throw;
#endif
                }
            }
        }
Exemplo n.º 8
0
        public void Execute(Shape changedShape, string identifier)
        {
            StakeholdersContainer stakeholdersContainer = (StakeholdersContainer)Globals.RationallyAddIn.View.Children.First(ch => ch is StakeholdersContainer);

            stakeholdersContainer?.AddStakeholder("<<name>>", "<<role>>");
        }
Exemplo n.º 9
0
 public override void AddToTree(Shape s, bool allowAddOfSubpart)
 {
     if (AlternativesContainer.IsAlternativesContainer(s.Name))
     {
         if (Children.Exists(x => AlternativesContainer.IsAlternativesContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneAlternativesContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             Children.Add(new AlternativesContainer(Page, s));
         }
     }
     else if (RelatedDocumentsContainer.IsRelatedDocumentsContainer(s.Name))
     {
         if (Children.Exists(x => RelatedDocumentsContainer.IsRelatedDocumentsContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneRelatedDocumentsContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             RelatedDocumentsContainer rdc = new RelatedDocumentsContainer(Page, s);
             Children.Add(rdc);
         }
     }
     else if (ForcesContainer.IsForcesContainer(s.Name))
     {
         if (Children.Exists(x => ForcesContainer.IsForcesContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneForcesContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             ForcesContainer forcesContainer = new ForcesContainer(Page, s);
             Children.Add(forcesContainer);
         }
     }
     else if (InformationContainer.IsInformationContainer(s.Name))
     {
         if (Children.Exists(x => InformationContainer.IsInformationContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneInformationContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             InformationContainer informationContainer = new InformationContainer(Page, s);
             Children.Add(informationContainer);
         }
     }
     else if (TitleLabel.IsTitleLabel(s.Name))
     {
         if (Children.Exists(x => TitleLabel.IsTitleLabel(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneTitleAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             TitleLabel titleLabel = new TitleLabel(Page, s);
             Children.Add(titleLabel);
         }
     }
     else if (StakeholdersContainer.IsStakeholdersContainer(s.Name))
     {
         if (Children.Exists(x => StakeholdersContainer.IsStakeholdersContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneStakeholdersContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             StakeholdersContainer stakeholdersContainer = new StakeholdersContainer(Page, s);
             Children.Add(stakeholdersContainer);
         }
     }
     else if (PlanningContainer.IsPlanningContainer(s.Name))
     {
         if (Children.Exists(x => PlanningContainer.IsPlanningContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OnePlanningContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             PlanningContainer planningContainer = new PlanningContainer(Page, s);
             Children.Add(planningContainer);
         }
     }
     else if (allowAddOfSubpart)
     {
         Children.ForEach(r => r.AddToTree(s, true));
     }
 }