Subversion Repositories DevTools

Rev

Rev 2104 | Rev 2108 | 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.Collections;
4
using System.IO;
2104 ghuddy 5
using System.Text;
2088 ghuddy 6
using Word;
7
 
8
namespace EA_DocGen
9
{
10
   /// <summary>
11
   /// A Base Class designed to work with the findAndProcessPackageElements method.
12
   /// Users will normally derive their own classes from this and add real functionality
13
   /// to the over-ridable methods the base class provides.
14
   /// </summary>
15
   public class EA_UtilitiesRecursionWorker
16
   {
17
      public EA_UtilitiesRecursionWorker()
18
      {
19
      }
20
 
21
      public virtual void processElement( EA.Element theElement )
22
      {
23
      }
24
      public virtual void processPackage( EA.Package thePackage )
25
      {
26
      }
27
   }
28
 
2094 ghuddy 29
 
30
 
2088 ghuddy 31
	/// <summary>
32
	/// Class containing functions that implement the EA_DocGen menu items.
33
	/// </summary>
34
	public class EA_Utilities
35
	{
2106 ghuddy 36
      // data used by followLink() to roll around multiple GUIDs contained in the link
37
      static int lastLinkID = -1;
38
      static int nextGuidIndex = 0;
2088 ghuddy 39
 
40
 
41
 
42
      // Operations
43
 
2106 ghuddy 44
      public static void identifyClipboardItem()
45
      {
46
         object o = null;
2088 ghuddy 47
 
2106 ghuddy 48
         Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
49
         Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "", -1);
50
         Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Name : " + GUID_Clipboard.name, -1);
51
         Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "GUID : " + GUID_Clipboard.guid, -1);
52
         if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
53
         {
54
            Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Type : Package", -1);
55
            o = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
56
         }
57
         else if (GUID_Clipboard.objType == EA.ObjectType.otElement)
58
         {
59
            Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Type : Element", -1);
60
            o = Main.EA_Repository.GetElementByGuid(GUID_Clipboard.guid);
61
         }
62
         else if (GUID_Clipboard.objType == EA.ObjectType.otDiagram)
63
         {
64
            Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Type : Diagram", -1);
65
            o = Main.EA_Repository.GetDiagramByGuid(GUID_Clipboard.guid);
66
         }
67
         if (o != null)
68
         {
69
            Main.EA_Repository.ShowInProjectView(o);
70
         }
71
      }
2088 ghuddy 72
 
2106 ghuddy 73
      public static void updateLink()
74
      {
75
         EA.ObjectType objType;
76
         object obj;
2094 ghuddy 77
 
2106 ghuddy 78
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
79
         if (objType == EA.ObjectType.otElement)
80
         {
81
            EA.Element ele = (EA.Element)obj;
2094 ghuddy 82
 
2106 ghuddy 83
            if (ele.Name.StartsWith(EA_Constants.EA_DocGenBaseName)
84
               && ele.Name.IndexOf("Link") > 0)
85
            {
86
               char[] sep = new char[] {'\r', '\n'};
87
               string[] strings = ele.Notes.Split(sep, 50);
88
               foreach(string s in strings)
89
               {
90
                  if (s.Length > 0 && s[0] == '{')
91
                  {
92
                     if (ele.Name.StartsWith(EA_Constants.EA_DocGenDiagramLink))
93
                     {
94
                        EA.Diagram diag = (EA.Diagram)Main.EA_Repository.GetDiagramByGuid(s);
95
                        if (diag != null)
96
                        {
97
                           ele.Name = EA_Constants.EA_DocGenDiagramLink + " - " + GetPackagePath(diag.PackageID, diag.Name);
98
                           ele.Update();
99
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
100
                           Main.EA_Repository.ShowInProjectView(ele);
101
                           return;
102
                        }
103
                     }
104
                     else if (ele.Name.StartsWith(EA_Constants.EA_DocGenElementLink))
105
                     {
106
                        EA.Element e = (EA.Element)Main.EA_Repository.GetElementByGuid(s);
107
                        if (e != null)
108
                        {
109
                           ele.Name = EA_Constants.EA_DocGenElementLink + " - " + GetPackagePath(e.PackageID, e.Name);
110
                           ele.Update();
111
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
112
                           Main.EA_Repository.ShowInProjectView(ele);
113
                           return;
114
                        }
115
                     }
116
                     else if (ele.Name.StartsWith(EA_Constants.EA_DocGenPackageLink))
117
                     {
118
                        EA.Package p = (EA.Package)Main.EA_Repository.GetPackageByGuid(s);
119
                        if (p != null)
120
                        {
121
                           ele.Name = EA_Constants.EA_DocGenPackageLink + " - " + GetPackagePath(p.PackageID, p.Name);
122
                           ele.Update();
123
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
124
                           Main.EA_Repository.ShowInProjectView(ele);
125
                           return;
126
                        }
127
                     }
128
                     else if (ele.Name.StartsWith(EA_Constants.EA_DocGenNameLink))
129
                     {
130
                        EA.Package p = (EA.Package)Main.EA_Repository.GetPackageByGuid(s);
131
                        if (p != null)
132
                        {
133
                           ele.Name = EA_Constants.EA_DocGenNameLink + " - " + GetPackagePath(p.PackageID, p.Name);
134
                           ele.Update();
135
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
136
                           Main.EA_Repository.ShowInProjectView(ele);
137
                           return;
138
                        }
139
                     }
140
                     return;
141
                  }
142
               }
143
               MessageBox.Show("Unable to find link GUID");
144
               return;
145
            }
146
         }
147
         MessageBox.Show("You must select an EA_DocGen link element");
148
      }
149
 
150
      public static void followLink()
