Subversion Repositories DevTools

Rev

Rev 2108 | Rev 2122 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2088 ghuddy 1
using System;
2
using System.Windows.Forms;
3
using System.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>
2114 ghuddy 465
      /// Generate a package hierarchy that reflects the standard design views.
466
      /// </summary>
467
      public static void create_StandardView_Layout()
468
      {
469
         EA.ObjectType objType;
470
         object obj;
471
 
472
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
473
         if (objType == EA.ObjectType.otPackage)
474
         {
475
            EA.Package parentPackage = ((EA.Package)obj);
476
 
477
            EA.Package newobj = null;
478
 
479
            newobj  = createPackage(parentPackage, "Component View", 1);
480
 
481
            newobj  = createPackage(parentPackage, "Deployment View", 2);
482
 
483
            newobj  = createPackage(parentPackage, "Document View", 3);
484
 
485
            newobj  = createPackage(parentPackage, "Logical View", 4);
486
 
487
            newobj = createPackage(parentPackage, "Dynamic View", 5);
488
 
489
            newobj = createPackage(parentPackage, "Requirement View",6);
490
 
491
            newobj = createPackage(parentPackage, "Use Case View", 7);
492
 
493
            parentPackage.Packages.Refresh();
494
 
495
            // refresh project browser view
496
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
497
         }
498
         else
499
         {
500
            MessageBox.Show("You must select a package into which the layout will be inserted");
501
         }
502
      }
503
 
504
 
505
      /// <summary>
2088 ghuddy 506
      /// This function works its way up the parental hierarchy to the root model, collecting the
2094 ghuddy 507
      /// strings names of each package and prepending them to a string accumulator with a view to
2088 ghuddy 508
      /// obtaing the full path of an element,diagram, or package.
509
      /// </summary>
510
      /// <param name="parentId"></param>
511
      /// <param name="instr"></param>
512
      /// <returns></returns>
2106 ghuddy 513
      public static string GetPackagePath( int parentId, string instr )
2088 ghuddy 514
      {
515
         if (parentId != 0)
516
         {
517
            EA.Package pkg;
2106 ghuddy 518
            pkg = Main.EA_Repository.GetPackageByID( parentId );
2088 ghuddy 519
            if (pkg != null)
520
            {
521
               instr = pkg.Name + "/" + instr;
522
               instr = GetPackagePath(pkg.ParentID, instr);
2094 ghuddy 523
            }
2088 ghuddy 524
         }
525
         return instr;
526
      }
527
 
528
 
2106 ghuddy 529
      private static void copy_GUID_to_clipboard(object obj, EA.ObjectType objType, bool confirm)
2088 ghuddy 530
      {
2106 ghuddy 531
         GUID_Clipboard.copy(obj, objType, confirm);
2088 ghuddy 532
      }
533
 
2094 ghuddy 534
 
2088 ghuddy 535
      /// <summary>
2094 ghuddy 536
      /// For the selected item, copy its GUID to the internal add-in GUID clipboard and the
2088 ghuddy 537
      /// global external clipboard. Also copy to the internal add-in GUID clipboard, the name of
538
      /// the element and its type. This will support the AddLinkElement() method.
539
      /// </summary>
2106 ghuddy 540
      public static void copy_GUID_to_clipboard()
2088 ghuddy 541
      {
542
         EA.ObjectType objType;
543
         object obj;
2106 ghuddy 544
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
545
         GUID_Clipboard.copy(obj, objType, true);
2088 ghuddy 546
      }
547
 
548
 
2106 ghuddy 549
      public static void AddTestTraceabilityElement()
2094 ghuddy 550
      {
551
         EA.ObjectType objType;
552
         object obj;
2106 ghuddy 553
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 554
         AddTestTraceabilityElement(obj, objType);
555
      }
2106 ghuddy 556
      public static void AddTestTraceabilityElement(object obj, EA.ObjectType objType)
2094 ghuddy 557
      {
558
         if (objType == EA.ObjectType.otPackage)
559
         {
560
            object newobj = null;
2088 ghuddy 561
 
2094 ghuddy 562
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestTraceability, EA_Constants.EA_DocGenElementType);
563
            if (newobj != null)
564
            {
565
               ((EA.Element)newobj).Update();
566
            }         
567
         }
568
         else
569
         {
570
            MessageBox.Show("You must select a package into which the element will be inserted");
571
         }
572
      }
573
 
2104 ghuddy 574
 
