Subversion Repositories DevTools

Rev

Rev 2104 | Rev 2110 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2088 ghuddy 1
using System;
2
using System.Windows.Forms;
3
using System.IO;
4
using Word;
2106 ghuddy 5
using System.Threading;
2088 ghuddy 6
 
7
 
8
namespace EA_DocGen
9
{
10
	/// <summary>
11
	/// 
12
	/// </summary>
13
	public class Main
14
	{
15
      public AboutForm theForm;
16
 
2106 ghuddy 17
      // All other classes access the EA repository through this public static item
18
      public static EA.Repository EA_Repository = null;
2088 ghuddy 19
 
20
      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_DocGen";
21
 
2106 ghuddy 22
      // EA_DocGen Menu strings
2088 ghuddy 23
 
2106 ghuddy 24
      //////////////////////////////////////////////////////////////////////////////////
25
      /// The Main Menu
26
      //////////////////////////////////////////////////////////////////////////////////
27
      private const string MI_Root            = "-&EA DocGen";
2088 ghuddy 28
 
2106 ghuddy 29
      private const string MI_Separator                  = "-";
30
      private const string MI_GenDocFromModelLayout      = "&Generate Document From Model Layout";
31
      private const string MI_CopyGUIDToClipboard        = "&Copy GUID To Clipboard";
32
      private const string MI_AddTableElement            = "&Add Table Element";
33
      private const string MI_AddTextElement             = "&Add Text Element";
34
      private const string MI_AddRelMatrixElement        = "&Add RelationshipMatrix Element";
35
      private const string MI_AddTestTraceabilityElement = "&Add Test Traceability Element";
36
      private const string MI_AddDocumentReference       = "&Add Document Reference";
37
      private const string MI_AddTerminologyEntry        = "&Add Terminology Entry";
38
      private const string MI_ModifyDocumentOptions      = "&Modify EA_DocGen Options";
39
      private const string MI_GenModelLayoutForDesignDoc = "&Generate Model Layout For Design Document";
40
      private const string MI_GenBasicModelLayout        = "&Generate Basic Document Model Layout";
41
      private const string MI_About                      = "&About...";
42
 
43
      private string[] MI_RootMenu = new string[] { MI_GenDocFromModelLayout, 
44
                                                    MI_Separator,
45
                                                    MI_CopyGUIDToClipboard,
46
                                                    MI_UsingCopiedGUID, // sub-menu
47
                                                    MI_Separator,
48
                                                    MI_AddTableElement,
49
                                                    MI_AddTextElement,
50
                                                    MI_AddRelMatrixElement,
51
                                                    MI_AddTestTraceabilityElement,
52
                                                    MI_Separator,
53
                                                    MI_AddDocumentReference,
54
                                                    MI_AddTerminologyEntry,
55
                                                    MI_Separator,
56
                                                    MI_ModifyDocumentOptions,
57
                                                    MI_Separator,
58
                                                    MI_GenModelLayoutForDesignDoc,
59
                                                    MI_GenBasicModelLayout,
60
                                                    MI_Separator,
61
                                                    MI_MiscUtils,       // sub-menu
62
                                                    MI_About };
63
 
64
      //////////////////////////////////////////////////////////////////////////////////
65
      /// Using Copied GUID sub-menu
66
      //////////////////////////////////////////////////////////////////////////////////
67
      private const string MI_UsingCopiedGUID = "-&Using Copied GUID...";
68
 
69
      private const string MI_AddLinkElement     = "&Add Link Element";
70
      private const string MI_AddTestLinkElement = "&Add Test Link Element";
71
      private const string MI_AddNameLinkElement = "&Add Name Link Element";
72
      private const string MI_GenPkgsFromEleList = "&Generate Packages From Element List";
73
      private const string MI_GenSubPkgLinks     = "&Generate Sub-Package Links";
74
      private const string MI_GenEleLinks        = "&Generate Element Links";
75
 
76
      private string[] MI_UsingCopiedGUIDSubMenu = new string[] { MI_AddLinkElement,
77
                                                                  MI_AddTestLinkElement,
78
                                                                  MI_AddNameLinkElement,
79
                                                                  MI_Separator,
80
                                                                  MI_GenPkgsFromEleList,
81
                                                                  MI_GenSubPkgLinks,
82
                                                                  MI_GenEleLinks};
83
 
84
      //////////////////////////////////////////////////////////////////////////////////
85
      /// Misc Utils sub-menu
86
      //////////////////////////////////////////////////////////////////////////////////
87
      private const string MI_MiscUtils       = "-&Misc Utils";
88
 
89
      private const string MI_MarkContentWithAPIStereotype   = "&Mark Content With API Stereotype";
90
      private const string MI_RemoveAPIStereotypeFromContent = "&Remove API Stereotype From Content";
91
      private const string MI_ShowDiscoveryOrder             = "&Show Package/Element Discovery Order";
92
      private const string MI_FollowLink                     = "&Follow Link";
93
      private const string MI_UpdateLink                     = "&Update Link";
94
      private const string MI_IdentifyClipboardItem          = "&Identify Clipboard Item";
95
 
96
      private string[] MI_MiscUtilsSubMenu = new string[] { MI_MarkContentWithAPIStereotype,
97
                                                            MI_RemoveAPIStereotypeFromContent,
98
                                                            MI_Separator,
99
                                                            MI_ShowDiscoveryOrder,
100
                                                            MI_Separator,
101
                                                            MI_FollowLink,
102
                                                            MI_UpdateLink,
103
                                                            MI_Separator,
104
                                                            MI_IdentifyClipboardItem};
105
 
106
 
107
 
108
      // Thread variables so the document generation dialog can be detached from the EA thread that
109
      // is used to drive EA_DocGen via the menus
110
      private Thread threadCreateDoc = null;
111
      public static bool threadCreateDocDialogRunning = false;   // true when the docu gen dialog is being shown
112
      public static bool threadCreateDocProcessRunning = false;  // true when document generation is taking place
113
 
114
 
115
 
116
 
2088 ghuddy 117
      //Called Before EA starts to check Add-In Exists
118
      public String EA_Connect(EA.Repository Repository)
119
      {
2106 ghuddy 120
         EA_Repository = Repository;
2088 ghuddy 121
         //No special processing required.
122
         return "a string";
123
      }
124
 
125
      /// <summary>
126
      /// Called when EA initialised. Creates an output tab for the add in.
127
      /// </summary>
128
      /// <param name="repository"></param>
2106 ghuddy 129
      public void EA_OnPostInitialized(EA.Repository Repository)
2088 ghuddy 130
      {
2106 ghuddy 131
         EA_Repository = Repository;
132
         Repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);
133
         Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
2088 ghuddy 134
      }
135
 
136
 
2094 ghuddy 137
 
2088 ghuddy 138
 
139
      //Called when user Click Add-Ins Menu item from within EA.
140
      //Populates the Menu with our desired selections.
141
      public object EA_GetMenuItems(EA.Repository Repository, string Location, string MenuName)
142
      {
2106 ghuddy 143
         EA_Repository = Repository;
144
 
2088 ghuddy 145
         switch( MenuName )
146
         {
147
            case "":
2106 ghuddy 148
               return MI_Root;
2088 ghuddy 149
 
2106 ghuddy 150
            case MI_UsingCopiedGUID:
151
               return MI_UsingCopiedGUIDSubMenu;
2088 ghuddy 152
 
2106 ghuddy 153
            case MI_MiscUtils:
154
               return MI_MiscUtilsSubMenu;
2088 ghuddy 155
 
156
            case "-&EA DocGen":
2106 ghuddy 157
               return MI_RootMenu;
2088 ghuddy 158
          }
159
 
2106 ghuddy 160
         return "";
2088 ghuddy 161
      }
162
 
163
      //Sets the state of the menu depending if there is an active project or not
164
      bool IsProjectOpen(EA.Repository Repository)
165
      {
2106 ghuddy 166
         EA_Repository = Repository;
167
 
2088 ghuddy 168
         try
169
         {
170
            EA.Collection c = Repository.Models;
171
            return true;
172
         }
173
         catch
174
         {
175
            return false;
176
         }
177
      }
178
 
2094 ghuddy 179
      private bool isEA_DocGenSelected(EA.Repository Repository)
180
      {
181
         EA.ObjectType objType;
182
         object obj;
183
 
184
         objType = Repository.GetTreeSelectedItem( out obj );
185
         if (objType == EA.ObjectType.otElement)
186
         {
187
            if (0 == ((EA.Element)obj).Name.CompareTo(EA_Constants.EA_DocGenBaseName))
188
               return true;
189
         }
190
         return false;
191
      }
192
 
193
      private bool isPackageSelected(EA.Repository Repository, string pkgName)
194
      {
195
         EA.ObjectType objType;
196
         object obj;
197
 
198
         objType = Repository.GetTreeSelectedItem( out obj );
199
         if (objType == EA.ObjectType.otPackage)
200
         {
201
            if (pkgName != null)
202
            {
203
               if ( 0 == ((EA.Package)obj).Name.CompareTo(pkgName) )
204
               {
205
                  return true;
206
               }
207
            }
208
            else
209
            {
210
               return true;
211
            }
212
         }
213
         return false;                                            
214
      }
215
 
216
 
2088 ghuddy 217
      //Called once Menu has been opened to see what menu items are active.
218
      public void EA_GetMenuState(EA.Repository Repository, string Location, string MenuName, string ItemName, ref bool IsEnabled, ref bool IsChecked)
219
      {
2106 ghuddy 220
         EA_Repository = Repository;
221
 
2088 ghuddy 222
         if( IsProjectOpen(Repository) )
223
         {
2106 ghuddy 224
            if (ItemName == MI_AddDocumentReference)
2088 ghuddy 225
            {
2106 ghuddy 226
               IsEnabled = isPackageSelected(Repository, "References");
227
            }
228
            else if (ItemName == MI_AddTerminologyEntry)
229
            {
230
               IsEnabled = isPackageSelected(Repository, "Terminology");
231
            }
232
            else if (ItemName == MI_ModifyDocumentOptions)
233
            {
234
               IsEnabled = isEA_DocGenSelected(Repository);
235
            }
236
            else if (   (MenuName == MI_UsingCopiedGUID) 
237
               && (GUID_Clipboard.objType == EA.ObjectType.otNone))
238
            {
2088 ghuddy 239
               IsEnabled = false;
240
            }
2106 ghuddy 241
            else if (ItemName == MI_GenDocFromModelLayout 
242
                     && (threadCreateDocDialogRunning == true || threadCreateDocProcessRunning == true))
243
            {
244
               IsEnabled = false;
245
            }
2088 ghuddy 246
            else
247
            {
2106 ghuddy 248
               IsEnabled = true;
2088 ghuddy 249
            }
250
         }
251
         else
252
         {
253
            // If no open project, disable all menu options
254
            IsEnabled = false;
255
         }
256
      }
257
 
258
      //Called when user makes a selection in the menu.
259
      //This is your main exit point to the rest of your Add-in
260
      public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
261
      {
2106 ghuddy 262
         EA_Repository = Repository;
2088 ghuddy 263
 
264
         switch( ItemName )
265
         {
2106 ghuddy 266
            case MI_GenDocFromModelLayout:	
2104 ghuddy 267
               Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
2106 ghuddy 268
               threadCreateDoc = new Thread(new ThreadStart(EA_Utilities.createWordDoc));
269
               threadCreateDoc.ApartmentState = ApartmentState.STA;
270
               threadCreateDoc.Start();
2088 ghuddy 271
               break;
272
 
2106 ghuddy 273
            case MI_CopyGUIDToClipboard:
274
               EA_Utilities.copy_GUID_to_clipboard();
2088 ghuddy 275
               break;
276
 
2106 ghuddy 277
            case MI_AddLinkElement:
278
               EA_Utilities.AddLinkElement();
2094 ghuddy 279
               break;
2088 ghuddy 280
 
2106 ghuddy 281
            case MI_AddNameLinkElement:
282
               EA_Utilities.AddNameLinkElement();
2104 ghuddy 283
               break;
284
 
2106 ghuddy 285
            case MI_AddTestLinkElement:
286
               EA_Utilities.AddTestLinkElement();
2094 ghuddy 287
               break;
288
 
2106 ghuddy 289
            case MI_GenPkgsFromEleList:
290
               EA_Utilities.GeneratePackagesFromElementList();
2088 ghuddy 291
               break;
292
 
2106 ghuddy 293
            case MI_GenSubPkgLinks:
294
               EA_Utilities.GenerateSubPackageLinks();
2088 ghuddy 295
               break;
296
 
2106 ghuddy 297
            case MI_GenEleLinks:
298
               EA_Utilities.GenerateElementLinks();
2088 ghuddy 299
               break;
300
 
2106 ghuddy 301
            case MI_AddTableElement:
302
               EA_Utilities.AddTableElement();
2088 ghuddy 303
               break;
304
 
2106 ghuddy 305
            case MI_AddTextElement:
306
               EA_Utilities.AddTextElement();
2088 ghuddy 307
               break;
308
 
2106 ghuddy 309
            case MI_AddRelMatrixElement:
310
               EA_Utilities.AddRelationshipMatrixElement();
2088 ghuddy 311
               break;
312
 
2106 ghuddy 313
            case MI_AddTestTraceabilityElement:
314
               EA_Utilities.AddTestTraceabilityElement();
2094 ghuddy 315
               break;
316
 
2106 ghuddy 317
            case MI_About:
2088 ghuddy 318
               AboutForm anAbout = new AboutForm();
319
               anAbout.ShowDialog();
320
               break;
321
 
2106 ghuddy 322
            case MI_AddDocumentReference:
323
               EA_Utilities.addDocumentReference();
2094 ghuddy 324
               break;
325
 
2106 ghuddy 326
            case MI_AddTerminologyEntry:
327
               EA_Utilities.addTerminology();
2094 ghuddy 328
               break;
329
 
2106 ghuddy 330
            case MI_ModifyDocumentOptions:
331
               EA_Utilities.modifyOptions();
2094 ghuddy 332
               break;
333
 
2106 ghuddy 334
            case MI_MarkContentWithAPIStereotype:
335
               EA_Utilities.MarkContentWithAPIStereotype();
2104 ghuddy 336
               break;
337
 
2106 ghuddy 338
            case MI_RemoveAPIStereotypeFromContent:
339
               EA_Utilities.RemoveAPIStereotypeFromContent();
2104 ghuddy 340
               break;
341
 
2106 ghuddy 342
            case MI_GenModelLayoutForDesignDoc:
343
               EA_Utilities.create_BMS00289_Layout();
2088 ghuddy 344
               break;
345
 
2106 ghuddy 346
            case MI_GenBasicModelLayout:
347
               EA_Utilities.create_basic_Layout();
2094 ghuddy 348
               break;
349
 
2106 ghuddy 350
            case MI_ShowDiscoveryOrder:
351
               EA_Utilities.showDiscoveryOrder();
2088 ghuddy 352
               break;
353
 
2106 ghuddy 354
            case MI_FollowLink:
355
               EA_Utilities.followLink();
2088 ghuddy 356
               break;
357
 
2106 ghuddy 358
            case MI_UpdateLink:
359
               EA_Utilities.updateLink();
2088 ghuddy 360
               break;
361
 
2106 ghuddy 362
            case MI_IdentifyClipboardItem:
363
               EA_Utilities.identifyClipboardItem();
364
               break;
2088 ghuddy 365
         }
366
      }
2106 ghuddy 367
 
368
      public static void WriteOutput(string s, int id)
369
      {
370
         EA_Repository.WriteOutput( GUI_OUTPUT_TAB_NAME, s, id);
371
      }
372
 
373
 
2088 ghuddy 374
	}
375
}