2088 ghuddy 151
      {
2106 ghuddy 152
         EA.ObjectType objType;
153
         object obj;
154
 
155
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
156
         if (objType == EA.ObjectType.otElement)
157
         {
158
            EA.Element ele = (EA.Element)obj;
159
 
160
            if (ele.Name.StartsWith(EA_Constants.EA_DocGenBaseName)
161
               && ele.Name.IndexOf("Link") > 0)
162
            {
163
 
164
               if (ele.ElementID != lastLinkID)
165
               {
166
                  nextGuidIndex = 0;
167
               }
168
 
169
               char[] sep = new char[] {'\r', '\n'};
170
               string[] strings = ele.Notes.Split(sep, 50);
171
               int thisGUIDIndex = 0;
172
               for(int i=0; i < 2; i++)
173
               {
174
                  foreach(string s in strings)
175
                  {
176
                     if (s.Length > 0 && s[0] == '{')
177
                     {
178
                        if (thisGUIDIndex < nextGuidIndex)
179
                        {
180
                           thisGUIDIndex++;
181
                           continue;
182
                        }
183
 
184
                        object o = null;
185
                        if (ele.Name.StartsWith(EA_Constants.EA_DocGenDiagramLink))
186
                        {
187
                           o = Main.EA_Repository.GetDiagramByGuid(s);
188
                        }
189
                        else if (ele.Name.StartsWith(EA_Constants.EA_DocGenElementLink))
190
                        {
191
                           o = Main.EA_Repository.GetElementByGuid(s);
192
                        }
193
                        else if (ele.Name.StartsWith(EA_Constants.EA_DocGenPackageLink))
194
                        {
195
                           o = Main.EA_Repository.GetPackageByGuid(s);
196
                        }
197
                        else if (ele.Name.StartsWith(EA_Constants.EA_DocGenNameLink))
198
                        {
199
                           o = Main.EA_Repository.GetPackageByGuid(s);
200
                        }
201
                        if (o != null)
202
                        {
203
                           Main.EA_Repository.ShowInProjectView(o);
204
                           lastLinkID = ele.ElementID;
205
                           nextGuidIndex++;
206
                        }
207
                        else
208
                        {
209
                           MessageBox.Show("Unable to resolve link\r\n" + s);
210
                        }
211
                        return;
212
                     }
213
                  }
214
                  if (nextGuidIndex > 0)
215
                  {
216
                     nextGuidIndex = 0;
217
                  }
218
                  else
219
                  {
220
                     break;
221
                  }
222
               }
223
               MessageBox.Show("Unable to find link GUID");
224
               return;
225
            }
226
         }
227
         MessageBox.Show("You must select an EA_DocGen link element");
2088 ghuddy 228
      }
229
 
2104 ghuddy 230
 
2106 ghuddy 231
      public static void modifyOptions()
2094 ghuddy 232
      {
233
         EA.ObjectType objType;
234
         object obj;
2088 ghuddy 235
 
2106 ghuddy 236
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 237
         if (objType == EA.ObjectType.otElement)
238
         {
239
            EA.Element ele = (EA.Element)obj;
2088 ghuddy 240
 
2094 ghuddy 241
            if (0 == ele.Name.CompareTo(EA_Constants.EA_DocGenBaseName))
242
            {
2106 ghuddy 243
               if (true == EA_DocGenOptions.lookForAndProcess_EA_DocGen_Element( ele ))
2094 ghuddy 244
               {
245
                  EA_DocGenOptionsForm dlg = new EA_DocGenOptionsForm();
2106 ghuddy 246
                  dlg.populate();
2094 ghuddy 247
                  DialogResult dlgRes = dlg.ShowDialog();
248
                  if (dlgRes == DialogResult.OK)
249
                  {
2106 ghuddy 250
                     dlg.read();
2088 ghuddy 251
 
2106 ghuddy 252
                     EA_DocGenOptions.updateEA_DocGen(ele);
2094 ghuddy 253
                  }
254
               }
255
            }
256
         }
257
      }
258
 
2104 ghuddy 259
 
2088 ghuddy 260
      /// <summary>
261
      /// Begins the document generation process, opening the dialog to capture input/output
262
      /// files. the createWordDoc dialog class does most of the work ofcoarse.
263
      /// </summary>
2106 ghuddy 264
      public static void createWordDoc()
2088 ghuddy 265
      {
2106 ghuddy 266
         Main.threadCreateDocDialogRunning = true;
2088 ghuddy 267
 
2106 ghuddy 268
         try
2088 ghuddy 269
         {
2106 ghuddy 270
            EA.ObjectType objType;
271
            object obj;
272
 
273
            objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
274
            if (objType == EA.ObjectType.otPackage)
2088 ghuddy 275
            {
2106 ghuddy 276
               EA_DocGenOptions.initialise();
277
 
278
               // Make sure this package has an EA_DocGen element
279
               if (true == EA_DocGenOptions.lookForAndProcess_EA_DocGen_Element( ((EA.Package)obj) ))
280
               {
281
                  // bring up the dialog for doc generation
282
                  createWordDoc dialog = new createWordDoc(((EA.Package)obj));
283
                  dialog.Text = "Generate Document From Model Layout";
284
                  dialog.textBox_template.Text    = ReadTag((EA.Package)obj, "TEMPLATE");
285
                  dialog.textBox_output_file.Text = ReadTag((EA.Package)obj, "DOCFILE");
286
                  dialog.ShowDialog();
287
                  WriteTag((EA.Package)obj, "TEMPLATE", dialog.textBox_template.Text); 
288
                  WriteTag((EA.Package)obj, "DOCFILE",  dialog.textBox_output_file.Text);
289
               }
290
               else
291
               {
292
                  MessageBox.Show("EA_DocGen document model packages must contain an EA_DocGen element");
293
               }
2094 ghuddy 294
            }
2088 ghuddy 295
            else
296
            {
2106 ghuddy 297
               MessageBox.Show("You must select a package whose content is to be formed into a document");
2088 ghuddy 298
            }
299
         }
2106 ghuddy 300
         catch(Exception e)
2088 ghuddy 301
         {
2106 ghuddy 302
            MessageBox.Show(e.Message);
2094 ghuddy 303
         }
2106 ghuddy 304
         Main.threadCreateDocDialogRunning = false;
2088 ghuddy 305
      }
306
 
307
 
308
      /// <summary>
309
      /// Creates a package under the specified parent package. the package is given a tree position
310
      /// as specified in order for it to be ordered in the model as the caller requires.
311
      /// </summary>
312
      /// <param name="parentPackage"></param>
313
      /// <param name="name"></param>
314
      /// <param name="treePos"></param>
315
      /// <returns></returns>
2106 ghuddy 316
      public static EA.Package createPackage(EA.Package parentPackage, string name, int treePos)
2088 ghuddy 317
      {
318
         EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");
319
         newobj.TreePos = treePos;
320
         newobj.Update();
321
         return newobj;
322
      }
323
 
2094 ghuddy 324
 
2088 ghuddy 325
      /// <summary>
326
      /// Generate a package hierarchy that reflects the document layout of BMS-00289, the
327
      /// ERG Product Software Design Document.
328
      /// </summary>
2106 ghuddy 329
      public static void create_BMS00289_Layout()