2094 ghuddy 575
      /// <summary>
576
      /// Using the internal add-in GUID clipboard, paste a test link element into the selected
577
      /// package.
578
      /// </summary>
2106 ghuddy 579
      public static void AddTestLinkElement()
2094 ghuddy 580
      {
581
         EA.ObjectType objType;
582
         object obj;
2106 ghuddy 583
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 584
         AddTestLinkElement(obj, objType);
585
      }
586
 
2106 ghuddy 587
      private static void AddTestLinkElement(object obj, EA.ObjectType objType)
2094 ghuddy 588
      {
589
         if (objType == EA.ObjectType.otPackage)
590
         {
591
            object newobj = null;
592
 
2106 ghuddy 593
            if (   GUID_Clipboard.objType == EA.ObjectType.otElement
594
                || GUID_Clipboard.objType == EA.ObjectType.otPackage)
2094 ghuddy 595
            {
2106 ghuddy 596
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2094 ghuddy 597
 
598
               if (newobj != null)
599
               {
2106 ghuddy 600
                  ((EA.Element)newobj).Notes = GUID_Clipboard.name + "\r\n" + GUID_Clipboard.guid;
2094 ghuddy 601
                  ((EA.Element)newobj).Update();
602
               }
603
            }
604
            else
605
            {
606
               MessageBox.Show("The GUID clipboard must first contain the GUID of an element (normally, a class), or a package");
607
            }
608
         }
609
         else
610
         {
611
            MessageBox.Show("You must select a package into which the test link will be inserted");
612
         }
613
      }
614
 
615
 
616
      /// <summary>
617
      /// Using the internal add-in GUID clipboard, paste a link element into the selected
618
      /// package.
619
      /// </summary>
2106 ghuddy 620
      public static void AddLinkElement()
2094 ghuddy 621
      {
622
         EA.ObjectType objType;
623
         object obj;
2106 ghuddy 624
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 625
         AddLinkElement(obj, objType);
626
      }
627
 
2106 ghuddy 628
      private static void AddLinkElement(object obj, EA.ObjectType objType)
2088 ghuddy 629
      {
630
         if (objType == EA.ObjectType.otPackage)
631
         {
632
            object newobj = null;
633
 
2106 ghuddy 634
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 635
            {
2106 ghuddy 636
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenPackageLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 637
            }
2106 ghuddy 638
            else if (GUID_Clipboard.objType == EA.ObjectType.otDiagram)
2088 ghuddy 639
            {
2106 ghuddy 640
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenDiagramLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 641
            }
2106 ghuddy 642
            else if (GUID_Clipboard.objType == EA.ObjectType.otElement)
2088 ghuddy 643
            {
2106 ghuddy 644
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenElementLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 645
            }
2106 ghuddy 646
            else if (GUID_Clipboard.objType == EA.ObjectType.otAttribute)
2088 ghuddy 647
            {
648
               MessageBox.Show("Attribute links are not currently supported");
649
            }
2106 ghuddy 650
            else if (GUID_Clipboard.objType == EA.ObjectType.otMethod)
2088 ghuddy 651
            {
652
               MessageBox.Show("Method links are not currently supported");
653
            }
654
 
655
            if (newobj != null)
656
            {
2106 ghuddy 657
               ((EA.Element)newobj).Notes = GUID_Clipboard.name + "\r\n" + GUID_Clipboard.guid;
2088 ghuddy 658
               ((EA.Element)newobj).Update();
659
            }
660
         }
661
         else
662
         {
663
            MessageBox.Show("You must select a package into which the link will be inserted");
2094 ghuddy 664
         }
2088 ghuddy 665
      }
666
 
2094 ghuddy 667
 
2106 ghuddy 668
      public static void AddNameLinkElement()
2104 ghuddy 669
      {
670
         EA.ObjectType objType;
671
         object obj;
2106 ghuddy 672
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 673
         AddNameLinkElement(obj, objType);
674
      }
675
 
2106 ghuddy 676
      private static void AddNameLinkElement(object obj, EA.ObjectType objType)
