refactored xper adapter module (2)
[cdmlib-apps.git] / XperCdmIntegration / src / test / java / eu / etaxonomy / cdm / io / xper / TestAdapterCdmXper.java
1 package eu.etaxonomy.cdm.io.xper;
2
3 import java.io.File;
4
5 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
6 import eu.etaxonomy.cdm.app.common.CdmDestinations;
7 import eu.etaxonomy.cdm.database.DbSchemaValidation;
8 import eu.etaxonomy.cdm.database.ICdmDataSource;
9 import eu.etaxonomy.cdm.io.xper.AdaptaterCdmXper;
10 import fr_jussieu_snv_lis.Xper;
11 import fr_jussieu_snv_lis.edition.XPDisplay;
12 import fr_jussieu_snv_lis.utils.Utils;
13
14 public class TestAdapterCdmXper {
15
16
17
18 public TestAdapterCdmXper(){
19
20 DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
21 ICdmDataSource datasource = CdmDestinations.cdm_test_local_xper();
22
23 final CdmApplicationController appCtr = CdmApplicationController.NewInstance(datasource, dbSchemaValidation);
24
25
26 Thread t = new Thread() {
27 public void run() {
28 new Xper(appCtr);
29 }
30 };
31 t.start();
32 }
33
34 public static void xperloadDataFromCdm(){
35 // create a new empty base and load data from CDM
36 if(Xper.getCdmApplicationController() != null){
37 // create a new base
38 Xper.getMainframe().newBase("baseTest");
39 // specify that the current base is not new (needed to be able to add images)
40 Utils.isNewBase = false;
41 // use the current directory as working directory for Xper2
42 XPDisplay.getControler().getBase().setPathName(System.getProperty("user.dir") + Utils.sep);
43 // create a _thumbnail directory to store thumbnails
44 new File(System.getProperty("user.dir") + Utils.sep + "images" + Utils.sep + "_thumbnails").mkdirs();
45 // delete the variable create by default and update the frame
46 XPDisplay.getControler().getBase().deleteVariable(XPDisplay.getControler().getBase().getVariableAt(0));
47 XPDisplay.displayNbVariable();
48 XPDisplay.getControler().displayJifVarTree();
49
50 AdaptaterCdmXper adapterCdmXper = new AdaptaterCdmXper();
51 Utils.cdmAdapter = adapterCdmXper;
52
53 if (Utils.currentBase != null) {
54 // adaptaterCdmXper.createWorkingSet();
55 adapterCdmXper.load();
56
57 XPDisplay.displayNbVariable();
58 XPDisplay.getControler().displayJifVarTree();
59 }
60 }
61 }
62
63 /**
64 * @param args
65 */
66 public static void main(String[] args) {
67 System.out.println("cdm start");
68 new TestAdapterCdmXper();
69 System.out.println("cdm started :::");
70
71 while(!Utils.xperReady){
72 //TODO wait
73 }
74 System.out.println("start load data");
75 // display a loading gif
76 Utils.displayLoadingGif(true);
77 // load the data from CDM
78
79 xperloadDataFromCdm();
80 // undisplay a loading gif
81 Utils.displayLoadingGif(false);
82 System.out.println("stop load data");
83 System.out.println("start generate thumbnails");
84 // generate all thumbnails (a loading gif is automatically displayed
85 Utils.generateThumbnailsFromURLImage(XPDisplay.getControler().getBase().getAllResources());
86 System.out.println("stop generate thumbnails");
87
88 }
89
90 }