Project VN2664QNR : Export to QSL from Questionnaire Editor

From Catglobe Wiki
Revision as of 10:23, 12 May 2009 by Catglobe (talk | contribs) (Data structure)
Jump to: navigation, search

What's purpose of this project ?

The main goal of this project is to allow user to export the structure of a questionnaire template into a QSL script .

Feature design

The feature design could be found here : \\catproc\Share\CatGlobe Teams\Questionnaire\Projects\Version 5.8\VN2644QNR - Export to QSL from Questionnaire Editor

Implement GUI

In this project , we need to write a new collapse-able container and a container that can hold a collection of collapse-able container because the editor only use Swing ( standard Java's API library for providing a graphical user interface ) and this library does not have an explicit collapse-able container .

Class diagram

Container.JPG

How to use an instance of collapse-able container

All sub panels of the container initialized once on constructor . The parameter of constructor contains an Array of sub panel's caption and an Array of sub panel . In order get the collapse-able container itself , use method getComponent() TO add a collapse-able container to another

Making an customize save file dialog

Currently we have an class for customize save file dialog but this one has not been supported our customize file filter yet so i modified it a little bit so that it supports

Making the a file filter

The default "All file(*.*)" filter is in inconvenient when using so it will be overwrite . Another useful of it is that we can have text resource fully supported .

Make QSL file filter

 1 public class QSLFilter extends FileFilter {
 2 
 3     /* (non-Javadoc)
 4      * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
 5      */
 6     @Override
 7     public boolean accept(File arg0) {
 8         // TODO Auto-generated method stub
 9         if(arg0.isDirectory())
10             return true;
11         else 
12             return (getExtension(arg0).equals("qsl"));
13     }
14 
15     /* (non-Javadoc)
16      * @see javax.swing.filechooser.FileFilter#getDescription()
17      */
18     @Override
19     public String getDescription() {
20         
21         // TODO Auto-generated method stub
22         return "QSL file(*.qsl)";
23     }
24     public static String getExtension(File f) {
25         String ext = null;
26         String s = f.getName();
27         int i = s.lastIndexOf('.');
28 
29         if (i > 0 &&  i < s.length() - 1) {
30             ext = s.substring(i+1).toLowerCase();
31         }
32         return ext;
33     }

Export questionnaire template to QSL script

To implement export task , we need to go through the structure of the questionnaire template ( questionnaire , question , property , answer option , sub-question) and export to a text file . "Visitor Pattern" has been chosen because this pattern allows us add new operations to existing object structures without modifying those structures . Thus, using the visitor pattern helps conformance with the open/closed principle

Visitor pattern

Diagram.JPG

QSL keyword using in exporting

The QSL keywords are defined in file questionnaire.g and we can't get keywords directly from it . In order to keep the synchronization with import QSL module , we will get the keyword from public variables of QuestionnaireLexer.java and QuestionnaireParser.java . Those 2 file were generated directly and automiccally from Questionnaire.g using ANTLR library .

Processing properties

In the questionnaire template , properties are only defined for questionnaire and question but QSL script has properties for sub question and answer option . We need to generate these properties from the properties of the related question . To solve this problem , we use 2 map ( Map in java used like a dictionary in .NET) to store properties relate to answer option and sub question .
Algorithm :
-Visit question element . If this question type has properties use for answer option ( or sub question ) , process them and put to the map
-When visit answer option ( or sub question ) , if the map is not empty then get the value from it and generate properties for answer option ( or sub question )

Data structure use for export task

DataStructure.PNG