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