« Back

File Selection Mechanism

Combination View Flat View Tree View
Threads [ Previous | Next ]
File Selection Mechanism
external coupling scenario documentation adoscript constructs
Answer
27/03/14 09:05
This package provides an example of a mechanism that adds files - contained in a folder and all of its subfolders - to a list (Record attribute). The base folder is selected by the user.

The images below show the selection of a folder and the complete list of all files contained in this folder.






Downloads


The files below contain an example library (File selection.abl) and an example model (File selection demo model.adl). A step-by-step configuration guide is presented in the Hands-On section below. It completely describes how to build this example library and contains the code of the mechanism.

File selection.abl
File selection demo model.adl

Description of the Mechanism



Functionality provided by ADOxx



ADOxx Realisation Approach



Used Modeling Language for Demonstration of the Mechanism
  • modeltype: File Selection Sample
  • classes: A, List of files (Record class)
  • attributes: Import files, List of files.
Hands-On

1) Preparations

Creation of before mentioned classes & attributes for the sake of a minimal  working example. This step can be skipped – import File selection.abl instead.

a) Create new record class List of files


  • Go to the Library management, select an Application library and click Class hierarchy.
  • Unfold Record classes, select Record classes and click New --> New record class…
  • Name new record class List of files.
b) Add new attribute to record class List of files


  • Select record class List of files
  • Click New --> New attribute...
  • Name new attributes and select type according figure above: name: Filename, type: String

c) Configure AttrRep attribute of List of files record class


  • Double click on AttrRep attribute
  • Set Standard value:
1NOTEBOOK
2ATTR "Filename" width:20

d) Create class A


  • Go to the dynamic library and click Class hierarchy.
  • Click View and select Metamodel.
  • Select __D-construct__ (Metamodel)
  • Click New --> New class; name it A

e) Add new attributes to class A



  • Select class A
  • Click New --> New attribute...
  • Name new attributes and select type according figure above: (1) name: Import files, type: Programcall (2) name: List of Files, type: Record --> select List of files as referenced record class after clicking OK.
f) Configure Import files attribute


  • Double click on Import files attribute
  • Set Standard value to Import files
  • Click Facets and set EnumerationDomain to
1ITEM "Import files"
2SETG g_callingObjectID: ( objid )
3EXECUTE file: "db:\\ImportFiles.asc"
  • Make sure that the file ImportFiles.asc is contained in the ADOxx database.

g) Configure AttrRep attribute (of class A)
  • Double click on AttrRep attribute
  • Set Standard value:
1NOTEBOOK
2CHAPTER "Description"
3ATTR "Name"
4ATTR "Import files" push-button no-param
5ATTR "List of files"

h) Configure GraphRep attribute (of class A)
  • Go to class A.
  • Double click GraphRep (Metamodel).
  • Click the Dialog button.
  • Enter:
1GRAPHREP
2SHADOW off
3FILL color:blue
4ELLIPSE x:0.00cm y:0cm rx:1cm ry:1cm
5ATTR "Name" x:0.00cm y:1.0cm w:c

i) Definine Modeltype


  • Go back to the Library management and select your current Dynamic Library.
  • Click Library attributes… -->  Add-ons and define the following model type according the figure above:
1MODELTYPE "File Selection Sample" from:none plural:"File Selection Samples" pos:0 not-simulateable bitmap:"db:\\sample.bmp"
2INCL "A"


2) Implementation of Mechanism with AdoScript
 1
 2# get objid (see "Import files" attribute)
 3SET id_crtObjID: ( g_callingObjectID )
 4
 5#open dialog
 6CC "AdoScript" DIRECTORY_DIALOG
 7SETL s_selectedPath: ( path )
 8
 9# add file path of files contained in selected folder to the record
10IF ( endbutton = "ok") {
11    IMPORT_FROM_FOLDER ( s_selectedPath)    
12}
13
14
15PROCEDURE IMPORT_FROM_FOLDER string: folderpath  {
16    CC "AdoScript" DIR_LIST path: (folderpath)
17   
18    SETL s_filesInPath: ( files )
19    SETL s_foldersInPath: ( dirs )
20    FOR sFileName in: (s_filesInPath) sep: ("*") {   
21        CC "Core"  GET_CLASS_ID objid: (id_crtObjID)
22        SETL id_crtClassID: ( classid )
23       
24        CC "Core"  GET_ATTR_ID classid: (id_crtClassID) attrname: ("List of files")
25        SETL id_loadedFilesAttrID: ( attrid )
26        # add new row to record
27        CC "Core"  ADD_REC_ROW objid: (id_crtObjID) attrid: (id_loadedFilesAttrID)
28        SETL id_newRowID: ( rowid )
29        # write file path into new row
30        CC "Core"  SET_ATTR_VAL objid: (id_newRowID) attrname: ("Filename") val: ( folderpath + sFileName) as-string   
31    }
32    # apply procedure on subfolders:
33    FOR sFolderName in: (s_foldersInPath) sep: ("*") {
34    IMPORT_FROM_FOLDER (folderpath + sFolderName + "\\")
35    }
36}


Result