Subversion Repositories DevTools

Rev

Rev 2098 | Rev 2104 | 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;
5
using Word;
6
 
7
namespace EA_DocGen
8
{
9
   /// <summary>
10
   /// A Base Class designed to work with the findAndProcessPackageElements method.
11
   /// Users will normally derive their own classes from this and add real functionality
12
   /// to the over-ridable methods the base class provides.
13
   /// </summary>
14
   public class EA_UtilitiesRecursionWorker
15
   {
16
      public EA_UtilitiesRecursionWorker()
17
      {
18
      }
19
 
20
      public virtual void processElement( EA.Element theElement )
21
      {
22
      }
23
      public virtual void processPackage( EA.Package thePackage )
24
      {
25
      }
26
   }
27
 
2094 ghuddy 28
 
29
 
2088 ghuddy 30
	/// <summary>
31
	/// Class containing functions that implement the EA_DocGen menu items.
32
	/// </summary>
33
	public class EA_Utilities
34
	{
35
      // Data
36
      public EA_DocGenOptions options = null;
37
 
38
      public GUID_Clipboard guid_clipboard = null;
39
 
40
      private EA.Repository EA_Repository = null;
41
 
42
      public EA_Finders EA_Finder = null;
43
 
44
      private EA_RelationshipMatrix EA_RelMatrix = null;
45
 
46
      // Operations
47
 
48
		public EA_Utilities()
49
		{
50
         guid_clipboard = new GUID_Clipboard(this);
51
 
52
         options = new EA_DocGenOptions(this);
53
 
54
         EA_Finder = new EA_Finders();
2094 ghuddy 55
 
2088 ghuddy 56
         EA_RelMatrix = new EA_RelationshipMatrix(this);
57
		}
2094 ghuddy 58
 
59
 
2088 ghuddy 60
      public void accept_EA_RepositoryRef(EA.Repository EA_RepositoryRef)
61
      {
62
         EA_Repository = EA_RepositoryRef;
63
         EA_Finder.accept_EA_RepositoryRef(EA_RepositoryRef);
64
      }
65
 
2094 ghuddy 66
      public void modifyOptions()
67
      {
68
         EA.ObjectType objType;
69
         object obj;
2088 ghuddy 70
 
2094 ghuddy 71
         objType = EA_Repository.GetTreeSelectedItem( out obj );
72
         if (objType == EA.ObjectType.otElement)
73
         {
74
            EA.Element ele = (EA.Element)obj;
2088 ghuddy 75
 
2094 ghuddy 76
            if (0 == ele.Name.CompareTo(EA_Constants.EA_DocGenBaseName))
77
            {
78
               if (true == options.lookForAndProcess_EA_DocGen_Element( ele ))
79
               {
80
                  EA_DocGenOptionsForm dlg = new EA_DocGenOptionsForm();
81
                  dlg.populate(EA_Repository, options);
82
                  DialogResult dlgRes = dlg.ShowDialog();
83
                  if (dlgRes == DialogResult.OK)
84
                  {
85
                     dlg.read(EA_Repository, options);
2088 ghuddy 86
 
2094 ghuddy 87
                     options.updateEA_DocGen(ele);
88
                  }
89
               }
90
            }
91
         }
92
      }
93
 
2088 ghuddy 94
      /// <summary>
95
      /// Begins the document generation process, opening the dialog to capture input/output
96
      /// files. the createWordDoc dialog class does most of the work ofcoarse.
97
      /// </summary>
98
      public void createWordDoc()
99
      {
100
         EA.ObjectType objType;
101
         object obj;
102
 
103
         objType = EA_Repository.GetTreeSelectedItem( out obj );
104
         if (objType == EA.ObjectType.otPackage)
105
         {
106
            // Make sure this package has an EA_DocGen element
107
            if (true == options.lookForAndProcess_EA_DocGen_Element( ((EA.Package)obj) ))
108
            {
2094 ghuddy 109
               // bring up the dialog for doc generation
2088 ghuddy 110
               createWordDoc dialog = new createWordDoc(EA_Repository, ((EA.Package)obj), this);
111
               dialog.Text = "Generate Document From Model Layout";
2094 ghuddy 112
               dialog.ShowDialog();
113
            }
2088 ghuddy 114
            else
115
            {
116
               MessageBox.Show("EA_DocGen document model packages must contain an EA_DocGen element");
117
            }
118
         }
119
         else
120
         {
121
            MessageBox.Show("You must select a package whose content is to be formed into a document");
2094 ghuddy 122
         }
2088 ghuddy 123
      }
124
 
125
 
126
      /// <summary>
127
      /// Creates a package under the specified parent package. the package is given a tree position
128
      /// as specified in order for it to be ordered in the model as the caller requires.
129
      /// </summary>
130
      /// <param name="parentPackage"></param>
131
      /// <param name="name"></param>
132
      /// <param name="treePos"></param>
133
      /// <returns></returns>
134
      public EA.Package createPackage(EA.Package parentPackage, string name, int treePos)
135
      {
136
         EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");
137
         newobj.TreePos = treePos;
138
         newobj.Update();
139
         return newobj;
140
      }
141
 
2094 ghuddy 142
 
2088 ghuddy 143
      /// <summary>
144
      /// Generate a package hierarchy that reflects the document layout of BMS-00289, the
145
      /// ERG Product Software Design Document.
146
      /// </summary>
147
      public void create_BMS00289_Layout()
148
      {
149
         EA.ObjectType objType;
150
         object obj;
151
 
152
         objType = EA_Repository.GetTreeSelectedItem( out obj );
153
         if (objType == EA.ObjectType.otPackage)
154
         {
2094 ghuddy 155
            if (  ((EA.Package)obj).Packages.Count == 0
2088 ghuddy 156
               && ((EA.Package)obj).Elements.Count == 0
157
               && ((EA.Package)obj).Diagrams.Count == 0 )
158
            {
159
               EA.Package parentPackage = ((EA.Package)obj);
160
 
161
               EA.Package newobj = null;
162
               EA.Package newobj2 = null;
163
               EA.Package newobj3 = null;
164
               EA.Package newobj4 = null;
165
               EA.Package newobj5 = null;
166
 
167
               newobj  = createPackage(parentPackage, "Introduction", 1);
168
               newobj2 = createPackage(newobj, "Purpose", 1);
169
               newobj2 = createPackage(newobj, "Scope", 2);
170
               newobj2 = createPackage(newobj, "Terminology", 3);
171
               newobj2 = createPackage(newobj, "References", 4);
172
 
173
               newobj  = createPackage(parentPackage, "Design Assumptions And Constraints", 2);
174
 
175
               newobj  = createPackage(parentPackage, "System Overview", 3);
176
 
177
               newobj  = createPackage(parentPackage, "High Level Design", 4);
178
               newobj2 = createPackage(newobj, "Software Architecture", 1);
179
               newobj2 = createPackage(newobj, "External Interfaces", 2);
180
               newobj2 = createPackage(newobj, "Internal Interfaces", 3);
181
               newobj2 = createPackage(newobj, "Memory And Processing Time Allocation", 4);
182
               newobj2 = createPackage(newobj, "Operational Modes", 5);
183
               newobj2 = createPackage(newobj, "Component Descriptions", 6);
184
 
185
               newobj = createPackage(parentPackage, "Detailed Design", 5);
186
 
187
               newobj = createPackage(parentPackage, "Unit Test Design",6);
188
 
189
               newobj2 = createPackage(newobj, "Test Data", 1);
190
               newobj2 = createPackage(newobj, "Test Stubs", 2);
191
               newobj2 = createPackage(newobj, "Other Elements", 3);
192
               newobj2 = createPackage(newobj, "Unit Test Traceability To Design", 4);
193
               newobj2 = createPackage(newobj, "Test Suites and Test Cases", 5);
194
               newobj3 = createPackage(newobj2, "Test Suite Name", 1);
195
               newobj4 = createPackage(newobj3, "Test Name", 1);
196
               newobj5 = createPackage(newobj4, "Description", 1);
197
               newobj5 = createPackage(newobj4, "Inputs", 2);
198
               newobj5 = createPackage(newobj4, "Expected Outputs", 3);
199
 
200
               newobj = createPackage(parentPackage, "Requirements Traceability", 7);
201
 
202
               // create an EA_DocGen element
203
               EA.Element newElement = (EA.Element)parentPackage.Elements.AddNew( "EA_DocGen", "InformationItem" );
2094 ghuddy 204
               newElement.Notes = "[ElementTypes]\r\nRequirement\r\nClass\r\nComponent\r\n";
2088 ghuddy 205
               newElement.Update();
206
 
207
               parentPackage.Packages.Refresh();
208
 
209
               // refresh project browser view
210
               EA_Repository.RefreshModelView(parentPackage.PackageID);
211
            }
212
            else
213
            {
214
               MessageBox.Show("Can only insert layout into an empty package");
215
            }
216
         }
217
         else
218
         {
219
            MessageBox.Show("You must select a package into which the layout will be inserted");
220
         }
221
      }
222
 
223
 
224
      /// <summary>
2094 ghuddy 225
      /// Generate a package hierarchy that reflects a basic document layout.
226
      /// </summary>
227
      public void create_basic_Layout()
228
      {
229
         EA.ObjectType objType;
230
         object obj;
231
 
232
         objType = EA_Repository.GetTreeSelectedItem( out obj );
233
         if (objType == EA.ObjectType.otPackage)
234
         {
235
            if (  ((EA.Package)obj).Packages.Count == 0
236
               && ((EA.Package)obj).Elements.Count == 0
237
               && ((EA.Package)obj).Diagrams.Count == 0 )
238
            {
239
               EA.Package parentPackage = ((EA.Package)obj);
240
 
241
               EA.Package newobj = null;
242
               EA.Package newobj2 = null;
243
               //EA.Package newobj3 = null;
244
               //EA.Package newobj4 = null;
245
               //EA.Package newobj5 = null;
246
 
247
               newobj  = createPackage(parentPackage, "Introduction", 1);
248
               newobj2 = createPackage(newobj, "Purpose", 1);
249
               newobj2 = createPackage(newobj, "Scope", 2);
250
               newobj2 = createPackage(newobj, "Terminology", 3);
251
               newobj2 = createPackage(newobj, "References", 4);
252
 
253
               newobj  = createPackage(parentPackage, "Section 2 (rename me as required)", 2);
254
 
255
               newobj  = createPackage(parentPackage, "Section 3 (rename me as required)", 3);
256
 
257
               // create an EA_DocGen element
258
               EA.Element newElement = (EA.Element)parentPackage.Elements.AddNew( EA_Constants.EA_DocGenBaseName,
259
                                                                                  EA_Constants.EA_DocGenElementType );
260
               newElement.Notes = "[ElementTypes]\r\nRequirement\r\nClass\r\nComponent\r\n";
261
               newElement.Update();
262
 
263
               parentPackage.Packages.Refresh();
264
 
265
               // refresh project browser view
266
               EA_Repository.RefreshModelView(parentPackage.PackageID);
267
            }
268
            else
269
            {
270
               MessageBox.Show("Can only insert layout into an empty package");
271
            }
272
         }
273
         else
274
         {
275
            MessageBox.Show("You must select a package into which the layout will be inserted");
276
         }
277
      }
278
 
279
 
280
      /// <summary>
2088 ghuddy 281
      /// This function works its way up the parental hierarchy to the root model, collecting the
2094 ghuddy 282
      /// strings names of each package and prepending them to a string accumulator with a view to
2088 ghuddy 283
      /// obtaing the full path of an element,diagram, or package.
284
      /// </summary>
285
      /// <param name="parentId"></param>
286
      /// <param name="instr"></param>
287
      /// <returns></returns>
288
      public string GetPackagePath( int parentId, string instr )
289
      {
290
         if (parentId != 0)
291
         {
292
            EA.Package pkg;
293
            pkg = EA_Repository.GetPackageByID( parentId );
294
            if (pkg != null)
295
            {
296
               instr = pkg.Name + "/" + instr;
297
               instr = GetPackagePath(pkg.ParentID, instr);
2094 ghuddy 298
            }
2088 ghuddy 299
         }
300
         return instr;
301
      }
302
 
303
 
304
      private void copy_GUID_to_clipboard(object obj, EA.ObjectType objType, bool confirm)
305
      {
306
         guid_clipboard.copy(obj, objType, confirm);
307
      }
308
 
2094 ghuddy 309
 
2088 ghuddy 310
      /// <summary>
2094 ghuddy 311
      /// For the selected item, copy its GUID to the internal add-in GUID clipboard and the
2088 ghuddy 312
      /// global external clipboard. Also copy to the internal add-in GUID clipboard, the name of
313
      /// the element and its type. This will support the AddLinkElement() method.
314
      /// </summary>
315
      public void copy_GUID_to_clipboard()
316
      {
317
         EA.ObjectType objType;
318
         object obj;
319
         objType = EA_Repository.GetTreeSelectedItem( out obj );
320
         guid_clipboard.copy(obj, objType, true);
321
      }
322
 
323
 
2094 ghuddy 324
      public void AddTestTraceabilityElement()
325
      {
326
         EA.ObjectType objType;
327
         object obj;
328
         objType = EA_Repository.GetTreeSelectedItem( out obj );
329
         AddTestTraceabilityElement(obj, objType);
330
      }
331
      public void AddTestTraceabilityElement(object obj, EA.ObjectType objType)
332
      {
333
         if (objType == EA.ObjectType.otPackage)
334
         {
335
            object newobj = null;
2088 ghuddy 336
 
2094 ghuddy 337
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestTraceability, EA_Constants.EA_DocGenElementType);
338
            if (newobj != null)
339
            {
340
               ((EA.Element)newobj).Update();
341
            }         
342
         }
343
         else
344
         {
345
            MessageBox.Show("You must select a package into which the element will be inserted");
346
         }
347
      }
348
 
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
 
442
      public void AddTableElement()
2088 ghuddy 443
      {
444
         EA.ObjectType objType;
445
         object obj;
446
 
447
         objType = EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 448
         if (objType == EA.ObjectType.otPackage)
449
         {
450
            object newobj = null;
2088 ghuddy 451
 
2094 ghuddy 452
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTable, EA_Constants.EA_DocGenElementType);
453
            if (newobj != null)
454
            {
455
               ((EA.Element)newobj).Notes = "title=insertYourTitleHere\r\n"
456
                                          + "columns=2\r\n"
457
                                          + "seperator=,\r\n"
458
                                          + "column1Title,column2Title\r\n"
459
                                          + "cellcontent,cellcontent\r\n"
460
                                          + "etc,etc";
461
               ((EA.Element)newobj).Update();
462
            }
463
         }
464
         else
465
         {
466
            MessageBox.Show("You must select a package into which the Table Element will be inserted");
467
         }
2088 ghuddy 468
      }
