Subversion Repositories DevTools

Rev

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