Search code examples
ibm-doors

Populate a list with Modules and display it in a Dialogbox in DOORS


I need a DXL script that fill a DialogBox with returned Module names'. I have several modules within a project.

Below is my current progress. My idea is to put all Module names in a List and then display the list in a DialogBox.

Can you help me write ´´´fillModulelist()´´´

// This DXL script iterates through all formal modules of the folder
DB      dbMain        = null
DBE     dbeModuleList   = null
DBE     dbeExport     = null
DBE     dbeExportPath = null

Folder  currFolder    = null

string startFolder="/Project/Folder";
int moduleCount=0;
 
void forAllModulesInFolder(Folder f)
{
  Item itemRef;
  string shType;
  string sItemNameFull;
  string sItemName;
  Module moduleReference;
 
  for itemRef in f do
  {
    shType = type(itemRef);
    print shType "\t";
 
    sItemNameFull = fullName(itemRef);
    print sItemNameFull "\t";
 
    sItemName = name(itemRef);
    print sItemName "\n";
 
  if(shType=="Folder")
  {
    string selectedFolder = sItemNameFull;
    Folder f = folder selectedFolder;
    forAllModulesInFolder(f);
  }
 
  if(shType=="Formal")
  {
    moduleReference = read(sItemNameFull,false,true);
    filtering off;
    // do s.th. with the moduleReference
    close(moduleReference);
    moduleCount++;
  }
}}

void fillModuleList()
{
    //........... HELP NEEDED........
    
}
 
// Main-Method
void main(void)
{
  string selectedFolder = startFolder;
  Folder f = folder selectedFolder;
  forAllModulesInFolder(f);
  print "Affected Modules: " moduleCount "\n";
}
 
main();

Any help provided I would be very thankful.


Solution

  • As the list of modules is for displaying it to the user (and perhaps let them select from that list), it is best to display the full name of the modules, thus I would not store the module reference. You can open the module later, when the user has selected/double clicked the module (supposing that this is what you want). Thus, I fill a Skip list with sItemNameFull, sItemNameFull, but if it suits your script better, you can also fill it with moduleReference, sItemNameFull (use create instead of createString in this case). The changes to your script are marked with //->> and //<<-

    // This DXL script iterates through all formal modules of the folder
    DB      dbMain        = null
    DBE     dbeModuleList   = null
    DBE     dbeExport     = null
    DBE     dbeExportPath = null
    
    Folder  currFolder    = null
    
    string startFolder="/testtrunk";
    int moduleCount=0;
    
    //->>
    Skip skModules = createString()
    //<<-
     
    void forAllModulesInFolder(Folder f)
    {
      Item itemRef;
      string shType;
      string sItemNameFull;
      string sItemName;
      Module moduleReference;
     
      for itemRef in f do
      {
        shType = type(itemRef);
        print shType "\t";
     
        sItemNameFull = fullName(itemRef);
        print sItemNameFull "\t";
     
        sItemName = name(itemRef);
        print sItemName "\n";
     
      if(shType=="Folder")
      {
        string selectedFolder = sItemNameFull;
        Folder f = folder selectedFolder;
        forAllModulesInFolder(f);
      }
     
      if(shType=="Formal")
      {
        //->>
        put (skModules, sItemNameFull, sItemNameFull)
        //moduleReference = read(sItemNameFull,false,true);
        //filtering off;
        // do s.th. with the moduleReference
        //close(moduleReference);
        //<<-
        moduleCount++;
      }
    }}
    
    //->>
    void fillModuleList(Skip skContent, DBE dbeList)
    {
        empty dbeList
        int cnt=0
        string sLine
        for sLine in skContent do {
            insert (dbeList, cnt, sLine)
            cnt++
        }
    }
    //<<-
    
    
    //->>
    void DoSomethingWithDoubleClickedModule (DBE x) {
        string sModName = get(x)
        print "doing something with " sModName "<---\n"
    }
    
    
    void canvasDummyCB( DBE dummy ) { }
    void doNothing(DBE x) {}
    void prepareGui()
    {
        const string sArEmpty[] = {}
    
        dbMain = create ("mytitle", styleCentered)
        
        DBE spaceLeft = canvas(dbMain, 0, 0, canvasDummyCB)
        spaceLeft->"top"->"form"; spaceLeft->"left"->"form"
        spaceLeft->"right"->"unattached"; spaceLeft->"bottom"->"unattached"
        
        DBE spaceRight = canvas(dbMain, 0, 0, canvasDummyCB)
        spaceRight->"top"->"form"; spaceRight->"right"->"form"
        spaceRight->"left"->"unattached"; spaceRight->"bottom"->"unattached"
        
        DBE dInfoTextLabel = label(dbMain, "choose a module")
        dInfoTextLabel->"top"->"form"
        dInfoTextLabel->"left"->"flush"->spaceLeft
        dInfoTextLabel->"right"->"flush"->spaceRight
        
        dbeModuleList = list( dbMain, "Modules", 200, 15, sArEmpty)  
        dbeModuleList->"top"->"flush"->dInfoTextLabel
        dbeModuleList->"left"->"flush"->spaceLeft
        dbeModuleList->"right"->"flush"->spaceRight
    
        realize dbMain
    
        set( dbeModuleList, doNothing, DoSomethingWithDoubleClickedModule)
    
    }
    //<<-
    
    
    // Main-Method
    void main(void)
    {
      //->>
      prepareGui()
      //<<-
      
      string selectedFolder = startFolder;
      Folder f = folder selectedFolder;
      setempty(skModules)
      forAllModulesInFolder(f);
      //->>
      fillModuleList (skModules, dbeModuleList)
      //<<-
      print "Affected Modules: " moduleCount "\n";
    }
     
    main();