469
 
470
 
2094 ghuddy 471
      public void AddTextElement()
472
      {
473
         EA.ObjectType objType;
474
         object obj;
475
 
476
         objType = EA_Repository.GetTreeSelectedItem( out obj );
477
         if (objType == EA.ObjectType.otPackage)
478
         {
479
            object newobj = null;
480
 
481
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenText, EA_Constants.EA_DocGenElementType);
482
            if (newobj != null)
483
            {
484
               ((EA.Element)newobj).Notes = "Add your text here.";
485
               ((EA.Element)newobj).Update();
486
            }
487
         }
488
         else
489
         {
490
            MessageBox.Show("You must select a package into which the Text Element will be inserted");
491
         }
492
      }
493
 
494
 
495
      public void AddRelationshipMatrixElement()
496
      {
497
         EA.ObjectType objType;
498
         object obj;
499
 
500
         objType = EA_Repository.GetTreeSelectedItem( out obj );
501
         if (objType == EA.ObjectType.otPackage)
502
         {
503
            object newobj = null;
504
 
505
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenRelationshipMatrix, EA_Constants.EA_DocGenElementType);
506
            if (newobj != null)
507
            {
508
               ((EA.Element)newobj).Notes  = EA_RelMatrix.optionTemplateForRelationshipMatrix();
509
               ((EA.Element)newobj).Update();
510
            }
511
         }