2104 ghuddy 677
      {
678
         if (objType == EA.ObjectType.otPackage)
679
         {
680
            object newobj = null;
681
 
2106 ghuddy 682
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2104 ghuddy 683
            {
2106 ghuddy 684
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenNameLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2104 ghuddy 685
               if (newobj != null)
686
               {
687
                  StringBuilder sb = new StringBuilder();
2106 ghuddy 688
                  sb.Append(GUID_Clipboard.name);
2104 ghuddy 689
                  sb.Append("\r\n");
2106 ghuddy 690
                  sb.Append(GUID_Clipboard.guid);
2104 ghuddy 691
                  sb.Append("\r\n");
692
                  sb.Append("### Add as many package names as you like below here.\r\n");
693
                  sb.Append("### Each should be of the form: package=name\r\n");
694
                  sb.Append("### Delete any unused package= lines from these notes.\r\n");
695
                  sb.Append("### The names are case sensitive and must match exactly\r\n");
696
                  sb.Append("### the names of the packages you wish to pull in to the\r\n");
697
                  sb.Append("### document model.\r\n");
698
                  sb.Append("package=\r\n");
699
                  sb.Append("package=\r\n");
700
                  sb.Append("package=\r\n");
701
 
702
                  ((EA.Element)newobj).Notes = sb.ToString();
703
                  ((EA.Element)newobj).Update();
704
               }            
705
            }
706
         }
707
         else
708
         {
709
            MessageBox.Show("You must select a package into which the name link will be inserted");
710
         }
711
      }
712
 
713
 
2106 ghuddy 714
      public static void AddTableElement()
2088 ghuddy 715
      {
716
         EA.ObjectType objType;
717
         object obj;
718
 
2106 ghuddy 719
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 720
         if (objType == EA.ObjectType.otPackage)
721
         {
722
            object newobj = null;
2088 ghuddy 723
 
2094 ghuddy 724
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTable, EA_Constants.EA_DocGenElementType);
725
            if (newobj != null)
726
            {
727
               ((EA.Element)newobj).Notes = "title=insertYourTitleHere\r\n"
728
                                          + "columns=2\r\n"
729
                                          + "seperator=,\r\n"
2104 ghuddy 730
                                          + "indent=1\r\n"
731
                                          + "widths=column1Width,column2Width\r\n"
2094 ghuddy 732
                                          + "column1Title,column2Title\r\n"
733
                                          + "cellcontent,cellcontent\r\n"
2104 ghuddy 734
                                          + "cellcontent,cellcontent\r\n"
735
                                          + "cellcontent,cellcontent\r\n"
2094 ghuddy 736
                                          + "etc,etc";
737
               ((EA.Element)newobj).Update();
738
            }
739
         }
740
         else
741
         {
742
            MessageBox.Show("You must select a package into which the Table Element will be inserted");
743
         }
2088 ghuddy 744
      }
745
 
746
 
2106 ghuddy 747
      public static void AddTextElement()
2094 ghuddy 748
      {
749
         EA.ObjectType objType;
750
         object obj;
751
 
2106 ghuddy 752
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 753
         if (objType == EA.ObjectType.otPackage)
754
         {
755
            object newobj = null;
756
 
757
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenText, EA_Constants.EA_DocGenElementType);
758
            if (newobj != null)
759
            {
760
               ((EA.Element)newobj).Notes = "Add your text here.";
761
               ((EA.Element)newobj).Update();
762
            }
763
         }
764
         else
765
         {
766
            MessageBox.Show("You must select a package into which the Text Element will be inserted");
767
         }
768
      }
769
 
770
 
2106 ghuddy 771
      public static void AddRelationshipMatrixElement()
2094 ghuddy 772
      {
773
         EA.ObjectType objType;
774
         object obj;
775
 
2106 ghuddy 776
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 777
         if (objType == EA.ObjectType.otPackage)
778
         {
2104 ghuddy 779
            RelationshipMatrixType dlg = new RelationshipMatrixType();
780
            DialogResult dlgRes = dlg.ShowDialog();
781
            if (dlgRes == DialogResult.OK)
2094 ghuddy 782
            {
2104 ghuddy 783
               object newobj = null;
784
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenRelationshipMatrix, EA_Constants.EA_DocGenElementType);
785
               if (newobj != null)
786
               {
787
                  ((EA.Element)newobj).Notes  = EA_RelationshipMatrix.optionTemplateForRelationshipMatrix(dlg.style());
788
                  ((EA.Element)newobj).Update();
789
               }
2094 ghuddy 790
            }
791
         }
792
         else
793
         {
794
            MessageBox.Show("You must select a package into which the RelationshipMatrix Element will be inserted");
795
         }
796
      }
797
 
798
 
2106 ghuddy 799
      public static void GeneratePackagesFromElementList()
