Subversion Repositories DevTools

Rev

Rev 2141 | Rev 2153 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

//-----------------------------------------------------------------------
// This is open source licensed under GPL
//
//
using System;
using System.Text;
using System.Globalization;
using System.Collections;
using System.Windows.Forms;
using ReqPro40;

namespace EA_ReqPro
{
   public class Main
   {
      public String EA_Connect(EA.Repository Repository)
      {
         return "a string";
      }


      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_ReqPro";



      /// <summary>
      /// Called when EA initialised. Creates an output tab for the add in.
      /// </summary>
      /// <param name="repository"></param>
      public void EA_OnPostInitialized(EA.Repository repository)
      {
         repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);
         repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
      }
      
      
      public void EA_Disconnect()
      {
         GC.Collect();
         GC.WaitForPendingFinalizers();
      }


      /// <summary>
      /// Event called when user clicks on an entry in the output
      /// window. If an element has been associated with the message, it will
      /// be automatically selected in the project browser.
      /// </summary>
      /// <param name="repository"></param>
      /// <param name="outputTabNea"></param>
      /// <param name="lineText"></param>
      /// <param name="lineIdentifier"></param>
      public void EA_OnOutputItemClicked( EA.Repository repository,
                                          String outputTabName,
                                          String lineText,
                                          Int32 identifier)
      {
         if ((outputTabName == GUI_OUTPUT_TAB_NAME) && (identifier > 0))
         {
            try
            {
               EA.Element element = repository.GetElementByID(identifier);
               repository.ShowInProjectView(element);
            }
            catch
            {
               try
               {
                  EA.Package package = repository.GetPackageByID(identifier);
                  repository.ShowInProjectView(package);
               }
               catch
               {
               }
            }
         }
      }


      public object EA_GetMenuItems(EA.Repository repository, string location, string menu)
      {
         switch( menu )
         {
            case "":
               return "-&EA_ReqPro";

            case "-&EA_ReqPro":
            {
               string[] ar = {
                                "&Import for Traceability Use",
                                "&Display Change Log",
                                "&Import for Document Model Use",
                                "&Export to ReqPro Compatible CSV File",
                                "&Create Requirement Diagram",
                             };
               return ar;
            }
         }
         return "";
      }


      bool IsProjectOpen(EA.Repository Repository)
      {
         try
         {
            EA.Collection collection = Repository.Models;
            return true;
         }
         catch
         {
            return false;
         }
      }


      public void EA_GetMenuState(EA.Repository repository, string location, string menuName, string itemName, ref bool isEnabled, ref bool isChecked)
      {
         object o;
         EA.ObjectType type;

         isChecked = false;

         if (IsProjectOpen(repository))
         {
            switch (itemName)
            {
               case "&Import for Document Model Use":
               case "&Export to ReqPro Compatible CSV File":
               case "&Create Requirement Diagram":
               case "&Import for Traceability Use":
                  isEnabled = true;
                  break;

               case "&Display Change Log":
                  type = repository.GetTreeSelectedItem(out o);
                  if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Name == "Change Log"))
                  {
                     isEnabled = true;
                  }
                  else
                  {
                     isEnabled = false;
                  }
                  break;

            }
         }
         else
         {
            isEnabled = false;
         }
      }


      public void EA_MenuClick(EA.Repository repository, string location, string menu, string itemName)
      {
         switch( itemName )
         {
            case "&Import for Traceability Use":
            {
               ImportReqProDatabase import_parser = new ImportReqProDatabase(repository);
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
               import_parser.prompt_and_parse(repository, ReqProDB_Artifact.MODE.TRACEABILITY); 
               break;
            }

            case "&Import for Document Model Use":
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
               CopyReqProDatabase copy_parser = new CopyReqProDatabase(repository);
               copy_parser.prompt_and_parse(repository, ReqProDB_Artifact.MODE.DOC_MODEL);
               break;

            case "&Export to ReqPro Compatible CSV File":
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
               ExportToReqProCSVForm export_dlg = new ExportToReqProCSVForm();
               DialogResult dlgRes = export_dlg.ShowDialog();
               if (dlgRes == DialogResult.OK)
               {
                  export_dlg.Export(repository);
               }
               break;

            case "&Display Change Log":
            {
               ImportReqProDatabase import_parser = new ImportReqProDatabase(repository);
               EA.Element changeLog = (EA.Element)repository.GetTreeSelectedObject();
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
               import_parser.displayChangeLog(repository, changeLog);
               break;
            }

            case "&Create Requirement Diagram":
            {
               EA_Utilities EA_Utils = new EA_Utilities(repository);
               ArrayList allowedElementTypes = new ArrayList();
               allowedElementTypes.Add("Requirement");
               //allowedElementTypes.Add("UseCase");
               ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
               EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
               EA_Utils.findAndProcessPackageElements( thePackage, reqLister, true );
               EA.Diagram newDiagram = (EA.Diagram)thePackage.Diagrams.AddNew("Requirements","Logical");
               newDiagram.Update();
               thePackage.Update();

               foreach (EA.Element element in reqLister.Elements)
               {
                  EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
                  newDiagramObject.ElementID = element.ElementID;
                  newDiagramObject.Update();
               }
               newDiagram.DiagramObjects.Refresh();
               thePackage.Update();
               repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID, 
                  EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
               break;

            }

         }
      }


   }
}