Subversion Repositories DevTools

Rev

Rev 2153 | Rev 2159 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2153 Rev 2155
Line 22... Line 22...
22
      private Thread ourThread = null;
22
      private Thread ourThread = null;
23
 
23
 
24
      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_ReqPro";
24
      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_ReqPro";
25
      public static EA.Repository EA_Repository = null;
25
      public static EA.Repository EA_Repository = null;
26
 
26
 
-
 
27
      public static int abortRequests = 0;
27
      public static bool mustAbort = false;
28
      public static bool mustAbort = false;
28
 
29
 
29
      /// <summary>
30
      /// <summary>
30
      /// Called when EA initialised. Creates an output tab for the add in.
31
      /// Called when EA initialised. Creates an output tab for the add in.
31
      /// </summary>
32
      /// </summary>
Line 90... Line 91...
90
               return "-&EA_ReqPro";
91
               return "-&EA_ReqPro";
91
 
92
 
92
            case "-&EA_ReqPro":
93
            case "-&EA_ReqPro":
93
               if (ourThread != null && ourThread.IsAlive == true)
94
               if (ourThread != null && ourThread.IsAlive == true)
94
               {
95
               {
95
                  ar = new string[] {"&Abort Import"};
96
                  ar = new string[] {"&Abort Import/Export"};
96
                  return ar;
97
                  return ar;
97
               }
98
               }
98
               else
99
               else
99
               {
100
               {
100
                  ar = new string[]{
101
                  ar = new string[]{
101
                                   "&Import for Traceability Use",
102
                                   "&Import for Traceability Use",
102
                                   "&Display Change Log",
103
                                   "&Display Change Log",
103
                                   "&Import for Document Model Use",
104
                                   "&Import for Document Model Use",
-
 
105
                                   "&Export to ReqPro",
104
                                   "&Export to ReqPro Compatible CSV File",
106
                                   "&Export to ReqPro Compatible CSV File",
105
                                   "&Create Requirement Diagram",
107
                                   "&Create Requirement Diagram",
-
 
108
                                   "&Create Requirement Diagram Using Model Search"
106
                  };
109
                  };
107
                  return ar;
110
                  return ar;
108
               }
111
               }
109
         }
112
         }
110
 
113
 
Line 138... Line 141...
138
 
141
 
139
         if (IsProjectOpen(repository))
142
         if (IsProjectOpen(repository))
140
         {
143
         {
141
            switch (itemName)
144
            switch (itemName)
142
            {
145
            {
143
               case "&Abort Import":
146
               case "&Abort Import/Export":
144
               case "&Import for Document Model Use":
147
               case "&Import for Document Model Use":
-
 
148
               case "&Export to ReqPro":
145
               case "&Export to ReqPro Compatible CSV File":
149
               case "&Export to ReqPro Compatible CSV File":
146
               case "&Create Requirement Diagram":
150
               case "&Create Requirement Diagram":
-
 
151
               case "&Create Requirement Diagram Using Model Search":
147
               case "&Import for Traceability Use":
152
               case "&Import for Traceability Use":
148
                  isEnabled = true;
153
                  isEnabled = true;
149
                  break;
154
                  break;
150
 
155
 
151
               case "&Display Change Log":
156
               case "&Display Change Log":
Line 157... Line 162...
157
                  else
162
                  else
158
                  {
163
                  {
159
                     isEnabled = false;
164
                     isEnabled = false;
160
                  }
165
                  }
161
                  break;
166
                  break;
162
 
-
 
163
            }
167
            }
164
         }
168
         }
165
         else
169
         else