2088 ghuddy 330
      {
331
         EA.ObjectType objType;
332
         object obj;
333
 
2106 ghuddy 334
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 335
         if (objType == EA.ObjectType.otPackage)
336
         {
2094 ghuddy 337
            if (  ((EA.Package)obj).Packages.Count == 0
2088 ghuddy 338
               && ((EA.Package)obj).Elements.Count == 0
339
               && ((EA.Package)obj).Diagrams.Count == 0 )
340
            {
341
               EA.Package parentPackage = ((EA.Package)obj);
342
 
343
               EA.Package newobj = null;
344
               EA.Package newobj2 = null;
345
               EA.Package newobj3 = null;
346
               EA.Package newobj4 = null;
347
               EA.Package newobj5 = null;
348
 
349
               newobj  = createPackage(parentPackage, "Introduction", 1);
350
               newobj2 = createPackage(newobj, "Purpose", 1);
351
               newobj2 = createPackage(newobj, "Scope", 2);
352
               newobj2 = createPackage(newobj, "Terminology", 3);
353
               newobj2 = createPackage(newobj, "References", 4);
354
 
355
               newobj  = createPackage(parentPackage, "Design Assumptions And Constraints", 2);
356
 
357
               newobj  = createPackage(parentPackage, "System Overview", 3);
358
 
359
               newobj  = createPackage(parentPackage, "High Level Design", 4);
360
               newobj2 = createPackage(newobj, "Software Architecture", 1);
361
               newobj2 = createPackage(newobj, "External Interfaces", 2);
362
               newobj2 = createPackage(newobj, "Internal Interfaces", 3);
363
               newobj2 = createPackage(newobj, "Memory And Processing Time Allocation", 4);
364
               newobj2 = createPackage(newobj, "Operational Modes", 5);
365
               newobj2 = createPackage(newobj, "Component Descriptions", 6);
366
 
367
               newobj = createPackage(parentPackage, "Detailed Design", 5);
368
 
369
               newobj = createPackage(parentPackage, "Unit Test Design",6);
370
 
371
               newobj2 = createPackage(newobj, "Test Data", 1);
372
               newobj2 = createPackage(newobj, "Test Stubs", 2);
373
               newobj2 = createPackage(newobj, "Other Elements", 3);
374
               newobj2 = createPackage(newobj, "Unit Test Traceability To Design", 4);
375
               newobj2 = createPackage(newobj, "Test Suites and Test Cases", 5);
376
               newobj3 = createPackage(newobj2, "Test Suite Name", 1);
377
               newobj4 = createPackage(newobj3, "Test Name", 1);
378
               newobj5 = createPackage(newobj4, "Description", 1);
379
               newobj5 = createPackage(newobj4, "Inputs", 2);
380
               newobj5 = createPackage(newobj4, "Expected Outputs", 3);
381
 
382
               newobj = createPackage(parentPackage, "Requirements Traceability", 7);
383
 
384
               // create an EA_DocGen element
385
               EA.Element newElement = (EA.Element)parentPackage.Elements.AddNew( "EA_DocGen", "InformationItem" );
2094 ghuddy 386
               newElement.Notes = "[ElementTypes]\r\nRequirement\r\nClass\r\nComponent\r\n";
2088 ghuddy 387
               newElement.Update();
388
 
389
               parentPackage.Packages.Refresh();
390
 
391
               // refresh project browser view
2106 ghuddy 392
               Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
2088 ghuddy 393
            }
394
            else
395
            {
396
               MessageBox.Show("Can only insert layout into an empty package");
397
            }
398
         }
399
         else
400
         {
401
            MessageBox.Show("You must select a package into which the layout will be inserted");
402
         }
403
      }
404
 
405
 
406
      /// <summary>
2094 ghuddy 407
      /// Generate a package hierarchy that reflects a basic document layout.
408
      /// </summary>
2106 ghuddy 409
      public static void create_basic_Layout()
2094 ghuddy 410
      {
411
         EA.ObjectType objType;
412
         object obj;
413
 
2106 ghuddy 414
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 415
         if (objType == EA.ObjectType.otPackage)
416
         {
417
            if (  ((EA.Package)obj).Packages.Count == 0
418
               && ((EA.Package)obj).Elements.Count == 0
419
               && ((EA.Package)obj).Diagrams.Count == 0 )
420
            {
421
               EA.Package parentPackage = ((EA.Package)obj);
422
 
423
               EA.Package newobj = null;
424
               EA.Package newobj2 = null;
425
               //EA.Package newobj3 = null;
426
               //EA.Package newobj4 = null;
427
               //EA.Package newobj5 = null;
428
 
429
               newobj  = createPackage(parentPackage, "Introduction", 1);
430
               newobj2 = createPackage(newobj, "Purpose", 1);
431
               newobj2 = createPackage(newobj, "Scope", 2);
432
               newobj2 = createPackage(newobj, "Terminology", 3);
433
               newobj2 = createPackage(newobj, "References", 4);
434
 
435
               newobj  = createPackage(parentPackage, "Section 2 (rename me as required)", 2);
436
 
437
               newobj  = createPackage(parentPackage, "Section 3 (rename me as required)", 3);
438
 
439
               // create an EA_DocGen element
440
               EA.Element newElement = (EA.Element)parentPackage.Elements.AddNew( EA_Constants.EA_DocGenBaseName,
441
                                                                                  EA_Constants.EA_DocGenElementType );
442
               newElement.Notes = "[ElementTypes]\r\nRequirement\r\nClass\r\nComponent\r\n";
443
               newElement.Update();
444
 
445
               parentPackage.Packages.Refresh();
446
 
447
               // refresh project browser view
2106 ghuddy 448
               Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
2094 ghuddy 449
            }
450
            else
451
            {
452
               MessageBox.Show("Can only insert layout into an empty package");
453
            }
454
         }
455
         else
456
         {
457
            MessageBox.Show("You must select a package into which the layout will be inserted");
458
         }
459
      }
460
 
461
 
462
      /// <summary>
2088 ghuddy 463
      /// This function works its way up the parental hierarchy to the root model, collecting the
2094 ghuddy 464
      /// strings names of each package and prepending them to a string accumulator with a view to
2088 ghuddy 465
      /// obtaing the full path of an element,diagram, or package.
466
      /// </summary>
467
      /// <param name="parentId"></param>
468
      /// <param name="instr"></param>
469
      /// <returns></returns>
2106 ghuddy 470
      public static string GetPackagePath( int parentId, string instr )
2088 ghuddy 471
      {
472
         if (parentId != 0)
473
         {
474
            EA.Package pkg;
2106 ghuddy 475
            pkg = Main.EA_Repository.GetPackageByID( parentId );
2088 ghuddy 476
            if (pkg != null)
477
            {
478
               instr = pkg.Name + "/" + instr;
479
               instr = GetPackagePath(pkg.ParentID, instr);
2094 ghuddy 480
            }
2088 ghuddy 481
         }
482
         return instr;
483
      }
