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