512
         else
513
         {
514
            MessageBox.Show("You must select a package into which the RelationshipMatrix Element will be inserted");
515
         }
516
      }
517
 
518
 
2088 ghuddy 519
      public void GeneratePackagesFromElementList()
520
      {
521
         EA.ObjectType objType;
522
         object obj;
523
 
524
         objType = EA_Repository.GetTreeSelectedItem( out obj );
525
         if (objType == EA.ObjectType.otPackage)
526
         {
527
            if (guid_clipboard.objType == EA.ObjectType.otPackage)
528
            {
529
               EA.Package theFoundPackage = EA_Finder.findPackageInRepositoryByGUID(guid_clipboard.guid);
530
               if (theFoundPackage != null)
531
               {
532
                  EA.Package srcPackage = theFoundPackage;
533
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 534
 
2088 ghuddy 535
                  foreach( EA.Element srcElement in srcPackage.Elements)
536
                  {
537
                     if (false == EA_Finder.elementNameExistsInPackage(destPackage, srcElement.Name.ToString()))
538
                     {
539
                        createPackage(destPackage, srcElement.Name.ToString(), 1);
540
                     }
541
                  }
2094 ghuddy 542
               }
2088 ghuddy 543
            }
544
            else
545
            {
546
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
547
            }
548
         }
549
         else
550
         {
551
            MessageBox.Show("You must select a Destination Package into which the Generated Packages will be inserted");
552
         }
553
      }
