Rev 2114 | Rev 2126 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;using System.Windows.Forms;using System.IO;using Word;using System.Threading;using System.Text;namespace EA_DocGen{/// <summary>////// </summary>public class Main{public AboutForm theForm;// All other classes access the EA repository through this public static itempublic static EA.Repository EA_Repository = null;public readonly static String GUI_OUTPUT_TAB_NAME = "EA_DocGen";// EA_DocGen Menu strings///////////////////////////////////////////////////////////////////////////////////// The Main Menu//////////////////////////////////////////////////////////////////////////////////private const string MI_Root = "-&EA DocGen";private const string MI_Separator = "-";private const string MI_GenDocFromModelLayout = "&Generate Document From Model Layout";private const string MI_CopyGUIDToClipboard = "&Copy GUID To Clipboard";private const string MI_AddTableElement = "&Add Table Element";private const string MI_AddTextElement = "&Add Text Element";private const string MI_AddRelMatrixElement = "&Add RelationshipMatrix Element";private const string MI_AddTestTraceabilityElement = "&Add Test Traceability Element";private const string MI_AddDocumentReference = "&Add Document Reference";private const string MI_AddTerminologyEntry = "&Add Terminology Entry";private const string MI_ModifyDocumentOptions = "&Modify EA_DocGen Options";private const string MI_GenModelLayoutForDesignDoc = "&Generate Model Layout For Design Document";private const string MI_GenBasicModelLayout = "&Generate Basic Document Model Layout";private const string MI_GenStandardViews = "&Generate Standard Views";private const string MI_About = "&About...";private string[] MI_RootMenu = new string[] { MI_GenDocFromModelLayout,MI_Separator,MI_CopyGUIDToClipboard,MI_UsingCopiedGUID, // sub-menuMI_Separator,MI_AddTableElement,MI_AddTextElement,MI_AddRelMatrixElement,MI_AddTestTraceabilityElement,MI_Separator,MI_AddDocumentReference,MI_AddTerminologyEntry,MI_Separator,MI_ModifyDocumentOptions,MI_Separator,MI_GenModelLayoutForDesignDoc,MI_GenBasicModelLayout,MI_GenStandardViews,MI_Separator,MI_MiscUtils, // sub-menuMI_About };///////////////////////////////////////////////////////////////////////////////////// Using Copied GUID sub-menu//////////////////////////////////////////////////////////////////////////////////private const string MI_UsingCopiedGUID = "-&Using Copied GUID...";private const string MI_AddLinkElement = "&Add Link Element";private const string MI_AddTestLinkElement = "&Add Test Link Element";private const string MI_AddNameLinkElement = "&Add Name Link Element";private const string MI_GenPkgsFromEleList = "&Generate Packages From Element List";private const string MI_GenSubPkgLinks = "&Generate Sub-Package Links";private const string MI_GenEleLinks = "&Generate Element Links";private string[] MI_UsingCopiedGUIDSubMenu = new string[] { MI_AddLinkElement,MI_AddTestLinkElement,MI_AddNameLinkElement,MI_Separator,MI_GenPkgsFromEleList,MI_GenSubPkgLinks,MI_GenEleLinks};///////////////////////////////////////////////////////////////////////////////////// Misc Utils sub-menu//////////////////////////////////////////////////////////////////////////////////private const string MI_MiscUtils = "-&Misc Utils";private const string MI_MarkContentWithAPIStereotype = "&Mark Content With API Stereotype";private const string MI_RemoveAPIStereotypeFromContent = "&Remove API Stereotype From Content";private const string MI_ShowDiscoveryOrder = "&Show Package/Element Discovery Order";private const string MI_FollowLink = "&Follow Link";private const string MI_UpdateLink = "&Update Link";private const string MI_IdentifyClipboardItem = "&Identify Clipboard Item";private string[] MI_MiscUtilsSubMenu = new string[] { MI_MarkContentWithAPIStereotype,MI_RemoveAPIStereotypeFromContent,MI_Separator,MI_ShowDiscoveryOrder,MI_Separator,MI_FollowLink,MI_UpdateLink,MI_Separator,MI_IdentifyClipboardItem };// Thread variables so the document generation dialog can be detached from the EA thread that// is used to drive EA_DocGen via the menusprivate Thread threadCreateDoc = null;public static bool threadCreateDocDialogRunning = false; // true when the docu gen dialog is being shownpublic static bool threadCreateDocProcessRunning = false; // true when document generation is taking place//Called Before EA starts to check Add-In Existspublic String EA_Connect(EA.Repository Repository){EA_Repository = Repository;//No special processing required.return "a string";}/// <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){EA_Repository = Repository;Repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);}//Called when user Click Add-Ins Menu item from within EA.//Populates the Menu with our desired selections.public object EA_GetMenuItems(EA.Repository Repository, string Location, string MenuName){EA_Repository = Repository;switch( MenuName ){case "":return MI_Root;case MI_UsingCopiedGUID:return MI_UsingCopiedGUIDSubMenu;case MI_MiscUtils:return MI_MiscUtilsSubMenu;case "-&EA DocGen":return MI_RootMenu;}return "";}//Sets the state of the menu depending if there is an active project or notbool IsProjectOpen(EA.Repository Repository){EA_Repository = Repository;try{EA.Collection c = Repository.Models;return true;}catch{return false;}}private bool isEA_DocGenSelected(EA.Repository Repository){EA.ObjectType objType;object obj;objType = Repository.GetTreeSelectedItem( out obj );if (objType == EA.ObjectType.otElement){if (0 == ((EA.Element)obj).Name.CompareTo(EA_Constants.EA_DocGenBaseName))return true;}return false;}private bool isPackageSelected(EA.Repository Repository, string pkgName){EA.ObjectType objType;object obj;objType = Repository.GetTreeSelectedItem( out obj );if (objType == EA.ObjectType.otPackage){if (pkgName != null){if ( 0 == ((EA.Package)obj).Name.CompareTo(pkgName) ){return true;}}else{return true;}}return false;}//Called once Menu has been opened to see what menu items are active.public void EA_GetMenuState(EA.Repository Repository, string Location, string MenuName, string ItemName, ref bool IsEnabled, ref bool IsChecked){EA_Repository = Repository;if( IsProjectOpen(Repository) ){if (ItemName == MI_AddDocumentReference){IsEnabled = isPackageSelected(Repository, "References");}else if (ItemName == MI_AddTerminologyEntry){IsEnabled = isPackageSelected(Repository, "Terminology");}else if (ItemName == MI_ModifyDocumentOptions){IsEnabled = isEA_DocGenSelected(Repository);}else if ( (MenuName == MI_UsingCopiedGUID)&& (GUID_Clipboard.objType == EA.ObjectType.otNone)){IsEnabled = false;}else if (ItemName == MI_GenDocFromModelLayout&& (threadCreateDocDialogRunning == true || threadCreateDocProcessRunning == true)){IsEnabled = false;}else{IsEnabled = true;}}else{// If no open project, disable all menu optionsIsEnabled = false;}}//Called when user makes a selection in the menu.//This is your main exit point to the rest of your Add-inpublic void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName){EA_Repository = Repository;switch( ItemName ){case MI_GenDocFromModelLayout:Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);threadCreateDoc = new Thread(new ThreadStart(EA_Utilities.createWordDoc));threadCreateDoc.ApartmentState = ApartmentState.STA;threadCreateDoc.Start();break;case MI_CopyGUIDToClipboard:EA_Utilities.copy_GUID_to_clipboard();break;case MI_AddLinkElement:EA_Utilities.AddLinkElement();break;case MI_AddNameLinkElement:EA_Utilities.AddNameLinkElement();break;case MI_AddTestLinkElement:EA_Utilities.AddTestLinkElement();break;case MI_GenPkgsFromEleList:EA_Utilities.GeneratePackagesFromElementList();break;case MI_GenSubPkgLinks:EA_Utilities.GenerateSubPackageLinks();break;case MI_GenEleLinks:EA_Utilities.GenerateElementLinks();break;case MI_AddTableElement:EA_Utilities.AddTableElement();break;case MI_AddTextElement:EA_Utilities.AddTextElement();break;case MI_AddRelMatrixElement:EA_Utilities.AddRelationshipMatrixElement();break;case MI_AddTestTraceabilityElement:EA_Utilities.AddTestTraceabilityElement();break;case MI_About:AboutForm anAbout = new AboutForm();anAbout.ShowDialog();break;case MI_AddDocumentReference:EA_Utilities.addDocumentReference();break;case MI_AddTerminologyEntry:EA_Utilities.addTerminology();break;case MI_ModifyDocumentOptions:EA_Utilities.modifyOptions();break;case MI_MarkContentWithAPIStereotype:EA_Utilities.MarkContentWithAPIStereotype();break;case MI_RemoveAPIStereotypeFromContent:EA_Utilities.RemoveAPIStereotypeFromContent();break;case MI_GenModelLayoutForDesignDoc:EA_Utilities.create_BMS00289_Layout();break;case MI_GenBasicModelLayout:EA_Utilities.create_basic_Layout();break;case MI_GenStandardViews:EA_Utilities.create_StandardView_Layout();break;case MI_ShowDiscoveryOrder:EA_Utilities.showDiscoveryOrder();break;case MI_FollowLink:EA_Utilities.followLink();break;case MI_UpdateLink:EA_Utilities.updateLink();break;case MI_IdentifyClipboardItem:EA_Utilities.identifyClipboardItem();break;}}public static void WriteOutput(string s, int id){EA_Repository.WriteOutput( GUI_OUTPUT_TAB_NAME, s, id);}public static void ShowException(Exception exc, string msg){StringBuilder sb = new StringBuilder();sb.Append(msg);sb.Append("\n\n");sb.Append(exc.ToString());Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, msg + " : " + exc.Message, -1);MessageBox.Show(sb.ToString());}}}