Subversion Repositories DevTools

Rev

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