554
 
555
 
556
      public void GenerateSubPackageLinks()
557
      {
558
         EA.ObjectType objType;
559
         object obj;
560
 
561
         objType = EA_Repository.GetTreeSelectedItem( out obj );
562
         if (objType == EA.ObjectType.otPackage)
563
         {
564
            if (guid_clipboard.objType == EA.ObjectType.otPackage)
565
            {
566
               EA.Package theFoundPackage = EA_Finder.findPackageInRepositoryByGUID(guid_clipboard.guid);
567
               if (theFoundPackage != null)
568
               {
569
                  EA.Package srcPackage = theFoundPackage;
570
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 571
 
2088 ghuddy 572
                  foreach( EA.Package subPackage in srcPackage.Packages)
573
                  {
574
                     copy_GUID_to_clipboard( (object)subPackage, EA.ObjectType.otPackage, false);
575
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
576
                  }
2094 ghuddy 577
               }
2088 ghuddy 578
            }
579
            else
580
            {
581
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
582
            }
583
         }
584
         else
585
         {
586
            MessageBox.Show("You must select a Destination Package into which the Sub-Package Links will be inserted");
587
         }
588
      }
589
 
590
 
591
      public void GenerateElementLinks()
592
      {
593
         EA.ObjectType objType;
594
         object obj;
595
 
596
         objType = EA_Repository.GetTreeSelectedItem( out obj );
597
         if (objType == EA.ObjectType.otPackage)
598
         {
599
            if (guid_clipboard.objType == EA.ObjectType.otPackage)
600
            {
601
               EA.Package theFoundPackage = EA_Finder.findPackageInRepositoryByGUID(guid_clipboard.guid);
602
               if (theFoundPackage != null)
603
               {
604
                  EA.Package srcPackage = theFoundPackage;
605
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 606
 
2088 ghuddy 607
                  foreach( EA.Element subElement in srcPackage.Elements)
608
                  {
609
                     copy_GUID_to_clipboard( (object)subElement, EA.ObjectType.otElement, false);
610
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
611
                  }
2094 ghuddy 612
               }
2088 ghuddy 613
            }
614
            else
615
            {
616
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
617
            }
618
         }
619
         else
620
         {
621
            MessageBox.Show("You must select a Destination Package into which the Element Links will be inserted");
2094 ghuddy 622
         }
2088 ghuddy 623
      }