166
         {
170
         {
167
            isEnabled = false;
171
            isEnabled = false;
Line 173... Line 177...
173
      {
177
      {
174
         EA_Repository = repository;
178
         EA_Repository = repository;
175
 
179
 
176
         switch( itemName )
180
         switch( itemName )
177
         {
181
         {
-
 
182
            // This menu option appears only when a thread is active. It allows the user to initiate
-
 
183
            // an abort of the thread.
178
            case "&Abort Import":
184
            case "&Abort Import/Export":
179
               if (ourThread != null && ourThread.IsAlive == true)
185
               if (ourThread != null && ourThread.IsAlive == true)
180
               {
186
               {
-
 
187
                  if (abortRequests > 0)
-
 
188
                  {
-
 
189
                     // if user has made a second abort request, it is probably because the thread does not
-
 
190
                     // appear to be aborting. This can happen sometimes. I have noticed occasional lockups,
-
 
191
                     // and every time this happens, the thread seems to be locked up in a call to an EA
-
 
192
                     // automation interface function, so perhaps there is some wierd interaction between
-
 
193
                     // the thread and the use of the menu in the main EA process? Anyway, lets try to abort
-
 
194
                     // the thread now because it does not appear as if it is going to quit gracefully.
-
 
195
                     ourThread.Abort();
-
 
196
                     ReqProDatabase.close();
-
 
197
                     break;
-
 
198
                  }
-
 
199
                  else
-
 
200
                  {
-
 
201
                     // try to quit gracefully.
181
                  mustAbort = true;
202
                     mustAbort = true;
-
 
203
                     abortRequests++;
-
 
204
                  }
182
               }
205
               }
183
               break;
206
               break;
184
 
207
 
185
            case "&Import for Traceability Use":
208
            case "&Import for Traceability Use":
186
               if (ourThread == null || ourThread.IsAlive == false)
209
               if (ourThread == null || ourThread.IsAlive == false)
Line 198... Line 221...
198
                  ourThread.ApartmentState = ApartmentState.STA;
221
                  ourThread.ApartmentState = ApartmentState.STA;
199
                  ourThread.Start();
222
                  ourThread.Start();
200
               }
223
               }
201
               break;
224
               break;
202
 
225
 
-
 
226
            case "&Export to ReqPro":
-
 
227
               if (ourThread == null || ourThread.IsAlive == false)
-
 
228
               {
-
 
229
                  ourThread = new Thread(new ThreadStart(ExportToReqPro_Thread));
-
 
230
                  ourThread.ApartmentState = ApartmentState.STA;
-
 
231
                  ourThread.Start();
-
 
232
               }
-
 
233
               break;
-
 
234
 
203
            case "&Export to ReqPro Compatible CSV File":
235
            case "&Export to ReqPro Compatible CSV File":
204
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
236
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
205
               repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
237
               repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
206
               ExportToReqProCSVForm export_dlg = new ExportToReqProCSVForm();
238
               ExportToReqProCSVForm export_dlg = new ExportToReqProCSVForm();
207
               DialogResult dlgRes = export_dlg.ShowDialog();
239
               DialogResult dlgRes = export_dlg.ShowDialog();
Line 226... Line 258...
226
               allowedElementTypes.Add("Requirement");
258
               allowedElementTypes.Add("Requirement");
227
               //allowedElementTypes.Add("UseCase");
259
               //allowedElementTypes.Add("UseCase");
228
               ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
260
               ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
229
               EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
261
               EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
230
               EA_Utilities.findAndProcessPackageElements( thePackage, reqLister, true );
262
               EA_Utilities.findAndProcessPackageElements( thePackage, reqLister, true );
231
               EA.Diagram newDiagram = (EA.Diagram)thePackage.Diagrams.AddNew("Requirements","Logical");
263
               createRequirementDiagram(thePackage, reqLister.Elements);
232
               newDiagram.Update();
264
               break;
233
               thePackage.Update();
265
            }
234
 
266
 
235
               foreach (EA.Element element in reqLister.Elements)
267
            case "&Create Requirement Diagram Using Model Search":
-
 
268
            {
-
 
269
               QueryForm qf = new QueryForm();
-
 
270
               DialogResult qf_dlgRes = qf.ShowDialog();
-
 
271
               if (qf_dlgRes == DialogResult.OK)
236
               {
272
               {
237
                  EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
273
                  EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
238
                  newDiagramObject.ElementID = element.ElementID;
274
                  EA.Collection c = EA_Repository.GetElementsByQuery(qf.textBox_query_name.Text, qf.textBox_search_term.Text);
239
                  newDiagramObject.Update();
275
                  createRequirementDiagram(thePackage, c);
240
               }
276
               }
241
               newDiagram.DiagramObjects.Refresh();
-
 
242
               thePackage.Update();
-
 
243
               repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID, 
-
 
244
                  EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
-
 
245
               break;
277
               break;
246
 
-
 
247
            }
278
            }
248
 
279
 
249
         }
280
         }
