Subversion Repositories DevTools

Rev

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