624
 
2094 ghuddy 625
      /// <summary>
626
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
627
      /// a user to specify what processing is to be done upon or with each element found.
628
      /// </summary>
629
      /// <param name="thePackage"></param>
630
      /// <param name="worker"></param>
631
      /// <param name="recurse"></param>
632
      public void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
2088 ghuddy 633
      {
2094 ghuddy 634
         worker.processPackage( thePackage );
2088 ghuddy 635
 
2094 ghuddy 636
         foreach (EA.Element theElement in thePackage.Elements)
2088 ghuddy 637
         {
2094 ghuddy 638
            worker.processElement( theElement );
639
         }
2088 ghuddy 640
 
2094 ghuddy 641
         if (recurse == true)
642
         {
643
            foreach (EA.Package subPackage in thePackage.Packages)
2088 ghuddy 644
            {
2094 ghuddy 645
               // RECURSION
646
               findAndProcessPackageElements( subPackage, worker, true);
2088 ghuddy 647
            }
648
         }
2094 ghuddy 649
 
2088 ghuddy 650
      }
651
 
2094 ghuddy 652
 
653
      public void addDocumentReference()
2088 ghuddy 654
      {
655
         EA.ObjectType objType;
656
         object obj;
657
 
658
         objType = EA_Repository.GetTreeSelectedItem( out obj );
659
         if (objType == EA.ObjectType.otPackage)
660
         {
2094 ghuddy 661
            DocReferenceForm dlg = new DocReferenceForm();
662
            DialogResult dlgRes = dlg.ShowDialog();
663
            if (dlgRes == DialogResult.OK)
664
            {
665
               object newobj = null;
2088 ghuddy 666
 
2094 ghuddy 667
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_DocNumber.Text, EA_Constants.EA_DocGenElementType);
668
               if (newobj != null)
669
               {
670
                  ((EA.Element)newobj).Notes = dlg.textBox_DocName.Text;
671
                  ((EA.Element)newobj).Update();
672
               }
2088 ghuddy 673
            }
674
         }