2088 ghuddy 800
      {
801
         EA.ObjectType objType;
802
         object obj;
803
 
2106 ghuddy 804
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 805
         if (objType == EA.ObjectType.otPackage)
806
         {
2106 ghuddy 807
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 808
            {
2106 ghuddy 809
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 810
               if (theFoundPackage != null)
811
               {
812
                  EA.Package srcPackage = theFoundPackage;
813
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 814
 
2088 ghuddy 815
                  foreach( EA.Element srcElement in srcPackage.Elements)
816
                  {
2106 ghuddy 817
                     if (false == EA_Finders.elementNameExistsInPackage(destPackage, srcElement.Name.ToString()))
2088 ghuddy 818
                     {
819
                        createPackage(destPackage, srcElement.Name.ToString(), 1);
820
                     }
821
                  }
2094 ghuddy 822
               }
2088 ghuddy 823
            }
824
            else
825
            {
826
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
827
            }
828
         }
829
         else
830
         {
831
            MessageBox.Show("You must select a Destination Package into which the Generated Packages will be inserted");
832
         }
833
      }
834
 
835
 
2106 ghuddy 836
      public static void GenerateSubPackageLinks()
2088 ghuddy 837
      {
838
         EA.ObjectType objType;
839
         object obj;
840
 
2106 ghuddy 841
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 842
         if (objType == EA.ObjectType.otPackage)
843
         {
2106 ghuddy 844
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 845
            {
2106 ghuddy 846
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 847
               if (theFoundPackage != null)
848
               {
849
                  EA.Package srcPackage = theFoundPackage;
850
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 851
 
2106 ghuddy 852
                  GUID_Clipboard.push();
853
 
2088 ghuddy 854
                  foreach( EA.Package subPackage in srcPackage.Packages)
855
                  {
856
                     copy_GUID_to_clipboard( (object)subPackage, EA.ObjectType.otPackage, false);
857
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
858
                  }
2106 ghuddy 859
 
860
                  GUID_Clipboard.pop();
2094 ghuddy 861
               }
2088 ghuddy 862
            }
863
            else
864
            {
865
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
866
            }
867
         }
868
         else
869
         {
870
            MessageBox.Show("You must select a Destination Package into which the Sub-Package Links will be inserted");
871
         }
872
      }
873
 
874
 
2106 ghuddy 875
      public static void GenerateElementLinks()
2088 ghuddy 876
      {
877
         EA.ObjectType objType;
878
         object obj;
879
 
2106 ghuddy 880
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 881
         if (objType == EA.ObjectType.otPackage)
882
         {
2106 ghuddy 883
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 884
            {
2106 ghuddy 885
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 886
               if (theFoundPackage != null)
887
               {
888
                  EA.Package srcPackage = theFoundPackage;
889
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 890
 
2106 ghuddy 891
                  GUID_Clipboard.push();
892
 
2088 ghuddy 893
                  foreach( EA.Element subElement in srcPackage.Elements)
894
                  {
895
                     copy_GUID_to_clipboard( (object)subElement, EA.ObjectType.otElement, false);
896
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
897
                  }
2106 ghuddy 898
 
899
                  GUID_Clipboard.pop();
2094 ghuddy 900
               }
2088 ghuddy 901
            }
902
            else
903
            {
904
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
905
            }
906
         }
907
         else
908
         {
909
            MessageBox.Show("You must select a Destination Package into which the Element Links will be inserted");
2094 ghuddy 910
         }
2088 ghuddy 911
      }
912
 
2094 ghuddy 913
      /// <summary>
914
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
915
      /// a user to specify what processing is to be done upon or with each element found.
916
      /// </summary>
917
      /// <param name="thePackage"></param>
918
      /// <param name="worker"></param>
919
      /// <param name="recurse"></param>
2106 ghuddy 920
      public static void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
2088 ghuddy 921
      {
2094 ghuddy 922
         worker.processPackage( thePackage );
2088 ghuddy 923
 
2094 ghuddy 924
         foreach (EA.Element theElement in thePackage.Elements)
2088 ghuddy 925
         {
2094 ghuddy 926
            worker.processElement( theElement );
927
         }
2088 ghuddy 928
 
2094 ghuddy 929
         if (recurse == true)
930
         {
931
            foreach (EA.Package subPackage in thePackage.Packages)
2088 ghuddy 932
            {
2094 ghuddy 933
               // RECURSION
934
               findAndProcessPackageElements( subPackage, worker, true);
2088 ghuddy 935
            }
936
         }
2094 ghuddy 937
 
2088 ghuddy 938
      }
