Subversion Repositories DevTools

Rev

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