675
      }
676
 
2094 ghuddy 677
 
678
      public void addTerminology()
2088 ghuddy 679
      {
680
         EA.ObjectType objType;
681
         object obj;
682
 
683
         objType = EA_Repository.GetTreeSelectedItem( out obj );
684
         if (objType == EA.ObjectType.otPackage)
685
         {
2094 ghuddy 686
            TerminologyForm dlg = new TerminologyForm();
687
            DialogResult dlgRes = dlg.ShowDialog();
688
            if (dlgRes == DialogResult.OK)
689
            {
690
               object newobj = null;
2088 ghuddy 691
 
2094 ghuddy 692
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_Term.Text, EA_Constants.EA_DocGenElementType);
693
               if (newobj != null)
694
               {
695
                  ((EA.Element)newobj).Notes = dlg.textBox_TermExpansion.Text;
696
                  ((EA.Element)newobj).Update();
697
               }
2088 ghuddy 698
            }
699
         }
700
      }
701
 
702
 
2098 ghuddy 703
 
704
      public string ReadTag(EA.Element theElement, string tagName)
705
      {
706
         string result;
707
 
708
         EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
709
         if (null != tag)
710
         {
711
            result = tag.Value;
712
         }
713
         else
714
         {
715
            result = "";
716
         }
717
         return result;
718
      }
719
 
720
 
721
      public bool WriteTag(EA.Element theElement, string tagName, string value)
722
      {
723
         bool result;
724
         EA.TaggedValue tag;
725
 
726
         tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
727
         if (null != tag)
728
         {
729
            tag.Value = value;
730
         }
731
         else
732
         {
733
            tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);
734
         }
735
 
736
         if (tag != null)
737
         {
738
            result = tag.Update();
739
         }
740
         else
741
         {
742
            result = false;
743
         }
744
         return result;
745
      }
746
 
747
 
2088 ghuddy 748
      #region Temporary or experimental code
749
 
750
 
2102 ghuddy 751
      private void parse_element(int parentId, EA.Element theElement, int recurse_level)
752
      {
753
         //if (parentId == 0 || parentId == theElement.ParentID)
754
         {
755
            EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
756
               "ParentId:"
757
               + parentId.ToString()
758
               + ", Level:"
759
               + recurse_level.ToString()
760
               + ", TreePos:"
761
               + theElement.TreePos.ToString() 
762
               + ", ELE-ParentID:"
763
               + theElement.ParentID.ToString()
764
               + ", ELE-PackageID:"
765
               + theElement.PackageID.ToString()
766
               + ", ELE-ElementID:"
767
               + theElement.ElementID.ToString()
768
               + ",  ELE-Name: " 
769
               + theElement.Name, -1);
770
 
771
            foreach(EA.Diagram theDiagram in theElement.Diagrams)
772
            {
773
               EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
774
                  "Level:"
775
                  + recurse_level.ToString() 
776
                  + ", ParentID:"
777
                  + theDiagram.ParentID.ToString()
778
                  + ", PackageID:"
779
                  + theDiagram.PackageID.ToString()
780
                  + ", DiagramID:"
781
                  + theDiagram.DiagramID.ToString()
782
                  + "  DIAGRAM: " 
783
                  + theDiagram.Name, -1);
784
            }
2088 ghuddy 785
 
2102 ghuddy 786
            foreach(EA.Element subElement in theElement.Elements)
787
            {
788
               parse_element(theElement.ElementID, subElement, recurse_level+1);
789
            }
790
         }
791
      }
792
 
793
 
2088 ghuddy 794
      /// <summary>
795
      /// Parse a package structure in a similar way to that taken when users are generating a word
796
      /// document, only here we simply write diagnostic text to the output tab.
797
      /// </summary>
798
      /// <param name="thePackage"></param>
799
      /// <param name="recurse_level"></param>
800
      private void parse_package(EA.Package thePackage, int recurse_level)
801
      {
802
         EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
803
                                      "Level:"
804
                                    + recurse_level.ToString() 
805
                                    + ", ParentID:"
806
                                    + thePackage.ParentID.ToString()
807
                                    + ", PackageID:"
808
                                    + thePackage.PackageID.ToString()
809
                                    + ",  PACKAGE: " 
810
                                    + thePackage.Name, -1);