484
 
485
 
2106 ghuddy 486
      private static void copy_GUID_to_clipboard(object obj, EA.ObjectType objType, bool confirm)
2088 ghuddy 487
      {
2106 ghuddy 488
         GUID_Clipboard.copy(obj, objType, confirm);
2088 ghuddy 489
      }
490
 
2094 ghuddy 491
 
2088 ghuddy 492
      /// <summary>
2094 ghuddy 493
      /// For the selected item, copy its GUID to the internal add-in GUID clipboard and the
2088 ghuddy 494
      /// global external clipboard. Also copy to the internal add-in GUID clipboard, the name of
495
      /// the element and its type. This will support the AddLinkElement() method.
496
      /// </summary>
2106 ghuddy 497
      public static void copy_GUID_to_clipboard()
2088 ghuddy 498
      {
499
         EA.ObjectType objType;
500
         object obj;
2106 ghuddy 501
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
502
         GUID_Clipboard.copy(obj, objType, true);
2088 ghuddy 503
      }
504
 
505
 
2106 ghuddy 506
      public static void AddTestTraceabilityElement()
2094 ghuddy 507
      {
508
         EA.ObjectType objType;
509
         object obj;
2106 ghuddy 510
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 511
         AddTestTraceabilityElement(obj, objType);
512
      }
2106 ghuddy 513
      public static void AddTestTraceabilityElement(object obj, EA.ObjectType objType)
2094 ghuddy 514
      {
515
         if (objType == EA.ObjectType.otPackage)
516
         {
517
            object newobj = null;
2088 ghuddy 518
 
2094 ghuddy 519
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestTraceability, EA_Constants.EA_DocGenElementType);
520
            if (newobj != null)
521
            {
522
               ((EA.Element)newobj).Update();
523
            }         
524
         }
525
         else
526
         {
527
            MessageBox.Show("You must select a package into which the element will be inserted");
528
         }
529
      }
530
 
2104 ghuddy 531
 
2094 ghuddy 532
      /// <summary>
533
      /// Using the internal add-in GUID clipboard, paste a test link element into the selected
534
      /// package.
535
      /// </summary>
2106 ghuddy 536
      public static void AddTestLinkElement()
2094 ghuddy 537
      {
538
         EA.ObjectType objType;
539
         object obj;
2106 ghuddy 540
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 541
         AddTestLinkElement(obj, objType);
542
      }
543
 
2106 ghuddy 544
      private static void AddTestLinkElement(object obj, EA.ObjectType objType)
2094 ghuddy 545
      {
546
         if (objType == EA.ObjectType.otPackage)
547
         {
548
            object newobj = null;
549
 
2106 ghuddy 550
            if (   GUID_Clipboard.objType == EA.ObjectType.otElement
551
                || GUID_Clipboard.objType == EA.ObjectType.otPackage)
2094 ghuddy 552
            {
2106 ghuddy 553
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2094 ghuddy 554
 
555
               if (newobj != null)
556
               {
2106 ghuddy 557
                  ((EA.Element)newobj).Notes = GUID_Clipboard.name + "\r\n" + GUID_Clipboard.guid;
2094 ghuddy 558
                  ((EA.Element)newobj).Update();
559
               }
560
            }
561
            else
562
            {
563
               MessageBox.Show("The GUID clipboard must first contain the GUID of an element (normally, a class), or a package");
564
            }
565
         }
566
         else
567
         {
568
            MessageBox.Show("You must select a package into which the test link will be inserted");
569
         }
570
      }
571
 
572
 
573
      /// <summary>
574
      /// Using the internal add-in GUID clipboard, paste a link element into the selected
575
      /// package.
576
      /// </summary>
2106 ghuddy 577
      public static void AddLinkElement()
2094 ghuddy 578
      {
579
         EA.ObjectType objType;
580
         object obj;
2106 ghuddy 581
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 582
         AddLinkElement(obj, objType);
583
      }
584
 
2106 ghuddy 585
      private static void AddLinkElement(object obj, EA.ObjectType objType)
2088 ghuddy 586
      {
587
         if (objType == EA.ObjectType.otPackage)
588
         {
589
            object newobj = null;
590
 
2106 ghuddy 591
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 592
            {
2106 ghuddy 593
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenPackageLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 594
            }
2106 ghuddy 595
            else if (GUID_Clipboard.objType == EA.ObjectType.otDiagram)
2088 ghuddy 596
            {
2106 ghuddy 597
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenDiagramLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 598
            }
2106 ghuddy 599
            else if (GUID_Clipboard.objType == EA.ObjectType.otElement)
2088 ghuddy 600
            {
2106 ghuddy 601
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenElementLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 602
            }
2106 ghuddy 603
            else if (GUID_Clipboard.objType == EA.ObjectType.otAttribute)
2088 ghuddy 604
            {
605
               MessageBox.Show("Attribute links are not currently supported");
606
            }
2106 ghuddy 607
            else if (GUID_Clipboard.objType == EA.ObjectType.otMethod)
2088 ghuddy 608
            {
609
               MessageBox.Show("Method links are not currently supported");
610
            }
611
 
612
            if (newobj != null)
613
            {
2106 ghuddy 614
               ((EA.Element)newobj).Notes = GUID_Clipboard.name + "\r\n" + GUID_Clipboard.guid;
2088 ghuddy 615
               ((EA.Element)newobj).Update();
616
            }
617
         }
618
         else
619
         {
620
            MessageBox.Show("You must select a package into which the link will be inserted");
2094 ghuddy 621
         }
2088 ghuddy 622
      }
623
 
2094 ghuddy 624
 
2106 ghuddy 625
      public static void AddNameLinkElement()
2104 ghuddy 626
      {
627
         EA.ObjectType objType;
628
         object obj;
2106 ghuddy 629
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 630
         AddNameLinkElement(obj, objType);
631
      }
632
 
2106 ghuddy 633
      private static void AddNameLinkElement(object obj, EA.ObjectType objType)