939
 
2094 ghuddy 940
 
2106 ghuddy 941
      public static void addDocumentReference()
2088 ghuddy 942
      {
943
         EA.ObjectType objType;
944
         object obj;
945
 
2106 ghuddy 946
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 947
         if (objType == EA.ObjectType.otPackage)
948
         {
2094 ghuddy 949
            DocReferenceForm dlg = new DocReferenceForm();
950
            DialogResult dlgRes = dlg.ShowDialog();
951
            if (dlgRes == DialogResult.OK)
952
            {
953
               object newobj = null;
2088 ghuddy 954
 
2094 ghuddy 955
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_DocNumber.Text, EA_Constants.EA_DocGenElementType);
956
               if (newobj != null)
957
               {
958
                  ((EA.Element)newobj).Notes = dlg.textBox_DocName.Text;
959
                  ((EA.Element)newobj).Update();
960
               }
2088 ghuddy 961
            }
962
         }
963
      }
964
 
2094 ghuddy 965
 
2106 ghuddy 966
      public static void addTerminology()
2088 ghuddy 967
      {
968
         EA.ObjectType objType;
969
         object obj;
970
 
2106 ghuddy 971
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 972
         if (objType == EA.ObjectType.otPackage)
973
         {
2094 ghuddy 974
            TerminologyForm dlg = new TerminologyForm();
975
            DialogResult dlgRes = dlg.ShowDialog();
976
            if (dlgRes == DialogResult.OK)
977
            {
978
               object newobj = null;
2088 ghuddy 979
 
2094 ghuddy 980
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_Term.Text, EA_Constants.EA_DocGenElementType);
981
               if (newobj != null)
982
               {
983
                  ((EA.Element)newobj).Notes = dlg.textBox_TermExpansion.Text;
984
                  ((EA.Element)newobj).Update();
985
               }
2088 ghuddy 986
            }
987
         }
988
      }
989
 
990
 
2106 ghuddy 991
      public static string ReadTag(EA.Package thePackage, string tagName)
2098 ghuddy 992
      {
2106 ghuddy 993
         EA.Element theElement = Main.EA_Repository.GetElementByGuid(thePackage.PackageGUID);
994
         if (theElement != null)
995
         {
996
            return ReadTag(theElement, tagName);
997
         }
998
         return "";
999
      }
1000
 
1001
      public static string ReadTag(EA.Element theElement, string tagName)
1002
      {
2098 ghuddy 1003
         string result;
1004
 
1005
         EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
1006
         if (null != tag)
1007
         {
1008
            result = tag.Value;
1009
         }
1010
         else
1011
         {
1012
            result = "";
1013
         }
1014
         return result;
1015
      }
1016
 
2106 ghuddy 1017
      public static bool WriteTag(EA.Package thePackage, string tagName, string value)
1018
      {
1019
         EA.Element theElement = Main.EA_Repository.GetElementByGuid(thePackage.PackageGUID);
1020
         if (theElement != null)
1021
         {
1022
            return WriteTag(theElement, tagName, value);
1023
         }
1024
         return false;
1025
      }
2098 ghuddy 1026
 
2106 ghuddy 1027
      public static bool WriteTag(EA.Element theElement, string tagName, string value)
2098 ghuddy 1028
      {
1029
         bool result;
1030
         EA.TaggedValue tag;
1031
 
1032
         tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
1033
         if (null != tag)
1034
         {
1035
            tag.Value = value;
1036
         }
1037
         else
1038
         {
1039
            tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);
1040
         }
1041
 
1042
         if (tag != null)
1043
         {
1044
            result = tag.Update();
1045
         }
1046
         else
1047
         {
1048
            result = false;
1049
         }
1050
         return result;
1051
      }
1052
 
1053
 
2106 ghuddy 1054
      public static void RemoveAPIStereotypeFromContent()
2104 ghuddy 1055
      {
1056
         EA.ObjectType objType;
1057
         object obj;
2106 ghuddy 1058
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 1059
         if (objType == EA.ObjectType.otPackage)
1060
         {
1061
            RemoveAPIStereotypeFromContent((EA.Package)obj);
2106 ghuddy 1062
            Main.EA_Repository.RefreshModelView(((EA.Package)obj).PackageID);
2104 ghuddy 1063
         }
1064
         else if (objType == EA.ObjectType.otDiagram)
1065
         {
1066
            RemoveAPIStereotypeFromDiagram((EA.Diagram)obj);
2106 ghuddy 1067
            Main.EA_Repository.RefreshModelView(((EA.Diagram)obj).PackageID);
2104 ghuddy 1068
         }
1069
         else if (objType == EA.ObjectType.otElement)
1070
         {
1071
            RemoveAPIStereotypeFromContent((EA.Element)obj);
2106 ghuddy 1072
            Main.EA_Repository.RefreshModelView(((EA.Element)obj).PackageID);
2104 ghuddy 1073
         }
1074
      }