250
      }
281
      }
251
 
282
 
-
 
283
      private void createRequirementDiagram(EA.Package containerPackage, EA.Collection c)
-
 
284
      {
-
 
285
         EA.Diagram newDiagram = (EA.Diagram)containerPackage.Diagrams.AddNew("Requirements","Logical");
-
 
286
         newDiagram.Update();
-
 
287
         containerPackage.Update();
-
 
288
 
-
 
289
         foreach (EA.Element element in c)
-
 
290
         {
-
 
291
            EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
-
 
292
            newDiagramObject.ElementID = element.ElementID;
-
 
293
            newDiagramObject.Update();
-
 
294
         }
-
 
295
         newDiagram.DiagramObjects.Refresh();
-
 
296
         containerPackage.Update();
-
 
297
         EA_Repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID, 
-
 
298
            EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
-
 
299
      }
-
 
300
 
-
 
301
      private void createRequirementDiagram(EA.Package containerPackage, ArrayList elements)
-
 
302
      {
-
 
303
         EA.Diagram newDiagram = (EA.Diagram)containerPackage.Diagrams.AddNew("Requirements","Logical");
-
 
304
         newDiagram.Update();
-
 
305
         containerPackage.Update();
-
 
306
 
-
 
307
         foreach (EA.Element element in elements)
-
 
308
         {
-
 
309
            EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
-
 
310
            newDiagramObject.ElementID = element.ElementID;
-
 
311
            newDiagramObject.Update();
-
 
312
         }
-
 
313
         newDiagram.DiagramObjects.Refresh();
-
 
314
         containerPackage.Update();
-
 
315
         EA_Repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID, 
-
 
316
            EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
-
 
317
      }
-
 
318
 
-
 
319
 
-
 
320
      /// <summary>
-
 
321
      /// Thread function for import for traceability use operation
-
 
322
      /// </summary>
252
      private static void ImportReqProDatabase_Thread()
323
      private static void ImportReqProDatabase_Thread()
253
      {
324
      {
-
 
325
         bool cancelled = false;
254
         mustAbort = false;
326
         mustAbort = false;
255
         ImportReqProDatabase import_parser = new ImportReqProDatabase();
327
         abortRequests = 0;
256
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
328
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
257
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
329
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
-
 
330
         ImportReqProDatabase import_parser = new ImportReqProDatabase();
258
         import_parser.prompt_and_parse(ReqProDB_Artifact.MODE.TRACEABILITY); 
331
         import_parser.prompt_and_parse(ReqProDB_Artifact.MODE.TRACEABILITY, out cancelled); 
259
         if (mustAbort)
332
         if (mustAbort)
-
 
333
         {
-
 
334
            EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME, "Import Aborted", -1);
260
            MessageBoxEx.Show("Import Aborted", "Progress");
335
            MessageBoxEx.Show("Import Aborted", "Progress");
-
 
336
         }
-
 
337
         else if (cancelled)
-
 
338
         {
-
 
339
            Main.WriteOutput("Import Cancelled",-1);
-
 
340
         }
-
 
341
         abortRequests = 0;
-
 
342
         ReqProDatabase.close();
261
      }
343
      }
262
 
344
 
-
 