2104 ghuddy 634
      {
635
         if (objType == EA.ObjectType.otPackage)
636
         {
637
            object newobj = null;
638
 
2106 ghuddy 639
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2104 ghuddy 640
            {
2106 ghuddy 641
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenNameLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2104 ghuddy 642
               if (newobj != null)
643
               {
644
                  StringBuilder sb = new StringBuilder();
2106 ghuddy 645
                  sb.Append(GUID_Clipboard.name);
2104 ghuddy 646
                  sb.Append("\r\n");
2106 ghuddy 647
                  sb.Append(GUID_Clipboard.guid);
2104 ghuddy 648
                  sb.Append("\r\n");
649
                  sb.Append("### Add as many package names as you like below here.\r\n");
650
                  sb.Append("### Each should be of the form: package=name\r\n");
651
                  sb.Append("### Delete any unused package= lines from these notes.\r\n");
652
                  sb.Append("### The names are case sensitive and must match exactly\r\n");
653
                  sb.Append("### the names of the packages you wish to pull in to the\r\n");
654
                  sb.Append("### document model.\r\n");
655
                  sb.Append("package=\r\n");
656
                  sb.Append("package=\r\n");
657
                  sb.Append("package=\r\n");
658
 
659
                  ((EA.Element)newobj).Notes = sb.ToString();
660
                  ((EA.Element)newobj).Update();
661
               }            
662
            }
663
         }
664
         else
665
         {
666
            MessageBox.Show("You must select a package into which the name link will be inserted");
667
         }
668
      }
669
 
670
 
2106 ghuddy 671
      public static void AddTableElement()
2088 ghuddy 672
      {
673
         EA.ObjectType objType;
674
         object obj;
675
 
2106 ghuddy 676
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 677
         if (objType == EA.ObjectType.otPackage)
678
         {
679
            object newobj = null;
2088 ghuddy 680
 
2094 ghuddy 681
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTable, EA_Constants.EA_DocGenElementType);
682
            if (newobj != null)
683
            {
684
               ((EA.Element)newobj).Notes = "title=insertYourTitleHere\r\n"
685
                                          + "columns=2\r\n"
686
                                          + "seperator=,\r\n"
2104 ghuddy 687
                                          + "indent=1\r\n"
688
                                          + "widths=column1Width,column2Width\r\n"
2094 ghuddy 689
                                          + "column1Title,column2Title\r\n"
690
                                          + "cellcontent,cellcontent\r\n"
2104 ghuddy 691
                                          + "cellcontent,cellcontent\r\n"
692
                                          + "cellcontent,cellcontent\r\n"
2094 ghuddy 693
                                          + "etc,etc";
694
               ((EA.Element)newobj).Update();
695
            }
696
         }
697
         else
698
         {
699
            MessageBox.Show("You must select a package into which the Table Element will be inserted");
700
         }
2088 ghuddy 701
      }
702
 
703
 
2106 ghuddy 704
      public static void AddTextElement()
2094 ghuddy 705
      {
706
         EA.ObjectType objType;
707
         object obj;
708
 
2106 ghuddy 709
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 710
         if (objType == EA.ObjectType.otPackage)
711
         {
712
            object newobj = null;
713
 
714
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenText, EA_Constants.EA_DocGenElementType);
715
            if (newobj != null)
716
            {
717
               ((EA.Element)newobj).Notes = "Add your text here.";
718
               ((EA.Element)newobj).Update();
719
            }
720
         }
721
         else
722
         {
723
            MessageBox.Show("You must select a package into which the Text Element will be inserted");
724
         }
725
      }
726
 
727
 
2106 ghuddy 728
      public static void AddRelationshipMatrixElement()
2094 ghuddy 729
      {
730
         EA.ObjectType objType;
731
         object obj;
732
 
2106 ghuddy 733
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 734
         if (objType == EA.ObjectType.otPackage)
735
         {
2104 ghuddy 736
            RelationshipMatrixType dlg = new RelationshipMatrixType();
737
            DialogResult dlgRes = dlg.ShowDialog();
738
            if (dlgRes == DialogResult.OK)
2094 ghuddy 739
            {
2104 ghuddy 740
               object newobj = null;
741
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenRelationshipMatrix, EA_Constants.EA_DocGenElementType);
742
               if (newobj != null)
743
               {
744
                  ((EA.Element)newobj).Notes  = EA_RelationshipMatrix.optionTemplateForRelationshipMatrix(dlg.style());
745
                  ((EA.Element)newobj).Update();
746
               }
2094 ghuddy 747
            }
748
         }
749
         else
750
         {
751
            MessageBox.Show("You must select a package into which the RelationshipMatrix Element will be inserted");
752
         }
753
      }
754
 
755
 
2106 ghuddy 756
      public static void GeneratePackagesFromElementList()
2088 ghuddy 757
      {
758
         EA.ObjectType objType;
759
         object obj;
760
 
2106 ghuddy 761
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 762
         if (objType == EA.ObjectType.otPackage)
763
         {
2106 ghuddy 764
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 765
            {
2106 ghuddy 766
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 767
               if (theFoundPackage != null)
768
               {
769
                  EA.Package srcPackage = theFoundPackage;
770
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 771
 
2088 ghuddy 772
                  foreach( EA.Element srcElement in srcPackage.Elements)
773
                  {
2106 ghuddy 774
                     if (false == EA_Finders.elementNameExistsInPackage(destPackage, srcElement.Name.ToString()))
2088 ghuddy 775
                     {
776
                        createPackage(destPackage, srcElement.Name.ToString(), 1);
777
                     }
778
                  }
2094 ghuddy 779
               }
2088 ghuddy 780
            }
781
            else
782
            {
783
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
784
            }
785
         }
786
         else
787
         {
788
            MessageBox.Show("You must select a Destination Package into which the Generated Packages will be inserted");
789
         }
790
      }
791
 
792
 
2106 ghuddy 793
      public static void GenerateSubPackageLinks()
2088 ghuddy 794
      {
795
         EA.ObjectType objType;
796
         object obj;
797
 
2106 ghuddy 798
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 799
         if (objType == EA.ObjectType.otPackage)
800
         {
2106 ghuddy 801
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 802
            {
2106 ghuddy 803
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 804
               if (theFoundPackage != null)
805
               {
806
                  EA.Package srcPackage = theFoundPackage;
807
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 808
 
2106 ghuddy 809
                  GUID_Clipboard.push();
810
 
2088 ghuddy 811
                  foreach( EA.Package subPackage in srcPackage.Packages)
812
                  {
813
                     copy_GUID_to_clipboard( (object)subPackage, EA.ObjectType.otPackage, false);
814
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
815
                  }
2106 ghuddy 816
 
817
                  GUID_Clipboard.pop();
2094 ghuddy 818
               }
2088 ghuddy 819
            }
820
            else
821
            {
822
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
823
            }
824
         }
825
         else
826
         {
827
            MessageBox.Show("You must select a Destination Package into which the Sub-Package Links will be inserted");
828
         }
829
      }
830
 
831
 
