splitting Utils to Utils and XPApp in Adapter
[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.XPApp;
11 import fr_jussieu_snv_lis.Xper;
12 import fr_jussieu_snv_lis.edition.XPDisplay;
13 import fr_jussieu_snv_lis.utils.Utils;
14
15 public class TestAdapterCdmXper {
16
17 AdaptaterCdmXper adapterCdmXper;
18
19 /**
20 *
21 */
22 private void startApplications() {
23 DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
24 ICdmDataSource datasource = CdmDestinations.cdm_test_local_xper();
25 System.out.println("cdm start");
26 CdmApplicationController appCtr = CdmApplicationController.NewInstance(datasource, dbSchemaValidation);
27 System.out.println("cdm started :::");
28
29 adapterCdmXper = new AdaptaterCdmXper(appCtr);
30
31 Thread t = new Thread() {
32 public void run() {
33 new Xper(adapterCdmXper);
34 }
35 };
36 System.out.println("xper2 start");
37 t.start();
38 while(!XPApp.xperReady){
39 //TODO wait
40 }
41 System.out.println("xper2 started :::");
42 }
43
44 public void xperloadDataFromCdm(){
45 System.out.println("start load data");
46 // display a loading gif
47 Utils.displayLoadingGif(true);
48
49
50 // create a new empty base and load data from CDM
51 if(XPApp.cdmAdapter != null){
52 // create a new base
53 XPApp.getMainframe().newBase("baseTest");
54 // specify that the current base is not new (needed to be able to add images)
55 XPApp.isNewBase = false;
56 // delete the variable create by default and update the frame
57 XPApp.getCurrentBase().deleteVariable(XPApp.getMainframe().getControler().getBase().getVariableAt(0));
58 XPApp.getMainframe().displayNbVariable();
59 XPApp.getMainframe().getControler().displayJifVarTree();
60
61 if (XPApp.getCurrentBase() != null) {
62 // adaptaterCdmXper.createWorkingSet();
63 adapterCdmXper.load();
64
65 XPApp.getMainframe().displayNbVariable();
66 XPApp.getMainframe().getControler().displayJifVarTree();
67 }
68 }
69 // undisplay a loading gif
70 Utils.displayLoadingGif(false);
71 System.out.println("data loaded :::");
72 }
73
74 /**
75 *
76 */
77 private void createThumbnailDirectory() {
78 // create a _thumbnail directory to store thumbnails
79 new File(System.getProperty("user.dir") + Utils.sep + "images" + Utils.sep + "_thumbnails").mkdirs();
80 }
81
82 /**
83 *
84 */
85 private void generateThumbnails() {
86 System.out.println("start generate thumbnails");
87 // generate all thumbnails (a loading gif is automatically displayed
88 XPApp.generateThumbnailsFromURLImage(XPApp.getCurrentBase().getAllResources());
89 System.out.println("stop generate thumbnails");
90 }
91
92
93 private void startPartialCdm() {
94 // TODO Auto-generated method stub
95
96 }
97
98 /**
99 * @param args
100 */
101 public static void main(String[] args) {
102 System.out.println("start test");
103 //start CDM and Xper
104 TestAdapterCdmXper testAdapter = new TestAdapterCdmXper();
105 testAdapter.startApplications();
106 testAdapter.createThumbnailDirectory();
107 if (args.length >= 1 && "-p".equals(args[0]) ){
108 testAdapter.startPartialCdm();
109 }else{
110 // load the data from CDM
111 testAdapter.xperloadDataFromCdm();
112 // use the current directory as working directory for Xper2
113 XPApp.getCurrentBase().setPathName(System.getProperty("user.dir") + Utils.sep);
114
115 testAdapter.generateThumbnails();
116 }
117
118
119
120 }
121
122
123
124
125 }