1075
 
2106 ghuddy 1076
      private static void RemoveAPIStereotypeFromPackage(EA.Package thePackage)
2104 ghuddy 1077
      {
1078
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace(",API","");
1079
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace("API,","");
1080
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace("API","");
1081
         thePackage.Update();
1082
      }
1083
 
2106 ghuddy 1084
      private static void RemoveAPIStereotypeFromDiagram(EA.Diagram theDiagram)
2104 ghuddy 1085
      {
1086
         // diagrams only use one stereotype, not a list of them
1087
         if (theDiagram.Stereotype.Equals("API"))
1088
         {
1089
            theDiagram.Stereotype = "";
1090
            theDiagram.Update();
1091
         }
1092
      }
1093
 
2106 ghuddy 1094
      private static void RemoveAPIStereotypeFromElement(EA.Element theElement)
2104 ghuddy 1095
      {
1096
         theElement.StereotypeEx = theElement.StereotypeEx.Replace(",API","");
1097
         theElement.StereotypeEx = theElement.StereotypeEx.Replace("API,","");
1098
         theElement.StereotypeEx = theElement.StereotypeEx.Replace("API","");
1099
         theElement.Update();
1100
      }
1101
 
2106 ghuddy 1102
      private static void RemoveAPIStereotypeFromContent(EA.Package thePackage)
2104 ghuddy 1103
      {
1104
         RemoveAPIStereotypeFromPackage(thePackage);
1105
 
1106
         foreach(EA.Diagram diagram in thePackage.Diagrams)
1107
         {
1108
            RemoveAPIStereotypeFromDiagram(diagram);
1109
         }
1110
 
1111
         foreach(EA.Element element in thePackage.Elements)
1112
         {
1113
            RemoveAPIStereotypeFromElement(element);
1114
         }
1115
 
1116
         foreach(EA.Package package in thePackage.Packages)
1117
         {
1118
            RemoveAPIStereotypeFromContent(package); // recursion
1119
         }
1120
      }
1121
 
2106 ghuddy 1122
      private static void RemoveAPIStereotypeFromContent(EA.Element theElement)
2104 ghuddy 1123
      {
1124
         RemoveAPIStereotypeFromElement(theElement);
1125
 
1126
         foreach(EA.Diagram diagram in theElement.Diagrams)
1127
         {
1128
            RemoveAPIStereotypeFromDiagram(diagram);
1129
         }
1130
 
1131
         foreach(EA.Element element in theElement.Elements)
1132
         {
1133
            RemoveAPIStereotypeFromContent(element); // recursion
1134
         }
1135
      }
1136
 
1137
 
2106 ghuddy 1138
      public static void MarkContentWithAPIStereotype()
2104 ghuddy 1139
      {
1140
         EA.ObjectType objType;
1141
         object obj;
2106 ghuddy 1142
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 1143
         if (objType == EA.ObjectType.otPackage)
1144
         {
1145
            MarkContentWithAPIStereotype((EA.Package)obj);
2106 ghuddy 1146
            Main.EA_Repository.RefreshModelView(((EA.Package)obj).PackageID);
2104 ghuddy 1147
         }
1148
         else if (objType == EA.ObjectType.otDiagram)
1149
         {
1150
            MarkDiagramWithAPIStereotype((EA.Diagram)obj);
2106 ghuddy 1151
            Main.EA_Repository.RefreshModelView(((EA.Diagram)obj).PackageID);
2104 ghuddy 1152
         }
1153
         else if (objType == EA.ObjectType.otElement)
1154
         {
1155
            MarkContentWithAPIStereotype((EA.Element)obj);
2106 ghuddy 1156
            Main.EA_Repository.RefreshModelView(((EA.Element)obj).PackageID);
2104 ghuddy 1157
         }
1158
      }
1159
 
2106 ghuddy 1160
      private static void MarkPackageWithAPIStereotype(EA.Package thePackage)