2106 ghuddy 832
      public static void GenerateElementLinks()
2088 ghuddy 833
      {
834
         EA.ObjectType objType;
835
         object obj;
836
 
2106 ghuddy 837
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 838
         if (objType == EA.ObjectType.otPackage)
839
         {
2106 ghuddy 840
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 841
            {
2106 ghuddy 842
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 843
               if (theFoundPackage != null)
844
               {
845
                  EA.Package srcPackage = theFoundPackage;
846
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 847
 
2106 ghuddy 848
                  GUID_Clipboard.push();
849
 
2088 ghuddy 850
                  foreach( EA.Element subElement in srcPackage.Elements)
851
                  {
852
                     copy_GUID_to_clipboard( (object)subElement, EA.ObjectType.otElement, false);
853
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
854
                  }
2106 ghuddy 855
 
856
                  GUID_Clipboard.pop();
2094 ghuddy 857
               }
2088 ghuddy 858
            }
859
            else
860
            {
861
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
862
            }
863
         }
864
         else
865
         {
866
            MessageBox.Show("You must select a Destination Package into which the Element Links will be inserted");
2094 ghuddy 867
         }
2088 ghuddy 868
      }
869
 
2094 ghuddy 870
      /// <summary>
871
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
872
      /// a user to specify what processing is to be done upon or with each element found.
873
      /// </summary>
874
      /// <param name="thePackage"></param>
875
      /// <param name="worker"></param>
876
      /// <param name="recurse"></param>
2106 ghuddy 877
      public static void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
2088 ghuddy 878
      {
2094 ghuddy 879
         worker.processPackage( thePackage );
2088 ghuddy 880
 
2094 ghuddy 881
         foreach (EA.Element theElement in thePackage.Elements)
2088 ghuddy 882
         {
2094 ghuddy 883
            worker.processElement( theElement );
884
         }
2088 ghuddy 885
 
2094 ghuddy 886
         if (recurse == true)
887
         {
888
            foreach (EA.Package subPackage in thePackage.Packages)
2088 ghuddy 889
            {
2094 ghuddy 890
               // RECURSION
891
               findAndProcessPackageElements( subPackage, worker, true);
2088 ghuddy 892
            }
893
         }
2094 ghuddy 894
 
2088 ghuddy 895
      }
896
 
2094 ghuddy 897
 
2106 ghuddy 898
      public static void addDocumentReference()
2088 ghuddy 899
      {
900
         EA.ObjectType objType;
901
         object obj;
902
 
2106 ghuddy 903
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 904
         if (objType == EA.ObjectType.otPackage)
905
         {
2094 ghuddy 906
            DocReferenceForm dlg = new DocReferenceForm();
907
            DialogResult dlgRes = dlg.ShowDialog();
908
            if (dlgRes == DialogResult.OK)
909
            {
910
               object newobj = null;
2088 ghuddy 911
 
2094 ghuddy 912
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_DocNumber.Text, EA_Constants.EA_DocGenElementType);
913
               if (newobj != null)
914
               {
915
                  ((EA.Element)newobj).Notes = dlg.textBox_DocName.Text;
916
                  ((EA.Element)newobj).Update();
917
               }
2088 ghuddy 918
            }
919
         }
920
      }
921
 
2094 ghuddy 922
 
2106 ghuddy 923
      public static void addTerminology()
2088 ghuddy 924
      {
925
         EA.ObjectType objType;
926
         object obj;
927
 
2106 ghuddy 928
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 929
         if (objType == EA.ObjectType.otPackage)
930
         {
2094 ghuddy 931
            TerminologyForm dlg = new TerminologyForm();
932
            DialogResult dlgRes = dlg.ShowDialog();
933
            if (dlgRes == DialogResult.OK)
934
            {
935
               object newobj = null;
2088 ghuddy 936
 
2094 ghuddy 937
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_Term.Text, EA_Constants.EA_DocGenElementType);
938
               if (newobj != null)
939
               {
940
                  ((EA.Element)newobj).Notes = dlg.textBox_TermExpansion.Text;
941
                  ((EA.Element)newobj).Update();
942
               }
2088 ghuddy 943
            }
944
         }
945
      }
946
 
947
 
2106 ghuddy 948
      public static string ReadTag(EA.Package thePackage, string tagName)
2098 ghuddy 949
      {
2106 ghuddy 950
         EA.Element theElement = Main.EA_Repository.GetElementByGuid(thePackage.PackageGUID);
951
         if (theElement != null)
952
         {
953
            return ReadTag(theElement, tagName);
954
         }
955
         return "";
956
      }
957
 
958
      public static string ReadTag(EA.Element theElement, string tagName)
959
      {
2098 ghuddy 960
         string result;
961
 
962
         EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
963
         if (null != tag)
964
         {
965
            result = tag.Value;
966
         }
967
         else
968
         {
969
            result = "";
970
         }
971
         return result;
972
      }
973
 
2106 ghuddy 974
      public static bool WriteTag(EA.Package thePackage, string tagName, string value)
975
      {
976
         EA.Element theElement = Main.EA_Repository.GetElementByGuid(thePackage.PackageGUID);
977
         if (theElement != null)
978
         {
979
            return WriteTag(theElement, tagName, value);
980
         }
981
         return false;
982
      }
2098 ghuddy 983
 
2106 ghuddy 984
      public static bool WriteTag(EA.Element theElement, string tagName, string value)
2098 ghuddy 985
      {
986
         bool result;
987
         EA.TaggedValue tag;
988
 
989
         tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
990
         if (null != tag)
991
         {
992
            tag.Value = value;
993
         }
994
         else
995
         {
996
            tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);
997
         }
998
 
999
         if (tag != null)
1000
         {
1001
            result = tag.Update();
1002
         }
1003
         else
1004
         {
1005
            result = false;
1006
         }
1007
         return result;
1008
      }
1009
 
1010
 
2106 ghuddy 1011
      public static void RemoveAPIStereotypeFromContent()
2104 ghuddy 1012
      {
1013
         EA.ObjectType objType;
1014
         object obj;
2106 ghuddy 1015
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 1016
         if (objType == EA.ObjectType.otPackage)
1017
         {
1018
            RemoveAPIStereotypeFromContent((EA.Package)obj);
2106 ghuddy 1019
            Main.EA_Repository.RefreshModelView(((EA.Package)obj).PackageID);
2104 ghuddy 1020
         }
1021
         else if (objType == EA.ObjectType.otDiagram)
1022
         {
1023
            RemoveAPIStereotypeFromDiagram((EA.Diagram)obj);
2106 ghuddy 1024
            Main.EA_Repository.RefreshModelView(((EA.Diagram)obj).PackageID);
2104 ghuddy 1025
         }
1026
         else if (objType == EA.ObjectType.otElement)
1027
         {
1028
            RemoveAPIStereotypeFromContent((EA.Element)obj);
2106 ghuddy 1029
            Main.EA_Repository.RefreshModelView(((EA.Element)obj).PackageID);
2104 ghuddy 1030
         }
1031
      }
