Subversion Repositories DevTools

Rev

Rev 2151 | Rev 2155 | 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;
2151 ghuddy 11
using System.Threading;
2139 ghuddy 12
 
13
namespace EA_ReqPro
14
{
15
   public class Main
16
   {
2141 ghuddy 17
      public String EA_Connect(EA.Repository Repository)
2139 ghuddy 18
      {
19
         return "a string";
20
      }
21
 
2151 ghuddy 22
      private Thread ourThread = null;
2139 ghuddy 23
 
2141 ghuddy 24
      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_ReqPro";
2151 ghuddy 25
      public static EA.Repository EA_Repository = null;
2139 ghuddy 26
 
2151 ghuddy 27
      public static bool mustAbort = false;
2139 ghuddy 28
 
2141 ghuddy 29
      /// <summary>
30
      /// Called when EA initialised. Creates an output tab for the add in.
31
      /// </summary>
32
      /// <param name="repository"></param>
33
      public void EA_OnPostInitialized(EA.Repository repository)
34
      {
35
         repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);
36
         repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
37
      }
38
 
39
 
40
      public void EA_Disconnect()
41
      {
42
         GC.Collect();
43
         GC.WaitForPendingFinalizers();
44
      }
2139 ghuddy 45
 
46
 
2141 ghuddy 47
      /// <summary>
48
      /// Event called when user clicks on an entry in the output
49
      /// window. If an element has been associated with the message, it will
50
      /// be automatically selected in the project browser.
51
      /// </summary>
52
      /// <param name="repository"></param>
53
      /// <param name="outputTabNea"></param>
54
      /// <param name="lineText"></param>
55
      /// <param name="lineIdentifier"></param>
56
      public void EA_OnOutputItemClicked( EA.Repository repository,
57
                                          String outputTabName,
58
                                          String lineText,
59
                                          Int32 identifier)
60
      {
61
         if ((outputTabName == GUI_OUTPUT_TAB_NAME) && (identifier > 0))
62
         {
63
            try
64
            {
65
               EA.Element element = repository.GetElementByID(identifier);
66
               repository.ShowInProjectView(element);
67
            }
68
            catch
69
            {
70
               try
71
               {
72
                  EA.Package package = repository.GetPackageByID(identifier);
73
                  repository.ShowInProjectView(package);
74
               }
75
               catch
76
               {
77
               }
78
            }
79
         }
80
      }
2139 ghuddy 81
 
2141 ghuddy 82
 
83
      public object EA_GetMenuItems(EA.Repository repository, string location, string menu)
2139 ghuddy 84
      {
2151 ghuddy 85
         string[] ar;
86
 
2139 ghuddy 87
         switch( menu )
88
         {
89
            case "":
90
               return "-&EA_ReqPro";
91
 
2145 ghuddy 92
            case "-&EA_ReqPro":
2151 ghuddy 93
               if (ourThread != null && ourThread.IsAlive == true)
94
               {
95
                  ar = new string[] {"&Abort Import"};
96
                  return ar;
97
               }
98
               else
99
               {
100
                  ar = new string[]{
101
                                   "&Import for Traceability Use",
102
                                   "&Display Change Log",
103
                                   "&Import for Document Model Use",
104
                                   "&Export to ReqPro Compatible CSV File",
105
                                   "&Create Requirement Diagram",
106
                  };
107
                  return ar;
108
               }
2139 ghuddy 109
         }
2151 ghuddy 110
 
2139 ghuddy 111
         return "";
112
      }
113
 
114
 
115
      bool IsProjectOpen(EA.Repository Repository)
116
      {
117
         try
118
         {
119
            EA.Collection collection = Repository.Models;
120
            return true;
121
         }
122
         catch
123
         {
124
            return false;
125
         }
126
      }
127
 
128
 
129
      public void EA_GetMenuState(EA.Repository repository, string location, string menuName, string itemName, ref bool isEnabled, ref bool isChecked)
130
      {
2151 ghuddy 131
         EA_Repository = repository;
132
 
2139 ghuddy 133
         object o;
134
         EA.ObjectType type;
135
 
136
         isChecked = false;
137
 
2151 ghuddy 138
 
2139 ghuddy 139
         if (IsProjectOpen(repository))
140
         {
141
            switch (itemName)
142
            {
2151 ghuddy 143
               case "&Abort Import":
2141 ghuddy 144
               case "&Import for Document Model Use":
145
               case "&Export to ReqPro Compatible CSV File":
2145 ghuddy 146
               case "&Create Requirement Diagram":
147
               case "&Import for Traceability Use":
2141 ghuddy 148
                  isEnabled = true;
149
                  break;
150
 
151
               case "&Display Change Log":
152
                  type = repository.GetTreeSelectedItem(out o);
153
                  if ( (type == EA.ObjectType.otElement) && (((EA.Element)o).Name == "Change Log"))
2139 ghuddy 154
                  {
155
                     isEnabled = true;
156
                  }
157
                  else
158
                  {
159
                     isEnabled = false;
160
                  }
161
                  break;
162
 
163
            }
164
         }
165
         else
166
         {
167
            isEnabled = false;
168
         }
169
      }
170
 
171
 
172
      public void EA_MenuClick(EA.Repository repository, string location, string menu, string itemName)
173
      {
2151 ghuddy 174
         EA_Repository = repository;
175
 
2139 ghuddy 176
         switch( itemName )
177
         {
2151 ghuddy 178
            case "&Abort Import":
179
               if (ourThread != null && ourThread.IsAlive == true)
180
               {
181
                  mustAbort = true;
182
               }
183
               break;
184
 
2141 ghuddy 185
            case "&Import for Traceability Use":
2151 ghuddy 186
               if (ourThread == null || ourThread.IsAlive == false)
187
               {
188
                  ourThread = new Thread(new ThreadStart(ImportReqProDatabase_Thread));
189
                  ourThread.ApartmentState = ApartmentState.STA;
190
                  ourThread.Start();
191
               }
2139 ghuddy 192
               break;
193
 
2141 ghuddy 194
            case "&Import for Document Model Use":
2151 ghuddy 195
               if (ourThread == null || ourThread.IsAlive == false)
196
               {
197
                  ourThread = new Thread(new ThreadStart(CopyReqProDatabase_Thread));
198
                  ourThread.ApartmentState = ApartmentState.STA;
199
                  ourThread.Start();
200
               }
2139 ghuddy 201
               break;
202
 
2141 ghuddy 203
            case "&Export to ReqPro Compatible CSV File":
204
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
2151 ghuddy 205
               repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
2141 ghuddy 206
               ExportToReqProCSVForm export_dlg = new ExportToReqProCSVForm();
207
               DialogResult dlgRes = export_dlg.ShowDialog();
208
               if (dlgRes == DialogResult.OK)
2139 ghuddy 209
               {
2151 ghuddy 210
                  export_dlg.Export();
2139 ghuddy 211
               }
2141 ghuddy 212
               break;
2139 ghuddy 213
 
2141 ghuddy 214
            case "&Display Change Log":
2139 ghuddy 215
            {
2151 ghuddy 216
               ImportReqProDatabase import_parser = new ImportReqProDatabase();
2141 ghuddy 217
               EA.Element changeLog = (EA.Element)repository.GetTreeSelectedObject();
218
               repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
2151 ghuddy 219
               import_parser.displayChangeLog(changeLog);
2141 ghuddy 220
               break;
2139 ghuddy 221
            }
2145 ghuddy 222
 
223
            case "&Create Requirement Diagram":
224
            {
225
               ArrayList allowedElementTypes = new ArrayList();
226
               allowedElementTypes.Add("Requirement");
227
               //allowedElementTypes.Add("UseCase");
228
               ElementAccumulator reqLister = new ElementAccumulator(allowedElementTypes);
229
               EA.Package thePackage = (EA.Package)repository.GetTreeSelectedObject();
2153 ghuddy 230
               EA_Utilities.findAndProcessPackageElements( thePackage, reqLister, true );
2145 ghuddy 231
               EA.Diagram newDiagram = (EA.Diagram)thePackage.Diagrams.AddNew("Requirements","Logical");
232
               newDiagram.Update();
233
               thePackage.Update();
234
 
235
               foreach (EA.Element element in reqLister.Elements)
236
               {
237
                  EA.DiagramObject newDiagramObject = (EA.DiagramObject)newDiagram.DiagramObjects.AddNew("l=1;r=10;t=1;b=1", "");
238
                  newDiagramObject.ElementID = element.ElementID;
239
                  newDiagramObject.Update();
240
               }
241
               newDiagram.DiagramObjects.Refresh();
242
               thePackage.Update();
243
               repository.GetProjectInterface().LayoutDiagramEx( newDiagram.DiagramGUID, 
244
                  EA.ConstLayoutStyles.lsDiagramDefault, 4, 20, 20, false);
245
               break;
246
 
247
            }
248
 
2139 ghuddy 249
         }
250
      }
251
 
2151 ghuddy 252
      private static void ImportReqProDatabase_Thread()
253
      {
254
         mustAbort = false;
255
         ImportReqProDatabase import_parser = new ImportReqProDatabase();
256
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
257
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
258
         import_parser.prompt_and_parse(ReqProDB_Artifact.MODE.TRACEABILITY); 
259
         if (mustAbort)
2153 ghuddy 260
            MessageBoxEx.Show("Import Aborted", "Progress");
2151 ghuddy 261
      }
2139 ghuddy 262
 
2151 ghuddy 263
      private static void CopyReqProDatabase_Thread()
264
      {
265
         mustAbort = false;
266
         EA_Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
267
         EA_Repository.WriteOutput(GUI_OUTPUT_TAB_NAME,"",-1);
268
         CopyReqProDatabase copy_parser = new CopyReqProDatabase();
269
         copy_parser.prompt_and_parse(ReqProDB_Artifact.MODE.DOC_MODEL);
270
         if (mustAbort)
2153 ghuddy 271
            MessageBoxEx.Show("Import Aborted", "Progress");
2151 ghuddy 272
      }
273
 
2153 ghuddy 274
      public static void MessageBoxException(Exception exc)
275
      {
276
         MessageBoxException(exc, "Exception");
277
      }
278
 
279
      public static void MessageBoxException(Exception exc, string caption)
280
      {
281
         MessageBoxEx.Show(exc.ToString(), caption);
282
      }
2139 ghuddy 283
   }
284
}