| 2177 |
brianf |
1 |
//-----------------------------------------------------------------------
|
|
|
2 |
// This is open source licensed under GPL
|
|
|
3 |
//
|
|
|
4 |
//
|
|
|
5 |
using System;
|
|
|
6 |
using System.Text;
|
|
|
7 |
using System.Globalization;
|
|
|
8 |
using System.Collections;
|
|
|
9 |
using System.Windows.Forms;
|
|
|
10 |
using ReqPro40;
|
|
|
11 |
using System.Threading;
|
|
|
12 |
|
|
|
13 |
namespace EA_ReqPro
|
|
|
14 |
{
|
|
|
15 |
public class Main
|
|
|
16 |
{
|
|
|
17 |
public String EA_Connect(EA.Repository Repository)
|
|
|
18 |
{
|
|
|
19 |
return "a string";
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
private Thread ourThread = null;
|
|
|
23 |
|
|
|
24 |
public readonly static String GUI_OUTPUT_TAB_NAME = "EA_ReqPro";
|
|
|
25 |
public static EA.Repository EA_Repository = null;
|
|
|
26 |
|
|
|
27 |
public static int abortRequests = 0;
|
|
|
28 |
public static bool mustAbort = false;
|
|
|
29 |
|
| 2161 |
ghuddy |
30 |
// EA_ReqPro Menu strings
|
|
|
31 |
private const string MI_Root = "-&EA ReqPro";
|
|
|
32 |
|
|
|
33 |
private const string MI_Separator = "-";
|
|
|
34 |
private const string MI_ImportForTraceabilityUse = "&Import for Traceability Use";
|
|
|
35 |
private const string MI_DisplayChangeLog = "&Display Change Log";
|
|
|
36 |
private const string MI_ImportForDocModelUse = "&Import for Document Model Use";
|
|
|
37 |
private const string MI_ExportToReqPro = "&Export to ReqPro";
|
|
|
38 |
private const string MI_ExportToReqProCSV = "&Export to ReqPro Compatible CSV File";
|
|
|
39 |
private const string MI_CreateReqDiagram = "&Create Requirement Diagram";
|
|
|
40 |
private const string MI_CreateReqDiagramUsingSrch = "&Create Requirement Diagram Using Model Search";
|
|
|
41 |
private const string MI_About = "&About...";
|
|
|
42 |
private const string MI_Abort = "&Abort Import/Export";
|
|
|
43 |
|
|
|
44 |
private string[] MI_RootMenu = new string[] { MI_ImportForTraceabilityUse,
|
|
|
45 |
MI_DisplayChangeLog,
|
|
|
46 |
MI_Separator,
|
|
|
47 |
MI_ImportForDocModelUse,
|
|
|
48 |
MI_Separator,
|
|
|
49 |
MI_ExportToReqPro,
|
|
|
50 |
MI_ExportToReqProCSV,
|
|
|
51 |
MI_Separator,
|
|
|
52 |
MI_CreateReqDiagram,
|
|
|
53 |
MI_CreateReqDiagramUsingSrch,
|
|
|
54 |
MI_Separator,
|
|
|
55 |
MI_About };
|
| 2177 |
brianf |
56 |
|
|
|
57 |
private string[] MI_AbortMenu = new string[] { MI_Abort };
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
/// <summary>
|
|
|
61 |
/// Called when EA initialised. Creates an output tab for the add in.
|
|
|
62 |
/// </summary>
|
|
|
63 |
/// <param name="repository"></param>
|
|
|
64 |
public void EA_OnPostInitialized(EA.Repository repository)
|
|
|
65 |
{
|
|
|
66 |
repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);
|
|
|
67 |
repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
public void EA_Disconnect()
|
|
|
72 |
{
|
|
|
73 |
GC.Collect();
|
|
|
74 |
GC.WaitForPendingFinalizers();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
/// <summary>
|
|
|
79 |
/// Event called when user clicks on an entry in the output
|
|
|
80 |
/// window. If an element has been associated with the message, it will
|
|
|
81 |
/// be automatically selected in the project browser.
|
|
|
82 |
/// </summary>
|
|
|
83 |
/// <param name="repository"></param>
|
|
|
84 |
/// <param name="outputTabNea"></param>
|
|
|
85 |
/// <param name="lineText"></param>
|
|
|
86 |
/// <param name="lineIdentifier"></param>
|
|
|
87 |
public void EA_OnOutputItemClicked( EA.Repository repository,
|
|
|
88 |
String outputTabName,
|
|
|
89 |
String lineText,
|
|
|
90 |
Int32 identifier)
|
|
|
91 |
{
|
|
|
92 |
if ((outputTabName == GUI_OUTPUT_TAB_NAME) && (identifier > 0))
|
|
|
93 |
{
|
|
|
94 |
try
|
|
|
95 |
{
|
|
|
96 |
EA.Element element = repository.GetElementByID(identifier);
|
|
|
97 |
if (element.MetaType == "Package")
|
|
|
98 |
{
|
|
|
99 |
EA.Package package = repository.GetPackageByID(element.PackageID);
|
|
|
100 |
repository.ShowInProjectView(package);
|
|
|
101 |
}
|
|
|
102 |
else
|
|
|
103 |
{
|
|
|
104 |
repository.ShowInProjectView(element);
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
catch
|
|
|
108 |
{
|
|
|
109 |
try
|
|
|
110 |
{
|
|
|
111 |
EA.Package package = repository.GetPackageByID(identifier);
|
|
|
112 |
repository.ShowInProjectView(package);
|
|
|
113 |
}
|
|
|
114 |
catch
|
|
|
115 |
{
|
|
|
116 |
try
|
|
|
117 |
{
|
|
|
118 |
EA.Diagram diagram = repository.GetDiagramByID(identifier);
|
|
|
119 |
repository.ShowInProjectView(diagram);
|
|
|
120 |
}
|
|
|
121 |
catch
|
|
|
122 |
{
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
public object EA_GetMenuItems(EA.Repository repository, string location, string menu)
|
|
|
132 |
{
|
|
|
133 |
switch( menu )
|
|
|
134 |
{
|
|
|
135 |
case "":
|
|
|
136 |
return MI_Root;
|
|
|
137 |
|
|
|
138 |
case MI_Root:
|
|
|
139 |
if (ourThread != null && ourThread.IsAlive == true)
|
|
|
140 |
{
|
|
|
141 |
return MI_AbortMenu;
|
|
|
142 |
}
|
|
|
143 |
else
|
|
|
144 |
{
|
|
|
145 |
return MI_RootMenu;
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
return "";
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
bool IsProjectOpen(EA.Repository Repository)
|
|
|
154 |
{
|
|
|
155 |
try
|
|
|
156 |
{
|
|
|
157 |
EA.Collection collection = Repository.Models;
|
|
|
158 |
return true;
|
|
|
159 |
}
|
|
|
160 |
catch
|
|
|
161 |
{
|
|
|
162 |
return false;
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
public void EA_GetMenuState(EA.Repository repository, string location, string menuName, string itemName, ref bool isEnabled, ref bool isChecked)
|
|
|
168 |
{
|
|
|
169 |
EA_Repository = repository;
|
|
|
170 |
|
|
|
171 |
object o;
|
|
|
172 |
EA.ObjectType type;
|
|
|
173 |
|
|
|
174 |
isChecked = false;
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
if (IsProjectOpen(repository))
|
|
|
178 |
{
|
|
|
179 |
switch (itemName)
|
|
|
180 |
{
|
|
|
181 |
case MI_Abort:
|
|
|
182 |
case MI_ImportForDocModelUse:
|
|
|
183 |
case MI_ExportToReqPro:
|
|
|
184 |
case MI_ExportToReqProCSV:
|
|
|
185 |
case MI_CreateReqDiagram:
|
|
|
186 |
case MI_CreateReqDiagramUsingSrch:
|
|
|
187 |
case MI_ImportForTraceabilityUse:
|
|
|
188 |
isEnabled = true;
|
|
|
189 |
break;
|
|
|
190 |
|
|
|
191 |
case MI_DisplayChangeLog:
|
|
|
192 |
type = repository.GetTreeSelectedItem(out o);
|
|
|
193 |
if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Name.StartsWith("Change Log")))
|
|
|
194 |
{
|
|
|
195 |
isEnabled = true;
|
|
|
196 |
}
|
|
|
197 |
else
|
|
|
198 |
{
|
|
|
199 |
isEnabled = false;
|
|
|
200 |
}
|
|
|
201 |
break;
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
else
|
|
|
205 |
{
|
|
|
206 |
isEnabled = false;
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
public void EA_MenuClick(EA.Repository repository, string location, string menu, string itemName)
|
|
|
212 |
{
|
|
|
213 |
EA_Repository = repository;
|
|
|
214 |
|
|
|
215 |
switch( itemName )
|
|
|
216 |
{
|
|
|
217 |
// This menu option appears only when a thread is active. It allows the user to initiate
|
|
|
218 |
// an abort of the thread.
|
|
|
219 |
case MI_Abort:
|
|
|
220 |
if (ourThread != null && ourThread.IsAlive == true)
|
|
|
221 |
{
|
|
|
222 |
if (abortRequests > 0)
|
|
|
223 |
{
|
|
|
224 |
// if user has made a second abort request, it is probably because the thread does not
|
|
|
225 |
// appear to be aborting. This can happen sometimes. I have noticed occasional lockups,
|
|
|
226 |
// and every time this happens, the thread seems to be locked up in a call to an EA
|
|
|
227 |
// automation interface function, so perhaps there is some wierd interaction between
|
|
|
228 |
// the thread and the use of the menu in the main EA process? Anyway, lets try to abort
|
|
|
229 |
// the thread now because it does not appear as if it is going to quit gracefully.
|
|
|
230 |
ourThread.Abort();
|
|
|
231 |
ReqProDatabase.close();
|
|
|
232 |
break;
|
|
|
233 |
}
|
|
|
234 |
else
|
|
|
235 |
{
|
|
|
236 |
// try to quit gracefully.
|
|
|
237 |
mustAbort = true;
|
|
|
238 |
abortRequests++;
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
break;
|
|
|
242 |
|
|
|
243 |
case MI_ImportForTraceabilityUse:
|
|
|
244 |
if (ourThread == null || ourThread.IsAlive == false)
|
|
|
245 |
{
|
|
|
246 |
ourThread = new Thread(new ThreadStart(ImportReqProDatabase_Thread));
|
|
|
247 |
ourThread.SetApartmentState(ApartmentState.STA);
|
|
|
248 |
ourThread.Start();
|
|
|
249 |
}
|
|
|
250 |
break;
|
|
|
251 |
|
|
|
252 |
case MI_ImportForDocModelUse:
|
|
|
253 |
if (ourThread == null || ourThread.IsAlive == false)
|
|
|
254 |
{
|
|
|
255 |
ourThread = new Thread(new ThreadStart(CopyReqProDatabase_Thread));
|
|
|
256 |
ourThread.SetApartmentState(ApartmentState.STA);
|
|
|
257 |
ourThread.Start();
|
|
|
258 |
}
|
|
|
259 |
break;
|
|
|
260 |
|
|
|
261 |
case MI_ExportToReqPro:
|
|
|
262 |
if (ourThread == null || ourThread.IsAlive == false)
|
|
|
263 |
{
|
|
|
264 |
ourThread = new Thread(new ThreadStart(ExportToReqPro_Thread));
|
|
|
265 |
ourThread.SetApartmentState(ApartmentState.STA);
|
|
|
266 |
ourThread.Start();
|
|
|
267 |
}
|
|
|
268 |
break;
|
|
|
269 |
|
|
|
270 |
case MI_ExportToReqProCSV:
|
|
|
271 |
repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
|
|
|
272 |
repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
|
|
|
273 |
ExportToReqProCSVForm export_dlg = new ExportToReqProCSVForm();
|
|
|
274 |
DialogResult dlgRes = export_dlg.ShowDialog();
|
|
|
275 |
if (dlgRes == DialogResult.OK)
|
|
|
276 |
{
|
|
|
277 |
export_dlg.Export();
|
|
|
278 |
}
|
|
|
279 |
break;
|
|
|
280 |
|
|
|
281 |
case MI_DisplayChangeLog:
|
|
|
282 |
{
|
|
|
283 |
ImportReqProDatabase import_parser = new ImportReqProDatabase();
|
|
|
284 |
EA.Element changeLog = (EA.Element)repository.GetTreeSelectedObject();
|
|
|
285 |
repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
|
|
|
286 |
import_parser.displayChangeLog(changeLog);
|
|
|
287 |
break;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
case MI_CreateReqDiagram:
|
|
|
291 |
{
|
|
|
292 |
ArrayList allowedElementTypes = new ArrayList();
|
|
|
293 |
allowedElementTypes.Add("Requirement");
|
|
|
294 |
//allowedElementTypes.Add("UseCase");
|
|
|
295 |
EA_ElementAccumulator reqLister = new EA_ElementAccumulator(allowedElementTypes);
|
|
|
296 |
EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
|
|
|
297 |
EA_Parsing.findAndProcessPackageElements( thePackage, reqLister, true );
|
|
|
298 |
createRequirementDiagram(thePackage, reqLister.Elements);
|
|
|
299 |
break;
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
case MI_CreateReqDiagramUsingSrch:
|
|
|
303 |
{
|
|
|
304 |
QueryForm qf = new QueryForm();
|
|
|
305 |
DialogResult qf_dlgRes = qf.ShowDialog();
|
|
|
306 |
if (qf_dlgRes == DialogResult.OK)
|
|
|
307 |
{
|
|
|
308 |
EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
|
|
|
309 |
EA.Collection c = EA_Repository.GetElementsByQuery(qf.textBox_query_name.Text, qf.textBox_search_term.Text);
|
|
|
310 |
createRequirementDiagram(thePackage, c);
|
|
|
311 |
}
|
|
|
312 |
break;
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
case MI_About:
|
| 2169 |
ghuddy |
316 |
AboutForm anAbout = new AboutForm();
|
|
|
317 |
anAbout.ShowDialog();
|
| 2177 |
brianf |
318 |
break;
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
private void createRequirementDiagram(EA.Package containerPackage, EA.Collection c)
|
|
|
323 |
{
|
|
|
324 |
EA.Diagram newDiagram = (EA.Diagram)containerPackage.Diagrams.AddNew("Requirements","Logical");
|
|
|
325 |
newDiagram.Update();
|
|
|
326 |
containerPackage.Update();
|
|
|
327 |
|
|
|
328 |
foreach (EA.Element element in c)
|
|
|
329 |
{
|
|
|
330 |
EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
|
|
|
331 |
newDiagramObject.ElementID = element.ElementID;
|
|
|
332 |
newDiagramObject.Update();
|
|
|
333 |
}
|
|
|
334 |
newDiagram.DiagramObjects.Refresh();
|
|
|
335 |
containerPackage.Update();
|
|
|
336 |
EA_Repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID,
|
|
|
337 |
EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
private void createRequirementDiagram(EA.Package containerPackage, ArrayList elements)
|
|
|
341 |
{
|
|
|
342 |
EA.Diagram newDiagram = (EA.Diagram)containerPackage.Diagrams.AddNew("Requirements","Logical");
|
|
|
343 |
newDiagram.Update();
|
|
|
344 |
containerPackage.Update();
|
|
|
345 |
|
|
|
346 |
foreach (EA.Element element in elements)
|
|
|
347 |
{
|
|
|
348 |
EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
|
|
|
349 |
newDiagramObject.ElementID = element.ElementID;
|
|
|
350 |
newDiagramObject.Update();
|
|
|
351 |
}
|
|
|
352 |
newDiagram.DiagramObjects.Refresh();
|
|
|
353 |
containerPackage.Update();
|
|
|
354 |
EA_Repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID,
|
|
|
355 |
EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
/// <summary>
|
|
|
360 |
/// Thread function for import for traceability use operation
|
|
|
361 |
/// </summary>
|
|
|
362 |
private static void ImportReqProDatabase_Thread()
|
|
|
363 |
{
|
|
|
364 |
bool cancelled = false;
|
|
|
365 |
mustAbort = false;
|
|
|
366 |
abortRequests = 0;
|
|
|
367 |
EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
|
|
|
368 |
EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
|
|
|
369 |
ImportReqProDatabase import_parser = new ImportReqProDatabase();
|
|
|
370 |
import_parser.prompt_and_parse(ReqProDB_Artifact.MODE.TRACEABILITY, out cancelled);
|
|
|
371 |
if (mustAbort)
|
|
|
372 |
{
|
|
|
373 |
EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME, "Import Aborted", -1);
|
|
|
374 |
MessageBoxEx.Show("Import Aborted", "Progress");
|
|
|
375 |
}
|
|
|
376 |
else if (cancelled)
|
|
|
377 |
{
|
|
|
378 |
Main.WriteOutput("Import Cancelled",-1);
|
|
|
379 |
}
|
|
|
380 |
abortRequests = 0;
|
|
|
381 |
ReqProDatabase.close();
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
/// <summary>
|
|
|
385 |
/// Thread function for import for document model use operation
|
|
|
386 |
/// </summary>
|
|
|
387 |
private static void CopyReqProDatabase_Thread()
|
|
|
388 |
{
|
|
|
389 |
bool cancelled = false;
|
|
|
390 |
mustAbort = false;
|
|
|
391 |
abortRequests = 0;
|
|
|
392 |
EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
|
|
|
393 |
EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
|
|
|
394 |
CopyReqProDatabase copy_parser = new CopyReqProDatabase();
|
|
|
395 |
copy_parser.prompt_and_parse(ReqProDB_Artifact.MODE.DOC_MODEL, out cancelled);
|
|
|
396 |
if (mustAbort)
|
|
|
397 |
{
|
|
|
398 |
EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME, "Import Aborted", -1);
|
|
|
399 |
MessageBoxEx.Show("Import Aborted", "Progress");
|
|
|
400 |
}
|
|
|
401 |
else if (cancelled)
|
|
|
402 |
{
|
|
|
403 |
Main.WriteOutput("Import Cancelled",-1);
|
|
|
404 |
}
|
|
|
405 |
abortRequests = 0;
|
|
|
406 |
ReqProDatabase.close();
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
/// <summary>
|
|
|
410 |
/// Thread function for export to reqpro database operation
|
|
|
411 |
/// </summary>
|
|
|
412 |
private static void ExportToReqPro_Thread()
|
|
|
413 |
{
|
|
|
414 |
bool cancelled = false;
|
|
|
415 |
mustAbort = false;
|
|
|
416 |
abortRequests = 0;
|
|
|
417 |
EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
|
|
|
418 |
EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
|
|
|
419 |
ExportToReqProDatabase export_parser = new ExportToReqProDatabase();
|
|
|
420 |
export_parser.prompt_and_parse(ReqProDB_Artifact.MODE.EXPORT, out cancelled);
|
|
|
421 |
if (mustAbort)
|
|
|
422 |
{
|
|
|
423 |
EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME, "Export Aborted", -1);
|
|
|
424 |
MessageBoxEx.Show("Export Aborted", "Progress");
|
|
|
425 |
}
|
|
|
426 |
else if (cancelled)
|
|
|
427 |
{
|
|
|
428 |
Main.WriteOutput("Export Cancelled",-1);
|
|
|
429 |
}
|
|
|
430 |
abortRequests = 0;
|
|
|
431 |
ReqProDatabase.close();
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
public static void MessageBoxException(Exception exc)
|
|
|
435 |
{
|
|
|
436 |
MessageBoxException(exc, "Exception");
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
public static void MessageBoxException(Exception exc, string caption)
|
|
|
440 |
{
|
|
|
441 |
MessageBoxEx.Show(exc.ToString(), caption, MessageBoxIcon.Error);
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
public static void WriteOutput(string s, int id)
|
|
|
445 |
{
|
|
|
446 |
EA_Repository.WriteOutput( GUI_OUTPUT_TAB_NAME, s, id);
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
public static void ClearOutput()
|
|
|
450 |
{
|
|
|
451 |
EA_Repository.ClearOutput(GUI_OUTPUT_TAB_NAME);
|
|
|
452 |
}
|
|
|
453 |
public static void WriteSeperator()
|
|
|
454 |
{
|
|
|
455 |
EA_Repository.WriteOutput( GUI_OUTPUT_TAB_NAME, "----------------------------------------------------------------------------------------------------------------------", -1);
|
|
|
456 |
}
|
|
|
457 |
}
|
|
|
458 |
}
|