1032
 
2106 ghuddy 1033
      private static void RemoveAPIStereotypeFromPackage(EA.Package thePackage)
2104 ghuddy 1034
      {
1035
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace(",API","");
1036
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace("API,","");
1037
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace("API","");
1038
         thePackage.Update();
1039
      }
1040
 
2106 ghuddy 1041
      private static void RemoveAPIStereotypeFromDiagram(EA.Diagram theDiagram)
2104 ghuddy 1042
      {
1043
         // diagrams only use one stereotype, not a list of them
1044
         if (theDiagram.Stereotype.Equals("API"))
1045
         {
1046
            theDiagram.Stereotype = "";
1047
            theDiagram.Update();
1048
         }
1049
      }
1050
 
2106 ghuddy 1051
      private static void RemoveAPIStereotypeFromElement(EA.Element theElement)
2104 ghuddy 1052
      {
1053
         theElement.StereotypeEx = theElement.StereotypeEx.Replace(",API","");
1054
         theElement.StereotypeEx = theElement.StereotypeEx.Replace("API,","");
1055
         theElement.StereotypeEx = theElement.StereotypeEx.Replace("API","");
1056
         theElement.Update();
1057
      }
1058
 
2106 ghuddy 1059
      private static void RemoveAPIStereotypeFromContent(EA.Package thePackage)
2104 ghuddy 1060
      {
1061
         RemoveAPIStereotypeFromPackage(thePackage);
1062
 
1063
         foreach(EA.Diagram diagram in thePackage.Diagrams)
1064
         {
1065
            RemoveAPIStereotypeFromDiagram(diagram);
1066
         }
1067
 
1068
         foreach(EA.Element element in thePackage.Elements)
1069
         {
1070
            RemoveAPIStereotypeFromElement(element);
1071
         }
1072
 
1073
         foreach(EA.Package package in thePackage.Packages)
1074
         {
1075
            RemoveAPIStereotypeFromContent(package); // recursion
1076
         }
1077
      }
1078
 
2106 ghuddy 1079
      private static void RemoveAPIStereotypeFromContent(EA.Element theElement)
2104 ghuddy 1080
      {
1081
         RemoveAPIStereotypeFromElement(theElement);
1082
 
1083
         foreach(EA.Diagram diagram in theElement.Diagrams)
1084
         {
1085
            RemoveAPIStereotypeFromDiagram(diagram);
1086
         }
1087
 
1088
         foreach(EA.Element element in theElement.Elements)
1089
         {
1090
            RemoveAPIStereotypeFromContent(element); // recursion
1091
         }
1092
      }
1093
 
1094
 
2106 ghuddy 1095
      public static void MarkContentWithAPIStereotype()
2104 ghuddy 1096
      {
1097
         EA.ObjectType objType;
1098
         object obj;
2106 ghuddy 1099
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 1100
         if (objType == EA.ObjectType.otPackage)
1101
         {
1102
            MarkContentWithAPIStereotype((EA.Package)obj);
2106 ghuddy 1103
            Main.EA_Repository.RefreshModelView(((EA.Package)obj).PackageID);
2104 ghuddy 1104
         }
1105
         else if (objType == EA.ObjectType.otDiagram)
1106
         {
1107
            MarkDiagramWithAPIStereotype((EA.Diagram)obj);
2106 ghuddy 1108
            Main.EA_Repository.RefreshModelView(((EA.Diagram)obj).PackageID);
2104 ghuddy 1109
         }
1110
         else if (objType == EA.ObjectType.otElement)
1111
         {
1112
            MarkContentWithAPIStereotype((EA.Element)obj);
2106 ghuddy 1113
            Main.EA_Repository.RefreshModelView(((EA.Element)obj).PackageID);
2104 ghuddy 1114
         }
1115
      }
1116
 
2106 ghuddy 1117
      private static void MarkPackageWithAPIStereotype(EA.Package thePackage)
2104 ghuddy 1118
      {
1119
         if (thePackage.StereotypeEx.IndexOf("API") < 0)
1120
         {
1121
            if (thePackage.StereotypeEx.Length > 0)
1122
               thePackage.StereotypeEx += ",API";
1123
            else
1124
               thePackage.StereotypeEx = "API";
1125
            thePackage.Update();
1126
         }
1127
      }
1128
 
2106 ghuddy 1129
      private static void MarkDiagramWithAPIStereotype(EA.Diagram theDiagram)
2104 ghuddy 1130
      {
1131
         // diagrams only use one stereotype, not a list of them
1132
         theDiagram.Stereotype = "API";
1133
         theDiagram.Update();
1134
      }
1135
 
2106 ghuddy 1136
      private static void MarkElementWithAPIStereotype(EA.Element theElement)
2104 ghuddy 1137
      {
1138
         if (theElement.StereotypeEx.IndexOf("API") < 0)
1139
         {
1140
            if (theElement.StereotypeEx.Length > 0)
1141
               theElement.StereotypeEx += ",API";
1142
            else
1143
               theElement.Stereotype = "API";
1144
            theElement.Update();
1145
         }
1146
      }
1147
 
2106 ghuddy 1148
      private static void MarkContentWithAPIStereotype(EA.Package thePackage)
2104 ghuddy 1149
      {
1150
         MarkPackageWithAPIStereotype(thePackage);
1151
 
1152
         foreach(EA.Diagram diagram in thePackage.Diagrams)
1153
         {
1154
            MarkDiagramWithAPIStereotype(diagram);
1155
         }
1156
 
1157
         foreach(EA.Element element in thePackage.Elements)
1158
         {
1159
            MarkElementWithAPIStereotype(element);
1160
         }
1161
 
1162
         foreach(EA.Package package in thePackage.Packages)
1163
         {
1164
            MarkContentWithAPIStereotype(package); // recursion
1165
         }
1166
      }
1167
 
2106 ghuddy 1168
      private static void MarkContentWithAPIStereotype(EA.Element theElement)
