public static void CreateAndTraceTopic()
        {
            IEARepository repository = EAMain.Repository;

            if (repository.GetContextItemType() == EANativeType.Element)
            {
                var eaelement = repository.GetContextObject <IEAElement>();
                if (eaelement != null && !EAMain.IsDecision(eaelement) && !EAMain.IsTopic(eaelement))
                {
                    string nameSuggestion  = string.Format(Messages.NameSuggestionTopic, eaelement.Name);
                    var    createTopicView = new CreateTopicDialog(nameSuggestion);
                    if (createTopicView.ShowDialog() == DialogResult.OK)
                    {
                        IEAPackage dvPackage = createTopicView.GetDecisionViewPackage();
                        IEAElement topic     = dvPackage.CreateElement(createTopicView.GetName(),
                                                                       EAConstants.TopicStereoType,
                                                                       EAConstants.ActivityMetaType);
                        topic.MetaType = EAConstants.TopicMetaType;
                        topic.AddTaggedValue(EATaggedValueKeys.DecisionStateModifiedDate,
                                             DateTime.Now.ToString(CultureInfo.InvariantCulture));
                        eaelement.ConnectTo(topic, EAConstants.AbstractionMetaType, EAConstants.RelationTrace);
                        topic.Update();

                        dvPackage.RefreshElements();
                        repository.RefreshModelView(dvPackage.ID);
                        topic.ShowInProjectView();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Implements IForcesModel.GetDecisions()
        /// </summary>
        /// <returns></returns>
        public IEAElement[] GetDecisions()
        {
            IEARepository repository = EAMain.Repository;

            IEAElement[] topicsElements = (from diagramObject in _diagram.GetElements()
                                           select repository.GetElementByID(diagramObject.ElementID)
                                           into element
                                           where
                                           EAMain.IsTopic(element) &&
                                           !element.TaggedValueExists(EATaggedValueKeys.IsForceElement, _diagram.GUID)
                                           select element).ToArray();



            ITopic[] topics = (from element in topicsElements select Topic.Load(element)).ToArray();

            IEnumerable <IEAElement> decisionsFromTopic =
                (from ITopic topic in topics select topic.GetDecisionsForTopic()).SelectMany(x => x);


            IEnumerable <IEAElement> decisionsDirectlyFromDiagram = (from diagramObject in _diagram.GetElements()
                                                                     select
                                                                     repository.GetElementByID(
                                                                         diagramObject.ElementID)
                                                                     into element
                                                                     where
                                                                     element.TaggedValueExists(
                                                                         EATaggedValueKeys.IsDecisionElement,
                                                                         _diagram.GUID)
                                                                     select element);

            return(decisionsFromTopic.Union(decisionsDirectlyFromDiagram).ToArray());
        }
        /********************************************************************************************
        ** EAMain Callbacks
        ********************************************************************************************/

        /// <summary>
        ///     This method is called when double clicking an element in the view pane. It opens the respective View.
        /// </summary>
        /// <param name="guid">
        ///     A string holding the GUID of the EAElement clicked by the user.
        /// </param>
        /// <param name="type">
        ///     The EANativeType of the element clicked by the user.
        /// </param>
        /// <returns></returns>
        public override bool OnContextItemDoubleClicked(string guid, EANativeType type)
        {
            // If the type is not an Element
            if (type != EANativeType.Element)
            {
                return(false);
            }
            // Get the element
            IEAElement element = EAMain.Repository.GetElementByGUID(guid);

            // If it is not a decision or a topic, leave!
            if (!(EAMain.IsDecision(element) || EAMain.IsTopic(element)))
            {
                return(false);
            }

            // Check if the tab is already open.
            if (EAMain.IsDecision(element))
            {
                OpenDecisionDetailView(Decision.Load(element));
                return(true);
            }

            if (EAMain.IsTopic(element))
            {
                OpenTopicDetailView(Topic.Load(element));
                return(true);
            }
            return(false);
        }
        private static bool ContextItemAreDecisions()
        {
            IEnumerable <IEAElement> selectedTopicsAndDecisions =
                (from IEAElement element in EAMain.Repository.GetSelectedItems()
                 where (EAMain.IsDecision(element) || EAMain.IsTopic(element)) && !EAMain.IsHistoryDecision(element)
                 select element);

            return(selectedTopicsAndDecisions.Any());
        }
Exemplo n.º 5
0
        public IEnumerable <IEAElement> GetDecisionsForTopic()
        {
            IEAElement element = EAMain.Repository.GetElementByGUID(GUID);

            if (!EAMain.IsTopic(element))
            {
                throw new Exception("EAElementImpl is not a topic");
            }

            return(from IEAElement e in element.GetElements() where EAMain.IsDecision(e) select e);
        }
Exemplo n.º 6
0
 private ITopic LoadTopic(IEAElement element)
 {
     if (element.ParentElement != null)
     {
         if (EAMain.IsTopic(element.ParentElement))
         {
             return(Model.Topic.Load(element.ParentElement));
         }
     }
     return(null);
 }
Exemplo n.º 7
0
 public override bool OnPostNewElement(IEAElement element)
 {
     if (EAMain.IsDecision(element))
     {
         element.AddTaggedValue(EATaggedValueKeys.DecisionState, element.Stereotype);
         element.AddTaggedValue(EATaggedValueKeys.IsHistoryDecision, false.ToString());
     }
     if (EAMain.IsDecision(element) || EAMain.IsTopic(element))
     {
         element.AddTaggedValue(EATaggedValueKeys.DecisionStateModifiedDate,
                                element.Modified.ToString(CultureInfo.InvariantCulture));
     }
     return(true);
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Adds an element and its children to the node
        /// </summary>
        /// <param name="node">Node to be added to</param>
        /// <param name="element"></param>
        /// <returns>A node with element information and its children</returns>
        private TreeNode AddElementToNode(TreeNode node, IEAElement element)
        {
            node.ImageKey = element.GUID;
            node.Text     = element.Name;

            foreach (IEAElement el in element.GetElements())
            {
                if (el.Name.Equals("") || EAMain.IsHistoryDecision(el))
                {
                    continue;
                }
                if (_decision && (!EAMain.IsDecision(el) && !EAMain.IsTopic(el)))
                {
                    continue;
                }
                node.Nodes.Add((AddElementToNode(new TreeNode(), el)));
            }
            return(node);
        }
Exemplo n.º 9
0
        public bool SaveChanges()
        {
            var element = EAMain.Repository.GetElementByGUID(GUID);

            if (null == element || !EAMain.IsTopic(element))
            {
                throw new Exception("element null or not a topic");
            }
            element.Name     = Name;
            element.Author   = Author;
            element.Modified = DateTime.Now;
            SaveDescription(element);
            SaveDecisions();
            SaveForces();
            SaveFiles(element);
            element.Update();
            EAMain.Repository.AdviseElementChanged(element.ID);
            Changed = false;
            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Adds a package and its children to the node
        /// </summary>
        /// <param name="node">Node to be added to</param>
        /// <param name="package">Package to be added</param>
        /// <returns>A node with the package information and its children</returns>
        private TreeNode AddPackageNode(TreeNode node, IEAPackage package)
        {
            node.ImageKey = package.GUID;
            node.Text     = package.Name;

            foreach (IEAPackage subPackage in package.Packages)
            {
                //Skip history package and packages without elements
                if (subPackage.Stereotype.Equals(EAConstants.ChronologicalStereoType) ||
                    !subPackage.GetAllElementsOfSubTree().Any())
                {
                    continue;
                }
                TreeNode subPackageNode = AddPackageNode(new TreeNode(), subPackage);
                if (null != subPackageNode)
                {
                    node.Nodes.Add(subPackageNode);
                }
            }

            int count = 0;

            foreach (IEAElement element in package.Elements)
            {
                if (element.Name.Equals("") || EAMain.IsHistoryDecision(element))
                {
                    continue;
                }
                if (_decision && (!EAMain.IsDecision(element) && !EAMain.IsTopic(element)))
                {
                    continue;
                }
                node.Nodes.Add(AddElementToNode(new TreeNode(), element));
                ++count;
            }
            if (node.GetNodeCount(true) == 0)
            {
                return(null);
            }
            return(node);
        }
Exemplo n.º 11
0
        private void LoadTopicDataFromElement(IEAElement element)
        {
            if (null == element)
            {
                throw new ArgumentNullException();
            }
            if (!EAMain.IsTopic(element))
            {
                throw new ArgumentException("not a topic");
            }

            PropertyChanged -= UpdateChangeFlag;
            GUID             = element.GUID;
            ID               = element.ID;
            Name             = element.Name;
            Description      = LoadDescription(element);
            Changed          = false;
            Author           = element.Author;
            Modified         = element.Modified;
            PropertyChanged += UpdateChangeFlag;
        }
 /// <summary>
 ///     This method is called when dragging in an element. It overrides the standard popup fro EAMain.
 /// </summary>
 /// <param name="element">
 ///     The EAElement dragged into the view pane
 /// </param>
 /// <returns></returns>
 public override bool OnPostNewElement(IEAElement element)
 {
     if (!EAMain.IsDecision(element) && !EAMain.IsTopic(element))
     {
         return(false);
     }
     // suppress properties window
     EAMain.Repository.SuppressDefaultDialogs(true);
     // Check if the tab is already open.
     if (EAMain.IsDecision(element))
     {
         OpenDecisionDetailView(Decision.Load(element));
         return(true);
     }
     if (EAMain.IsTopic(element))
     {
         OpenTopicDetailView(Topic.Load(element));
         return(true);
     }
     return(false);
 }
        static MenuEventHandler()
        {
            var createTraces           = new Model.Menu.Menu(Messages.MenuCreateTraces);
            var createAndTraceDecision = new MenuItem(Messages.MenuTraceToNewDecision,
                                                      CreateTraceMenu.CreateAndTraceDecision)
            {
                UpdateDelegate = menuItem =>
                {
                    if (EANativeType.Element == EAMain.Repository.GetContextItemType())
                    {
                        var eaelement = EAMain.Repository.GetContextObject <IEAElement>();
                        menuItem.IsEnabled = (eaelement != null && !EAMain.IsDecision(eaelement) &&
                                              !EAMain.IsTopic(eaelement));
                        return;
                    }
                    menuItem.IsEnabled = false;
                }
            };

            var createAndTraceTopic = new MenuItem(Messages.MenuTraceToNewTopic, CreateTraceMenu.CreateAndTraceTopic)
            {
                UpdateDelegate = menuItem =>
                {
                    if (EANativeType.Element == EAMain.Repository.GetContextItemType())
                    {
                        var eaelement = EAMain.Repository.GetContextObject <IEAElement>();
                        menuItem.IsEnabled = (eaelement != null && !EAMain.IsDecision(eaelement) &&
                                              !EAMain.IsTopic(eaelement));
                        return;
                    }
                    menuItem.IsEnabled = false;
                }
            };

            var generateChronologicalView = new MenuItem(Messages.MenuGenerateChronologicalVP, ChronologyMenu.Generate)
            {
                UpdateDelegate = self =>
                {
                    if (EANativeType.Package == EAMain.Repository.GetContextItemType())
                    {
                        var eapackage = EAMain.Repository.GetContextObject <IEAPackage>();
                        self.IsEnabled = (eapackage != null);
                        return;
                    }
                    self.IsEnabled = false;
                }
            };

            /*var reportMenu = new Model.Menu.Menu(Messages.MenuExport);
             * var generateWordReport = new MenuItem(Messages.MenuExportWord)
             *  {
             *      ClickDelegate = () => ReportMenu.GenerateReport(SelectedDecisionViewPackage(),"Report.docx", ReportType.Word),
             *      UpdateDelegate = self =>
             *          {
             *              self.IsEnabled = ContextItemIsDecisionViewPackage();
             *          }
             * };
             *
             * var generateExcelAllReport = new MenuItem(Messages.MenuExportExcelForcesAll)
             *  {
             *      ClickDelegate = () => ReportMenu.GenerateReport(SelectedDecisionViewPackage(),"AllForcesReport.xlsx", ReportType.Excel),
             *      UpdateDelegate = self =>
             *          {
             *              self.IsEnabled = ContextItemIsDecisionViewPackage();
             *          }
             *  };
             *
             * var generateExcelReport = new MenuItem(Messages.MenuExportExcelForces)
             *  {
             *      ClickDelegate = () =>
             *          {
             *              if (EANativeType.Diagram == EAFacade.EAMain.Repository.GetContextItemType())
             *              {
             *                  var eadiagram = EAFacade.EAMain.Repository.GetContextObject<IEADiagram>();
             *                  ReportMenu.GenerateForcesReport(eadiagram.Name + "_Report.xlsx", eadiagram);
             *              }
             *          },
             *      UpdateDelegate = self =>
             *          {
             *              if (EANativeType.Diagram == EAFacade.EAMain.Repository.GetContextItemType())
             *              {
             *                  var eadiagram = EAFacade.EAMain.Repository.GetContextObject<IEADiagram>();
             *                  self.IsEnabled = ((eadiagram != null) && eadiagram.IsForcesView());
             *                  return;
             *              }
             *              self.IsEnabled = false;
             *          }
             *  };
             *
             * var generateSelectedDecisionsWordReport = new MenuItem(Messages.MenuExportSelectedDecisionsWord)
             *  {
             *      ClickDelegate = () => ReportMenu.GenerateSelectedDecisionsReport("Report.docx", ReportType.Word),
             *      UpdateDelegate = self => { self.IsEnabled = ContextItemAreDecisions(); }
             *  };
             *
             * var generatePowerpointReport = new MenuItem(Messages.MenuExportPowerPoint)
             *  {
             *      ClickDelegate = () =>
             *                      ReportMenu.GenerateReport(SelectedDecisionViewPackage(),"Report.pptx", ReportType.PowerPoint),
             *      UpdateDelegate = self =>
             *          {
             *              self.IsEnabled = ContextItemIsDecisionViewPackage();
             *          }
             *  };
             *
             * var generateSelectedDecisionsPowerpointReport = new MenuItem(Messages.MenuExportSelectedDecisionsPowerPoint)
             *  {
             *      ClickDelegate = () =>
             *                      ReportMenu.GenerateSelectedDecisionsReport("Report.pptx", ReportType.PowerPoint),
             *      UpdateDelegate = self => { self.IsEnabled = ContextItemAreDecisions();  }
             *  };
             * */

            RootMenu.Add(createTraces);
            createTraces.Add(createAndTraceDecision);
            createTraces.Add(createAndTraceTopic);

            RootMenu.Add(new FollowTraceMenu());
            RootMenu.Add(MenuItem.Separator);
            RootMenu.Add(generateChronologicalView);
            RootMenu.Add(MenuItem.Separator);

            /* RootMenu.Add(reportMenu);
             * reportMenu.Add(generateWordReport);
             * reportMenu.Add(generatePowerpointReport);
             * reportMenu.Add(generateExcelAllReport);
             * reportMenu.Add(MenuItem.Separator);
             * reportMenu.Add(generateSelectedDecisionsWordReport);
             * reportMenu.Add(generateSelectedDecisionsPowerpointReport);
             * reportMenu.Add(generateExcelReport);*/
        }
Exemplo n.º 14
0
        public static void GenerateReport(IEAPackage decisionViewPackage, string filename, ReportType reportType)
        {
            IEARepository    repository = EAMain.Repository;
            List <IDecision> decisions  =
                decisionViewPackage.GetAllDecisions().Select(element => Decision.Load(element)).ToList();
            List <IEADiagram> diagrams = decisionViewPackage.GetAllDiagrams().ToList();

            IReportDocument report = null;

            try
            {
                string filenameExtension = filename.Substring(filename.IndexOf('.'));
                var    saveFileDialog1   = new SaveFileDialog();
                saveFileDialog1.Title  = Messages.SaveReportAs;
                saveFileDialog1.Filter = "Microsoft " + reportType.ToString() + " (*" + filenameExtension + ")|*" +
                                         filenameExtension;
                saveFileDialog1.FilterIndex = 0;

                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                saveFileDialog1.CheckFileExists = true;
                saveFileDialog1.CheckPathExists = true;
                string reportFilename = saveFileDialog1.FileName;
                report = ReportFactory.Create(reportType, reportFilename);
                //if the report cannot be created because is already used by another program a message will appear
                if (report == null)
                {
                    MessageBox.Show("Check if another program is using this file.",
                                    "Fail to create report",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                report.Open();


                //Insert Decision Relationship Viewpoint
                foreach (IEADiagram diagram in diagrams.Where(diagram => diagram.IsRelationshipView()))
                {
                    report.InsertDiagramImage(diagram);
                }

                //Retrieve Topics
                List <ITopic> topics = (from IEAElement element in repository.GetAllElements()
                                        where EAMain.IsTopic(element)
                                        select Topic.Load(element)).ToList();

                report.InsertDecisionDetailViewMessage();

                // Insert Decisions that have a Topic
                foreach (ITopic topic in topics)
                {
                    report.InsertTopicTable(topic);
                    //Insert Decisions with parent element the current Topic
                    foreach (IDecision decision in decisions)
                    {
                        IEAElement parent = EAMain.Repository.GetElementByGUID(decision.Topic.GUID);
                        if (parent != null && EAMain.IsTopic(parent))
                        {
                            if (parent.GUID.Equals(topic.GUID))
                            {
                                report.InsertDecisionTable(decision);
                            }
                        }
                    }
                }

                // Insert an appropriate message before the decisions that are not included in a topic
                report.InsertDecisionWithoutTopicMessage();

                // Insert decisions without a Topic
                foreach (IDecision decision in decisions)
                {
                    IEAElement parent = EAMain.Repository.GetElementByID(decision.ID).ParentElement;
                    if (parent == null || !EAMain.IsTopic(parent))
                    {
                        report.InsertDecisionTable(decision);
                    }
                }

                foreach (
                    IEADiagram diagram in
                    diagrams.Where(diagram => !diagram.IsForcesView() && !diagram.IsRelationshipView()))
                {
                    report.InsertDiagramImage(diagram);
                }
                foreach (IEADiagram diagram in diagrams.Where(diagram => diagram.IsForcesView()))
                {
                    report.InsertForcesTable(new ForcesModel(diagram));
                }
                var customMessage = new ExportReportsCustomMessageBox(reportType.ToString(), reportFilename);
                customMessage.Show();
            }
            finally
            {
                if (report != null)
                {
                    report.Close();
                }
            }
        }