345
      /// <summary>
-
 
346
      /// Thread function for import for document model use operation
-
 
347
      /// </summary>
263
      private static void CopyReqProDatabase_Thread()
348
      private static void CopyReqProDatabase_Thread()
264
      {
349
      {
-
 
350
         bool cancelled = false;
265
         mustAbort = false;
351
         mustAbort = false;
-
 
352
         abortRequests = 0;
266
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
353
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
267
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
354
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
268
         CopyReqProDatabase copy_parser = new CopyReqProDatabase();
355
         CopyReqProDatabase copy_parser = new CopyReqProDatabase();
269
         copy_parser.prompt_and_parse(ReqProDB_Artifact.MODE.DOC_MODEL);
356
         copy_parser.prompt_and_parse(ReqProDB_Artifact.MODE.DOC_MODEL, out cancelled);
270
         if (mustAbort)
357
         if (mustAbort)
-
 
358
         {
-
 
359
            EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME, "Import Aborted", -1);
271
            MessageBoxEx.Show("Import Aborted", "Progress");
360
            MessageBoxEx.Show("Import Aborted", "Progress");
-
 
361
         }
-
 
362
         else if (cancelled)
-
 
363
         {
-
 
364
            Main.WriteOutput("Import Cancelled",-1);
-
 
365
         }
-
 
366
         abortRequests = 0;
-
 
367
         ReqProDatabase.close();
-
 
368
      }
-
 
369
 
-
 
370
      /// <summary>
-
 
371
      /// Thread function for export to reqpro database operation
-
 
372
      /// </summary>
-
 
373
      private static void ExportToReqPro_Thread()
-
 
374
      {
-
 
375
         bool cancelled = false;
-
 
376
         mustAbort = false;
-
 
377
         abortRequests = 0;
-
 
378
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
-
 
379
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
-
 
380
         ExportToReqProDatabase export_parser = new ExportToReqProDatabase();
-
 
381
         export_parser.prompt_and_parse(ReqProDB_Artifact.MODE.EXPORT, out cancelled);
-
 
382
         if (mustAbort)
-
 
383
         {
-
 
384
            EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME, "Export Aborted", -1);
-
 
385
            MessageBoxEx.Show("Export Aborted", "Progress");
-
 
386
         }
-
 
387
         else if (cancelled)
-
 
388
         {
-
 
389
            Main.WriteOutput("Export Cancelled",-1);
-
 
390
         }
-
 
391
         abortRequests = 0;
-
 
392
         ReqProDatabase.close();
272
      }
393
      }
273
 
394
 
274
      public static void MessageBoxException(Exception exc)
395
      public static void MessageBoxException(Exception exc)
275
      {
396
      {
276
         MessageBoxException(exc, "Exception");
397
         MessageBoxException(exc, "Exception");
277
      }
398
      }
278
 
399
 
279
      public static void MessageBoxException(Exception exc, string caption)
400
      public static void MessageBoxException(Exception exc, string caption)
280
      {
401
      {
281
         MessageBoxEx.Show(exc.ToString(), caption);
402
         MessageBoxEx.Show(exc.ToString(), caption, MessageBoxIcon.Error);
-
 
403
      }
-
 
404
 
-
 
405
      public static void WriteOutput(string s, int id)
-
 
406
      {
-
 
407
         EA_Repository.WriteOutput( GUI_OUTPUT_TAB_NAME, s, id);
-
 
408
      }
-
 
409
 
-
 
410
      public static void ClearOutput()
-
 
411
      {
-
 
412
         EA_Repository.ClearOutput(GUI_OUTPUT_TAB_NAME);
-
 
413
      }
-
 
414
      public static void WriteSeperator()
-
 
415
      {
-
 
416
         EA_Repository.WriteOutput( GUI_OUTPUT_TAB_NAME, "----------------------------------------------------------------------------------------------------------------------", -1);
282
      }
417
      }
283
   }
418
   }
284
}
419
}