2104 ghuddy 1169
      {
1170
         MarkElementWithAPIStereotype(theElement);
1171
 
1172
         foreach(EA.Diagram diagram in theElement.Diagrams)
1173
         {
1174
            MarkDiagramWithAPIStereotype(diagram);
1175
         }
1176
 
1177
         foreach(EA.Element element in theElement.Elements)
1178
         {
1179
            MarkContentWithAPIStereotype(element); // recursion
1180
         }
1181
      }
1182
 
1183
 
1184
 
2088 ghuddy 1185
      #region Temporary or experimental code
1186
 
1187
 
2106 ghuddy 1188
      private static void parse_element(int parentId, EA.Element theElement, int recurse_level)
2102 ghuddy 1189
      {
2106 ghuddy 1190
         Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
1191
            "ParentId:"
1192
            + parentId.ToString()
1193
            + ", Level:"
1194
            + recurse_level.ToString()
1195
            + ", TreePos:"
1196
            + theElement.TreePos.ToString() 
1197
            + ", ELE-ParentID:"
1198
            + theElement.ParentID.ToString()
1199
            + ", ELE-PackageID:"
1200
            + theElement.PackageID.ToString()
1201
            + ", ELE-ElementID:"
1202
            + theElement.ElementID.ToString()
1203
            + ",  ELE-Name: " 
1204
            + theElement.Name, -1);
1205
 
1206
         foreach(EA.Diagram theDiagram in theElement.Diagrams)
2102 ghuddy 1207
         {
2106 ghuddy 1208
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
1209
               "Level:"
1210
               + recurse_level.ToString() 
1211
               + ", ParentID:"
1212
               + theDiagram.ParentID.ToString()
1213
               + ", PackageID:"
1214
               + theDiagram.PackageID.ToString()
1215
               + ", DiagramID:"
1216
               + theDiagram.DiagramID.ToString()
1217
               + "  DIAGRAM: " 
1218
               + theDiagram.Name, -1);
1219
         }
2088 ghuddy 1220
 
2106 ghuddy 1221
         foreach(EA.Element subElement in theElement.Elements)
1222
         {
1223
            parse_element(theElement.ElementID, subElement, recurse_level+1);
2102 ghuddy 1224
         }
1225
      }
1226
 
1227
 
2088 ghuddy 1228
      /// <summary>
1229
      /// Parse a package structure in a similar way to that taken when users are generating a word
1230
      /// document, only here we simply write diagnostic text to the output tab.
1231
      /// </summary>
1232
      /// <param name="thePackage"></param>
1233
      /// <param name="recurse_level"></param>
2106 ghuddy 1234
      private static void parse_package(EA.Package thePackage, int recurse_level)
2088 ghuddy 1235
      {
2106 ghuddy 1236
         Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2088 ghuddy 1237
                                      "Level:"
1238
                                    + recurse_level.ToString() 
1239
                                    + ", ParentID:"
1240
                                    + thePackage.ParentID.ToString()
1241
                                    + ", PackageID:"
1242
                                    + thePackage.PackageID.ToString()
1243
                                    + ",  PACKAGE: " 
1244
                                    + thePackage.Name, -1);
1245
 
1246
         // default handling of diagrams
1247
         foreach(EA.Diagram theDiagram in thePackage.Diagrams)
1248
         {
2102 ghuddy 1249
            if (theDiagram.ParentID == 0)
2088 ghuddy 1250
            {
2106 ghuddy 1251
               Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2102 ghuddy 1252
                  "Level:"
1253
                  + recurse_level.ToString() 
2088 ghuddy 1254
                  + ", ParentID:"
2102 ghuddy 1255
                  + theDiagram.ParentID.ToString()
2088 ghuddy 1256
                  + ", PackageID:"
2102 ghuddy 1257
                  + theDiagram.PackageID.ToString()
1258
                  + ", DiagramID:"
1259
                  + theDiagram.DiagramID.ToString()
1260
                  + "  DIAGRAM: " 
1261
                  + theDiagram.Name, -1);
1262
            }
1263
         }
2088 ghuddy 1264
 
2102 ghuddy 1265
         foreach(EA.Element subElement in thePackage.Elements)
1266
         {
1267
            if (subElement.ParentID == 0 || thePackage.PackageID == subElement.ParentID)
1268
               parse_element(thePackage.PackageID, subElement, recurse_level+1);
2088 ghuddy 1269
         }
1270
 
1271
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
1272
         {
2102 ghuddy 1273
            parse_package(lowerLevelPackage, recurse_level+1);
2088 ghuddy 1274
         }
1275
      }
1276
 
1277
 
1278
      /// <summary>
1279
      /// Parses a specified package in a similar way to what would be done if a user were generating
1280
      /// a word document, but here do nothing except write diagnostic text to the output tab.
1281
      /// </summary>
2106 ghuddy 1282
      public static void showDiscoveryOrder()
2088 ghuddy 1283
      {
1284
         EA.ObjectType objType;
1285
         object obj;
1286
 
2106 ghuddy 1287
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1288
         if (objType == EA.ObjectType.otPackage)
1289
         {
1290
            EA.Package EA_ParentPackage = ((EA.Package)obj);
1291
 
2106 ghuddy 1292
            Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
1293
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "", -1);
1294
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Showing Object Discovery order for " + EA_ParentPackage.Name, -1);
2088 ghuddy 1295
 
2106 ghuddy 1296
            parse_package(EA_ParentPackage, 1);
2088 ghuddy 1297
         }
1298
         else
1299
         {
1300
            MessageBox.Show("You must select a package to parse");
1301
         }
1302
      }
1303
 
1304
 
2106 ghuddy 1305
      public static void SaveVersionControlledPackage()
2088 ghuddy 1306
      {
1307
         EA.ObjectType objType;
1308
         object obj;
1309
 
2106 ghuddy 1310
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1311
         if (objType == EA.ObjectType.otPackage)
1312
         {
1313
            EA.Package EA_Package = ((EA.Package)obj);
1314
 
1315
            if (EA_Package.IsControlled == true)
1316
            {
2106 ghuddy 1317
               EA.Project EA_Project = Main.EA_Repository.GetProjectInterface();
2088 ghuddy 1318
 
1319
               EA_Project.SaveControlledPackage( EA_Package.PackageGUID );
1320
 
1321
               //EA_Project.SaveControlledPackage( EA_Project.GUIDtoXML( EA_Package.PackageGUID ) );
1322
            }
1323
            else
1324
            {
1325
               MessageBox.Show("The package selected is not version controlled");
1326
            }
1327
          }
1328
         else
1329
         {
1330
            MessageBox.Show("You must select a package");
2094 ghuddy 1331
         }
2088 ghuddy 1332
      }
1333
 
1334
 
1335
      #endregion
1336
	}
1337
 
1338
 
1339
}