Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
2139 ghuddy 1
//-----------------------------------------------------------------------
2
// This is open source licensed under GPL
3
//
4
//
5
using System;
6
using System.Text;
7
using System.Globalization;
2141 ghuddy 8
using System.Collections;
2139 ghuddy 9
using System.Windows.Forms;
10
using ReqPro40;
11
 
12
namespace EA_ReqPro
13
{
14
   public class Main
15
   {
2141 ghuddy 16
      public String EA_Connect(EA.Repository Repository)
2139 ghuddy 17
      {
18
         return "a string";
19
      }
20
 
21
 
2141 ghuddy 22
      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_ReqPro";
2139 ghuddy 23
 
24
 
25
 
2141 ghuddy 26
      /// <summary>
27
      /// Called when EA initialised. Creates an output tab for the add in.
28
      /// </summary>
29
      /// <param name="repository"></param>
30
      public void EA_OnPostInitialized(EA.Repository repository)
31
      {
32
         repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);
33
         repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
34
      }
35
 
36
 
37
      public void EA_Disconnect()
38
      {
39
         GC.Collect();
40
         GC.WaitForPendingFinalizers();
41
      }
2139 ghuddy 42
 
43
 
2141 ghuddy 44
      /// <summary>
45
      /// Event called when user clicks on an entry in the output
46
      /// window. If an element has been associated with the message, it will
47
      /// be automatically selected in the project browser.
48
      /// </summary>
49
      /// <param name="repository"></param>
50
      /// <param name="outputTabNea"></param>
51
      /// <param name="lineText"></param>
52
      /// <param name="lineIdentifier"></param>
53
      public void EA_OnOutputItemClicked( EA.Repository repository,
54
                                          String outputTabName,
55
                                          String lineText,
56
                                          Int32 identifier)
57
      {
58
         if ((outputTabName == GUI_OUTPUT_TAB_NAME) && (identifier > 0))
59
         {
60
            try
61
            {
62
               EA.Element element = repository.GetElementByID(identifier);
63
               repository.ShowInProjectView(element);
64
            }
65
            catch
66
            {
67
               try
68
               {
69
                  EA.Package package = repository.GetPackageByID(identifier);
70
                  repository.ShowInProjectView(package);
71
               }
72
               catch
73
               {
74
               }
75
            }
76
         }
77
      }
2139 ghuddy 78
 
2141 ghuddy 79
 
80
      public object EA_GetMenuItems(EA.Repository repository, string location, string menu)
2139 ghuddy 81
      {
82
         switch( menu )
83
         {
84
            case "":
85
               return "-&EA_ReqPro";
86
 
2145 ghuddy 87
            case "-&EA_ReqPro":
2141 ghuddy 88
            {
89
               string[] ar = {
90
                                "&Import for Traceability Use",
91
                                "&Display Change Log",
92
                                "&Import for Document Model Use",
93
                                "&Export to ReqPro Compatible CSV File",
2145 ghuddy 94
                                "&Create Requirement Diagram",
2139 ghuddy 95
                             };
96
               return ar;
2141 ghuddy 97
            }
2139 ghuddy 98
         }
99
         return "";
100
      }
101
 
102
 
103
      bool IsProjectOpen(EA.Repository Repository)
104
      {
105
         try
106
         {
107
            EA.Collection collection = Repository.Models;
108
            return true;
109
         }
110
         catch
111
         {
112
            return false;
113
         }
114
      }
115
 
116
 
117
      public void EA_GetMenuState(EA.Repository repository, string location, string menuName, string itemName, ref bool isEnabled, ref bool isChecked)
118
      {
119
         object o;
120
         EA.ObjectType type;
121
 
122
         isChecked = false;
123
 
124
         if (IsProjectOpen(repository))
125
         {
126
            switch (itemName)
127
            {
2141 ghuddy 128
               case "&Import for Document Model Use":
129
               case "&Export to ReqPro Compatible CSV File":
2145 ghuddy 130
               case "&Create Requirement Diagram":
131
               case "&Import for Traceability Use":
2141 ghuddy 132
                  isEnabled = true;
133
                  break;
134
 
135
               case "&Display Change Log":
136
                  type = repository.GetTreeSelectedItem(out o);
137
                  if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Name == "Change Log"))
2139 ghuddy 138
                  {
139
                     isEnabled = true;
140
                  }
141
                  else
142
                  {
143
                     isEnabled = false;
144
                  }
145
                  break;
146
 
147
            }
148
         }
149
         else
150
         {
151
            isEnabled = false;
152
         }
153
      }
154
 
155
 
156
      public void EA_MenuClick(EA.Repository repository, string location, string menu, string itemName)
157
      {
158
         switch( itemName )
159
         {
2141 ghuddy 160
            case "&Import for Traceability Use":
161
            {
162
               ImportReqProDatabase import_parser = new ImportReqProDatabase(repository);
163
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
2145 ghuddy 164
               import_parser.prompt_and_parse(repository, ReqProDB_Artifact.MODE.TRACEABILITY); 
2139 ghuddy 165
               break;
2141 ghuddy 166
            }
2139 ghuddy 167
 
2141 ghuddy 168
            case "&Import for Document Model Use":
169
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
170
               CopyReqProDatabase copy_parser = new CopyReqProDatabase(repository);
2145 ghuddy 171
               copy_parser.prompt_and_parse(repository, ReqProDB_Artifact.MODE.DOC_MODEL);
2139 ghuddy 172
               break;
173
 
2141 ghuddy 174
            case "&Export to ReqPro Compatible CSV File":
175
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
176
               ExportToReqProCSVForm export_dlg = new ExportToReqProCSVForm();
177
               DialogResult dlgRes = export_dlg.ShowDialog();
178
               if (dlgRes == DialogResult.OK)
2139 ghuddy 179
               {
2141 ghuddy 180
                  export_dlg.Export(repository);
2139 ghuddy 181
               }
2141 ghuddy 182
               break;
2139 ghuddy 183
 
2141 ghuddy 184
            case "&Display Change Log":
2139 ghuddy 185
            {
2141 ghuddy 186
               ImportReqProDatabase import_parser = new ImportReqProDatabase(repository);
187
               EA.Element changeLog = (EA.Element)repository.GetTreeSelectedObject();
188
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
189
               import_parser.displayChangeLog(repository, changeLog);
190
               break;
2139 ghuddy 191
            }
2145 ghuddy 192
 
193
            case "&Create Requirement Diagram":
194
            {
195
               EA_Utilities EA_Utils = new EA_Utilities(repository);
196
               ArrayList allowedElementTypes = new ArrayList();
197
               allowedElementTypes.Add("Requirement");
198
               //allowedElementTypes.Add("UseCase");
199
               ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
200
               EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
201
               EA_Utils.findAndProcessPackageElements( thePackage, reqLister, true );
202
               EA.Diagram newDiagram = (EA.Diagram)thePackage.Diagrams.AddNew("Requirements","Logical");
203
               newDiagram.Update();
204
               thePackage.Update();
205
 
206
               foreach (EA.Element element in reqLister.Elements)
207
               {
208
                  EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
209
                  newDiagramObject.ElementID = element.ElementID;
210
                  newDiagramObject.Update();
211
               }
212
               newDiagram.DiagramObjects.Refresh();
213
               thePackage.Update();
214
               repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID, 
215
                  EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
216
               break;
217
 
218
            }
219
 
2139 ghuddy 220
         }
221
      }
222
 
223
 
224
   }
225
}