2104 ghuddy 1161
      {
1162
         if (thePackage.StereotypeEx.IndexOf("API") < 0)
1163
         {
1164
            if (thePackage.StereotypeEx.Length > 0)
1165
               thePackage.StereotypeEx += ",API";
1166
            else
1167
               thePackage.StereotypeEx = "API";
1168
            thePackage.Update();
1169
         }
1170
      }
1171
 
2106 ghuddy 1172
      private static void MarkDiagramWithAPIStereotype(EA.Diagram theDiagram)
2104 ghuddy 1173
      {
1174
         // diagrams only use one stereotype, not a list of them
1175
         theDiagram.Stereotype = "API";
1176
         theDiagram.Update();
1177
      }
1178
 
2106 ghuddy 1179
      private static void MarkElementWithAPIStereotype(EA.Element theElement)
2104 ghuddy 1180
      {
1181
         if (theElement.StereotypeEx.IndexOf("API") < 0)
1182
         {
1183
            if (theElement.StereotypeEx.Length > 0)
1184
               theElement.StereotypeEx += ",API";
1185
            else
1186
               theElement.Stereotype = "API";
1187
            theElement.Update();
1188
         }
1189
      }
1190
 
2106 ghuddy 1191
      private static void MarkContentWithAPIStereotype(EA.Package thePackage)
2104 ghuddy 1192
      {
1193
         MarkPackageWithAPIStereotype(thePackage);
1194
 
1195
         foreach(EA.Diagram diagram in thePackage.Diagrams)
1196
         {
1197
            MarkDiagramWithAPIStereotype(diagram);
1198
         }
1199
 
1200
         foreach(EA.Element element in thePackage.Elements)
1201
         {
1202
            MarkElementWithAPIStereotype(element);
1203
         }
1204
 
1205
         foreach(EA.Package package in thePackage.Packages)
1206
         {
1207
            MarkContentWithAPIStereotype(package); // recursion
1208
         }
1209
      }
1210
 
2106 ghuddy 1211
      private static void MarkContentWithAPIStereotype(EA.Element theElement)
2104 ghuddy 1212
      {
1213
         MarkElementWithAPIStereotype(theElement);
1214
 
1215
         foreach(EA.Diagram diagram in theElement.Diagrams)
1216
         {
1217
            MarkDiagramWithAPIStereotype(diagram);
1218
         }
1219
 
1220
         foreach(EA.Element element in theElement.Elements)
1221
         {
1222
            MarkContentWithAPIStereotype(element); // recursion
1223
         }
1224
      }
1225
 
1226
 
1227
 
2088 ghuddy 1228
      #region Temporary or experimental code
1229
 
1230
 
2106 ghuddy 1231
      private static void parse_element(int parentId, EA.Element theElement, int recurse_level)
2102 ghuddy 1232
      {
2106 ghuddy 1233
         Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
1234
            "ParentId:"
1235
            + parentId.ToString()
1236
            + ", Level:"
1237
            + recurse_level.ToString()
1238
            + ", TreePos:"
1239
            + theElement.TreePos.ToString() 
1240
            + ", ELE-ParentID:"
1241
            + theElement.ParentID.ToString()
1242
            + ", ELE-PackageID:"
1243
            + theElement.PackageID.ToString()
1244
            + ", ELE-ElementID:"
1245
            + theElement.ElementID.ToString()
1246
            + ",  ELE-Name: " 
1247
            + theElement.Name, -1);
1248
 
1249
         foreach(EA.Diagram theDiagram in theElement.Diagrams)
2102 ghuddy 1250
         {
2106 ghuddy 1251
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
1252
               "Level:"
1253
               + recurse_level.ToString() 
1254
               + ", ParentID:"
1255
               + theDiagram.ParentID.ToString()
1256
               + ", PackageID:"
1257
               + theDiagram.PackageID.ToString()
1258
               + ", DiagramID:"
1259
               + theDiagram.DiagramID.ToString()
1260
               + "  DIAGRAM: " 
1261
               + theDiagram.Name, -1);
1262
         }
2088 ghuddy 1263
 
2106 ghuddy 1264
         foreach(EA.Element subElement in theElement.Elements)
1265
         {
1266
            parse_element(theElement.ElementID, subElement, recurse_level+1);
2102 ghuddy 1267
         }
1268
      }
1269
 
1270
 
2088 ghuddy 1271
      /// <summary>
1272
      /// Parse a package structure in a similar way to that taken when users are generating a word
