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
            PlanningContainer     planningContainer = (PlanningContainer)Globals.RationallyAddIn.View.Children.First(c => c is PlanningContainer);
            PlanningItemComponent toChange          = (PlanningItemComponent)planningContainer.Children.First(c => (int)c.Shape.CellsU[VisioFormulas.Cell_Index].ResultIU == currentIndex);
            PlanningItemComponent other             = (PlanningItemComponent)planningContainer.Children.First(c => (int)c.Shape.CellsU[VisioFormulas.Cell_Index].ResultIU == currentIndex - 1);

            //swap
            PlanningItem one = model.PlanningItems[currentIndex];

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

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

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


            RepaintHandler.Repaint();
        }
Example #2
0
        public void Execute(Shape changedShape, string identifier)
        {
            RationallyModel   model             = Globals.RationallyAddIn.Model;
            PlanningContainer planningContainer = (PlanningContainer)Globals.RationallyAddIn.View.Children.First(c => c is PlanningContainer);

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

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

            PlanningItem one = model.PlanningItems[currentIndex];

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

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

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

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

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


            RepaintHandler.Repaint();
        }
Example #3
0
        public void Execute(Shape s, string identifier)
        {
            VisioShape component = new VisioShape(Globals.RationallyAddIn.Application.ActivePage)
            {
                Shape = s
            };


            DialogResult confirmResult = MessageBox.Show("Are you sure you want to delete this item?", "Confirm Deletion", MessageBoxButtons.YesNo);

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

                if (PlanningItemComponent.IsPlanningItem(s.Name))
                {
                    shapeToPass = s;
                }
                else //subpart of planning item component
                {
                    //trace planning container
                    PlanningContainer planningContainer = (PlanningContainer)Globals.RationallyAddIn.View.Children.First(c => c is PlanningContainer);
                    //trace the correct planningItemComponent
                    PlanningItemComponent planningItemComponent = (PlanningItemComponent)planningContainer.Children.First(c => c is PlanningItemComponent && (component.Index == c.Index));

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

            planningContainer.Children.Where(c => c is PlanningItemComponent).ToList().ForEach(c => ((PlanningItemComponent)c).SetPlanningItemIndex(i++));
        }
Example #5
0
        private void Check(bool isChecked)
        {
            //update model
            Globals.RationallyAddIn.Model.PlanningItems[Index].Finished = isChecked;
            PlanningContainer planningContainer = Globals.RationallyAddIn.View.Children.FirstOrDefault(c => c is PlanningContainer) as PlanningContainer;

            planningContainer.Children[Index].Repaint();

            /*PlanningContainer planningContainer = (Globals.RationallyAddIn.View.Children.FirstOrDefault(c => c is PlanningContainer) as PlanningContainer);
             * //locate parent of stateComponent
             * PlanningItemComponent toStrikeThrough = planningContainer?.Children.Cast<PlanningItemComponent>().First(item => (item.Children.First(c => c is CheckBoxComponent) as CheckBoxComponent).Children.Contains(this));
             * toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough = isChecked;*/
        }
Example #6
0
        public void Execute(RationallyView view, Shape changedShape)
        {
            PlanningContainer cont = (PlanningContainer)view.Children.First(x => x is PlanningContainer);

            foreach (PlanningItemComponent planningComponent in cont.Children.Where(c => c is PlanningItemComponent).Cast <PlanningItemComponent>().ToList())
            {
                //check if this planning component contains the to be deleted component and is not already deleted
                if (planningComponent.ExistsInTree(changedShape) && !planningComponent.Deleted)
                {
                    planningComponent.Deleted = true;
                    planningComponent.Shape.Delete(); //delete the parent wrapper of s
                }
            }
        }
Example #7
0
        public void Execute(RationallyModel model, Shape changedShape)
        {
            Log.Debug("Entered delete planningitem 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 planning item container in view tree
            VisioShape planningComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape);

            PlanningItemComponent delete = planningComponent as PlanningItemComponent;

            if (delete != null)
            {
                PlanningItemComponent containerToDelete = delete;
                if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
                {
                    Log.Debug("deleting children of the planning item to delete");
                    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)
                }
                PlanningContainer planningContainer = (PlanningContainer)Globals.RationallyAddIn.View.Children.First(c => c is PlanningContainer);
                //update model
                model.PlanningItems.RemoveAll(p => p.Id == containerToDelete.Id);
                Log.Debug("Planning item removed from planning container.");
                //update view tree
                planningContainer.Children.Remove(containerToDelete);

                model.RegeneratePlanningIdentifiers();//one index no longer exists, so let the view adapt to the new index range

                if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
                {
                    planningContainer.MsvSdContainerLocked = true;
                }
                RepaintHandler.Repaint();
            }
        }
        private void Application_MouseDown(int button, int keyButtonState, double x, double y, ref bool cancelDefault)
        {
            if (button != 1) //if other than the left mouse button was clicked
            {
                return;
            }

            PlanningContainer planningContainer = View.Children.FirstOrDefault(c => c is PlanningContainer) as PlanningContainer;
            //locate all checkbox elements in the view
            List <CheckBoxStateComponent> candidates = planningContainer?.Children //map all planning items to their checkbox child, and that checkbox to its state component
                                                       .Select(planningItemComponent => ((PlanningItemComponent)planningItemComponent).Children
                                                               .First(c => c is CheckBoxComponent)).Cast <CheckBoxComponent>()
                                                       .Select(checkBox => (CheckBoxStateComponent)checkBox.Children.First()).ToList();

            if (candidates == null)
            {
                return;
            }
            CheckBoxStateComponent stateComponent = null;

            //for all the candidates, check if the clicked location was within its bounds. Stop as soon as a match if found.
            foreach (CheckBoxStateComponent candidate in candidates)
            {
                if (candidate.WasClicked(x, y))
                {
                    int scopeId = Application.BeginUndoScope(Messages.Scope_CheckboxClick);
                    candidate.Toggle(); //actual changing of the clicked checkbox's state
                    Application.EndUndoScope(scopeId, true);
                    break;
                }
            }

            //locate parent of stateComponent
            //PlanningItemComponent toStrikeThrough = planningContainer?.Children.Cast<PlanningItemComponent>().First(item => (item.Children.First(c => c is CheckBoxComponent) as CheckBoxComponent).Children.Contains(stateComponent));
            //toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough = !toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough;
        }
        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
                }
            }
        }
Example #10
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));
     }
 }
        public void Execute(Shape s, string context)
        {
            PlanningContainer planningContainer = (PlanningContainer)Globals.RationallyAddIn.View.Children.First(ch => ch is PlanningContainer);

            planningContainer.AddPlanningItem();
        }