811
 
812
         // default handling of diagrams
813
         foreach(EA.Diagram theDiagram in thePackage.Diagrams)
814
         {
2102 ghuddy 815
            if (theDiagram.ParentID == 0)
2088 ghuddy 816
            {
817
               EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2102 ghuddy 818
                  "Level:"
819
                  + recurse_level.ToString() 
2088 ghuddy 820
                  + ", ParentID:"
2102 ghuddy 821
                  + theDiagram.ParentID.ToString()
2088 ghuddy 822
                  + ", PackageID:"
2102 ghuddy 823
                  + theDiagram.PackageID.ToString()
824
                  + ", DiagramID:"
825
                  + theDiagram.DiagramID.ToString()
826
                  + "  DIAGRAM: " 
827
                  + theDiagram.Name, -1);
828
            }
829
         }
2088 ghuddy 830
 
2102 ghuddy 831
         foreach(EA.Element subElement in thePackage.Elements)
832
         {
833
            if (subElement.ParentID == 0 || thePackage.PackageID == subElement.ParentID)
834
               parse_element(thePackage.PackageID, subElement, recurse_level+1);
2088 ghuddy 835
         }
836
 
2102 ghuddy 837
//         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
838
//         EA.Element theElement = null;
839
//         int theElementsRelativeLevel = 0;
840
//         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
841
//         {
842
//            do
843
//            {
844
//               int theElementsRecurseLevel = recurse_level + theElementsRelativeLevel;
845
//
846
//               EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
847
//                    "Level:"
848
//                  + theElementsRecurseLevel.ToString()
849
//                  + ", "
850
//                  + theElement.TreePos.ToString() 
851
//                  + ", ParentID:"
852
//                  + theElement.ParentID.ToString()
853
//                  + ", PackageID:"
854
//                  + theElement.PackageID.ToString()
855
//                  + ", ElementID:"
856
//                  + theElement.ElementID.ToString()
857
//                  + ",  ELEMENT: " 
858
//                  + theElement.Name, -1);
859
//
860
//            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
861
//         }
862
 
2088 ghuddy 863
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
864
         {
2102 ghuddy 865
            parse_package(lowerLevelPackage, recurse_level+1);
2088 ghuddy 866
         }
867
      }
868
 
869
 
870
      /// <summary>
871
      /// Parses a specified package in a similar way to what would be done if a user were generating
872
      /// a word document, but here do nothing except write diagnostic text to the output tab.
873
      /// </summary>
874
      public void showDiscoveryOrder()
875
      {
876
         EA.ObjectType objType;
877
         object obj;
878
 
879
         objType = EA_Repository.GetTreeSelectedItem( out obj );
880
         if (objType == EA.ObjectType.otPackage)
881
         {
882
            EA.Package EA_ParentPackage = ((EA.Package)obj);
883
 
884
            EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Showing Object Discovery order for " + EA_ParentPackage.Name, -1);
885
 
886
            foreach(EA.Package thePackage in EA_ParentPackage.Packages)
887
            {
2102 ghuddy 888
               parse_package(thePackage, 1);
2088 ghuddy 889
            }
890
         }
891
         else
892
         {
893
            MessageBox.Show("You must select a package to parse");
894
         }
895
      }
896
 
897
 
898
      public void SaveVersionControlledPackage()
899
      {
900
         EA.ObjectType objType;
901
         object obj;
902
 
903
         objType = EA_Repository.GetTreeSelectedItem( out obj );
904
         if (objType == EA.ObjectType.otPackage)
905
         {
906
            EA.Package EA_Package = ((EA.Package)obj);
907
 
908
            if (EA_Package.IsControlled == true)
909
            {
910
               EA.Project EA_Project = EA_Repository.GetProjectInterface();
911
 
912
               EA_Project.SaveControlledPackage( EA_Package.PackageGUID );
913
 
914
               //EA_Project.SaveControlledPackage( EA_Project.GUIDtoXML( EA_Package.PackageGUID ) );
915
            }
916
            else
917
            {
918
               MessageBox.Show("The package selected is not version controlled");
919
            }
920
          }
921
         else
922
         {
923
            MessageBox.Show("You must select a package");
2094 ghuddy 924
         }
2088 ghuddy 925
      }
926
 
927
 
928
      #endregion
929
	}
930
 
931
 
932
}