1273
      /// document, only here we simply write diagnostic text to the output tab.
1274
      /// </summary>
1275
      /// <param name="thePackage"></param>
1276
      /// <param name="recurse_level"></param>
2106 ghuddy 1277
      private static void parse_package(EA.Package thePackage, int recurse_level)
2088 ghuddy 1278
      {
2106 ghuddy 1279
         Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2088 ghuddy 1280
                                      "Level:"
1281
                                    + recurse_level.ToString() 
1282
                                    + ", ParentID:"
1283
                                    + thePackage.ParentID.ToString()
1284
                                    + ", PackageID:"
1285
                                    + thePackage.PackageID.ToString()
1286
                                    + ",  PACKAGE: " 
1287
                                    + thePackage.Name, -1);
1288
 
1289
         // default handling of diagrams
1290
         foreach(EA.Diagram theDiagram in thePackage.Diagrams)
1291
         {
2102 ghuddy 1292
            if (theDiagram.ParentID == 0)
2088 ghuddy 1293
            {
2106 ghuddy 1294
               Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2102 ghuddy 1295
                  "Level:"
1296
                  + recurse_level.ToString() 
2088 ghuddy 1297
                  + ", ParentID:"
2102 ghuddy 1298
                  + theDiagram.ParentID.ToString()
2088 ghuddy 1299
                  + ", PackageID:"
2102 ghuddy 1300
                  + theDiagram.PackageID.ToString()
1301
                  + ", DiagramID:"
1302
                  + theDiagram.DiagramID.ToString()
1303
                  + "  DIAGRAM: " 
1304
                  + theDiagram.Name, -1);
1305
            }
1306
         }
2088 ghuddy 1307
 
2102 ghuddy 1308
         foreach(EA.Element subElement in thePackage.Elements)
1309
         {
1310
            if (subElement.ParentID == 0 || thePackage.PackageID == subElement.ParentID)
1311
               parse_element(thePackage.PackageID, subElement, recurse_level+1);
2088 ghuddy 1312
         }
1313
 
1314
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
1315
         {
2102 ghuddy 1316
            parse_package(lowerLevelPackage, recurse_level+1);
2088 ghuddy 1317
         }
1318
      }
1319
 
1320
 
1321
      /// <summary>
1322
      /// Parses a specified package in a similar way to what would be done if a user were generating
1323
      /// a word document, but here do nothing except write diagnostic text to the output tab.
1324
      /// </summary>
2106 ghuddy 1325
      public static void showDiscoveryOrder()
2088 ghuddy 1326
      {
1327
         EA.ObjectType objType;
1328
         object obj;
1329
 
2106 ghuddy 1330
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1331
         if (objType == EA.ObjectType.otPackage)
1332
         {
1333
            EA.Package EA_ParentPackage = ((EA.Package)obj);
1334
 
2106 ghuddy 1335
            Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
1336
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "", -1);
1337
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Showing Object Discovery order for " + EA_ParentPackage.Name, -1);
2088 ghuddy 1338
 
2106 ghuddy 1339
            parse_package(EA_ParentPackage, 1);
2088 ghuddy 1340
         }
1341
         else
1342
         {
1343
            MessageBox.Show("You must select a package to parse");
1344
         }
1345
      }
1346
 
1347
 
2106 ghuddy 1348
      public static void SaveVersionControlledPackage()
2088 ghuddy 1349
      {
1350
         EA.ObjectType objType;
1351
         object obj;
1352
 
2106 ghuddy 1353
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1354
         if (objType == EA.ObjectType.otPackage)
1355
         {
1356
            EA.Package EA_Package = ((EA.Package)obj);
1357
 
1358
            if (EA_Package.IsControlled == true)
1359
            {
2106 ghuddy 1360
               EA.Project EA_Project = Main.EA_Repository.GetProjectInterface();
2088 ghuddy 1361
 
1362
               EA_Project.SaveControlledPackage( EA_Package.PackageGUID );
1363
 
1364
               //EA_Project.SaveControlledPackage( EA_Project.GUIDtoXML( EA_Package.PackageGUID ) );
1365
            }
1366
            else
1367
            {
1368
               MessageBox.Show("The package selected is not version controlled");
1369
            }
1370
          }
1371
         else
1372
         {
1373
            MessageBox.Show("You must select a package");
2094 ghuddy 1374
         }
2088 ghuddy 1375
      }
1376
 
1377
 
1378
      #endregion
1379
	}
1380
 
1381
 
1382
}