Révision 2197
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/LoadBinaryCorporaDirectory.java (revision 2197) | ||
---|---|---|
92 | 92 |
if (dialog.open() != null) { |
93 | 93 |
|
94 | 94 |
File directory = new File(dialog.getFilterPath()); |
95 |
|
|
95 |
|
|
96 | 96 |
if (directory.exists()) { |
97 | 97 |
LastOpened.set(ID, directory); |
98 | 98 |
JobHandler job = loadBinaryCorpusFromCorporaDirectory(directory, true, true, false); |
... | ... | |
116 | 116 |
* @return |
117 | 117 |
*/ |
118 | 118 |
public static JobHandler loadBinaryCorpusFromCorporaDirectory(final File directory, final boolean askSelection, final boolean replace, final boolean loadDirectories) { |
119 |
|
|
119 |
|
|
120 | 120 |
JobHandler jobhandler = new JobHandler(NLS.bind(TXMUIMessages.LoadBinaryCorporaDirectory_loadingCorporaFromTheP0Directory, directory), true) { |
121 |
|
|
121 |
|
|
122 | 122 |
JobHandler self = this; |
123 | 123 |
@Override |
124 | 124 |
protected IStatus run(final IProgressMonitor monitor) { |
125 | 125 |
this.runInit(monitor); |
126 | 126 |
|
127 |
// try { |
|
128 |
// SearchEnginesManager.getCQPSearchEngine().stop(); |
|
129 |
// } catch (Exception e1) { |
|
130 |
// // TODO Auto-generated catch block |
|
131 |
// e1.printStackTrace(); |
|
132 |
// } |
|
133 |
|
|
127 |
// try {
|
|
128 |
// SearchEnginesManager.getCQPSearchEngine().stop();
|
|
129 |
// } catch (Exception e1) {
|
|
130 |
// // TODO Auto-generated catch block
|
|
131 |
// e1.printStackTrace();
|
|
132 |
// }
|
|
133 |
|
|
134 | 134 |
File corporaDirectory = new File(Toolbox.getTxmHomePath(), "corpora"); //$NON-NLS-1$ |
135 | 135 |
if (!corporaDirectory.exists()) { |
136 | 136 |
Log.severe(TXMUIMessages.LoadBinaryCorporaDirectory_corporaDirectoryNotFoundAborting); |
137 |
// try { |
|
138 |
// SearchEnginesManager.getCQPSearchEngine().start(null); |
|
139 |
// } catch (Exception e) { |
|
140 |
// // TODO Auto-generated catch block |
|
141 |
// e.printStackTrace(); |
|
142 |
// } |
|
137 |
// try {
|
|
138 |
// SearchEnginesManager.getCQPSearchEngine().start(null);
|
|
139 |
// } catch (Exception e) {
|
|
140 |
// // TODO Auto-generated catch block
|
|
141 |
// e.printStackTrace();
|
|
142 |
// }
|
|
143 | 143 |
return Status.CANCEL_STATUS; |
144 | 144 |
} |
145 |
|
|
145 |
|
|
146 | 146 |
final ArrayList<Project> newProjects = new ArrayList<Project>(); |
147 | 147 |
if (askSelection) { |
148 |
|
|
148 |
|
|
149 | 149 |
this.syncExec(new Runnable() { |
150 | 150 |
@Override |
151 | 151 |
public void run() { |
... | ... | |
156 | 156 |
} |
157 | 157 |
} |
158 | 158 |
}); |
159 |
|
|
159 |
|
|
160 | 160 |
} else { // try loading corpora and dont replace existing corpus |
161 | 161 |
List<File> files = Arrays.asList(getBinaryCorpusFiles(directory, loadDirectories)); |
162 | 162 |
ArrayList<Project> tmp = loadBinaryCorpusFromCorporaDirectory(files, this, monitor, replace); |
... | ... | |
165 | 165 |
} |
166 | 166 |
} |
167 | 167 |
|
168 |
// this.acquireSemaphore(); |
|
169 |
// try { |
|
170 |
// SearchEnginesManager.getCQPSearchEngine().start(null); |
|
171 |
// } catch (Exception e) { |
|
172 |
// e.printStackTrace(); |
|
173 |
// } |
|
174 |
// this.releaseSemaphore(); |
|
168 |
// this.acquireSemaphore();
|
|
169 |
// try {
|
|
170 |
// SearchEnginesManager.getCQPSearchEngine().start(null);
|
|
171 |
// } catch (Exception e) {
|
|
172 |
// e.printStackTrace();
|
|
173 |
// }
|
|
174 |
// this.releaseSemaphore();
|
|
175 | 175 |
|
176 | 176 |
for (Project newProject2 : newProjects) { |
177 | 177 |
try { |
... | ... | |
183 | 183 |
if (newProjects.size() > 0) { |
184 | 184 |
System.out.println(NLS.bind(TXMUIMessages.P0CorpusLoaded, newProjects.size())); |
185 | 185 |
} |
186 |
|
|
186 |
|
|
187 | 187 |
this.syncExec(new Runnable() { |
188 | 188 |
@Override |
189 | 189 |
public void run() { |
... | ... | |
191 | 191 |
StatusLine.setMessage(TXMUIMessages.info_txmIsReady); |
192 | 192 |
} |
193 | 193 |
}); |
194 |
|
|
194 |
|
|
195 | 195 |
return Status.OK_STATUS; |
196 | 196 |
} |
197 | 197 |
}; |
... | ... | |
199 | 199 |
jobhandler.schedule(); |
200 | 200 |
return jobhandler; |
201 | 201 |
} |
202 |
|
|
202 |
|
|
203 | 203 |
protected static List<File> getBinaryCorpusSelection(File directory, boolean loadDirectories) { |
204 | 204 |
ArrayList<File> selectedFiles = new ArrayList<File>();; |
205 | 205 |
if (!directory.isDirectory()) return selectedFiles; |
206 | 206 |
if (!directory.exists()) return selectedFiles; |
207 |
|
|
207 |
|
|
208 | 208 |
Shell shell = null; |
209 |
|
|
209 |
|
|
210 | 210 |
if (Display.getCurrent() != null) { |
211 | 211 |
shell = Display.getCurrent().getActiveShell(); |
212 | 212 |
} else if (Display.getDefault() == null) { |
... | ... | |
217 | 217 |
return selectedFiles; |
218 | 218 |
} |
219 | 219 |
File[] files = getBinaryCorpusFiles(directory, loadDirectories); |
220 |
|
|
220 |
|
|
221 | 221 |
ListSelectionDialog lsd = new ListSelectionDialog(shell, files, new ArrayContentProvider(), new LabelProvider() { |
222 | 222 |
|
223 | 223 |
@Override |
224 | 224 |
public String getText(Object element) { |
225 | 225 |
if (element == null) return "error";//$NON-NLS-1$ |
226 |
|
|
226 |
|
|
227 | 227 |
if (!(element instanceof File)) return "not a file ("+element+")";//$NON-NLS-1$ //$NON-NLS-2$ |
228 |
|
|
228 |
|
|
229 | 229 |
File f = (File) element; |
230 | 230 |
if (f.isDirectory()) { |
231 | 231 |
if (new File(f, ".settings").exists()) {//$NON-NLS-1$ |
... | ... | |
236 | 236 |
} else if (f.getName().endsWith(".txm")) {//$NON-NLS-1$ |
237 | 237 |
return Zip.getRoot(f).toUpperCase()+" ("+f+")";//$NON-NLS-1$ //$NON-NLS-2$ |
238 | 238 |
} |
239 |
|
|
239 |
|
|
240 | 240 |
return "not a txm corpus ("+f+")";//$NON-NLS-1$ //$NON-NLS-2$ |
241 | 241 |
} |
242 | 242 |
}, TXMUIMessages.LoadBinaryCorporaDirectory_selectTheTXMCorpusToLoad); |
... | ... | |
248 | 248 |
selectedFiles.add(new File(o.toString())); |
249 | 249 |
} |
250 | 250 |
} |
251 |
|
|
251 |
|
|
252 | 252 |
return selectedFiles; |
253 | 253 |
} |
254 | 254 |
|
255 | 255 |
private static File[] getBinaryCorpusFiles(File directory, boolean loadDirectories) { |
256 | 256 |
File[] files = null; |
257 |
|
|
257 |
|
|
258 | 258 |
if (loadDirectories) { |
259 | 259 |
files = directory.listFiles(new FileFilter() { |
260 | 260 |
@Override |
... | ... | |
270 | 270 |
} |
271 | 271 |
}); |
272 | 272 |
} |
273 |
|
|
273 |
|
|
274 | 274 |
Arrays.sort(files, new Comparator<File>() { |
275 | 275 |
@Override |
276 | 276 |
public int compare(File o1, File o2) { |
... | ... | |
281 | 281 |
return i; |
282 | 282 |
} |
283 | 283 |
}); |
284 |
|
|
284 |
|
|
285 | 285 |
return files; |
286 | 286 |
} |
287 | 287 |
|
... | ... | |
309 | 309 |
* @return the loaded projects |
310 | 310 |
*/ |
311 | 311 |
protected static ArrayList<Project> loadBinaryCorpusFromCorporaDirectory(List<File> corporaFiles, JobHandler job, IProgressMonitor monitor, boolean replace) { |
312 |
|
|
312 |
|
|
313 | 313 |
ArrayList<Project> projects = new ArrayList<Project>(); |
314 |
|
|
314 |
|
|
315 | 315 |
try { |
316 |
|
|
317 |
// SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
318 |
// if (engine.isRunning()) { |
|
319 |
// engine.stop(); |
|
320 |
// } |
|
321 |
|
|
316 |
|
|
317 |
// SearchEngine engine = SearchEnginesManager.getCQPSearchEngine();
|
|
318 |
// if (engine.isRunning()) {
|
|
319 |
// engine.stop();
|
|
320 |
// }
|
|
321 |
|
|
322 | 322 |
monitor.beginTask(TXMUIMessages.loadingBinaryCorpus, 100); |
323 | 323 |
job.acquireSemaphore(); |
324 |
// Toolbox.getEngineManager(EngineType.SEARCH).stopEngines(); |
|
324 |
// Toolbox.getEngineManager(EngineType.SEARCH).stopEngines();
|
|
325 | 325 |
job.releaseSemaphore(); |
326 | 326 |
|
327 | 327 |
monitor.subTask(TXMUIMessages.loadingTheCorpusInThePlatform); |
328 | 328 |
for (File corpusDirectory : corporaFiles) { |
329 |
if (corpusDirectory.isHidden()) { |
|
330 |
continue; |
|
329 |
try { |
|
330 |
if (corpusDirectory.isHidden()) { |
|
331 |
continue; |
|
332 |
} |
|
333 |
|
|
334 |
Project project = Toolbox.workspace.getProject(corpusDirectory.getName().toUpperCase()); |
|
335 |
if (project != null) { |
|
336 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.LoadBinaryCorporaDirectory_aCorpusNamedP0alreadyExistsLoadingOfP1Canceled, corpusDirectory.getName().toUpperCase(), corpusDirectory)); |
|
337 |
continue; |
|
338 |
} |
|
339 |
|
|
340 |
if (corpusDirectory.isDirectory()) { |
|
341 |
project = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory, monitor, replace); |
|
342 |
} else { |
|
343 |
project = LoadBinaryCorpus.loadBinaryCorpusArchive(corpusDirectory, job, monitor, replace); |
|
344 |
} |
|
345 |
|
|
346 |
// Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory); |
|
347 |
if (project == null) { |
|
348 |
//Log.warning("Failed to load binary corpus: "+corpusDirectory); |
|
349 |
} else { |
|
350 |
projects.add(project); |
|
351 |
project.save(); |
|
352 |
} |
|
353 |
} catch (Exception e2) { |
|
354 |
Log.warning("Could not load corpus from "+corpusDirectory+": "+e2); |
|
355 |
Log.printStackTrace(e2); |
|
331 | 356 |
} |
332 |
|
|
333 |
Project project = Toolbox.workspace.getProject(corpusDirectory.getName().toUpperCase()); |
|
334 |
if (project != null) { |
|
335 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.LoadBinaryCorporaDirectory_aCorpusNamedP0alreadyExistsLoadingOfP1Canceled, corpusDirectory.getName().toUpperCase(), corpusDirectory)); |
|
336 |
continue; |
|
337 |
} |
|
338 |
|
|
339 |
if (corpusDirectory.isDirectory()) { |
|
340 |
project = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory, monitor, replace); |
|
341 |
} else { |
|
342 |
project = LoadBinaryCorpus.loadBinaryCorpusArchive(corpusDirectory, job, monitor, replace); |
|
343 |
} |
|
344 |
|
|
345 |
// Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory); |
|
346 |
if (project == null) { |
|
347 |
//Log.warning("Failed to load binary corpus: "+corpusDirectory); |
|
348 |
} else { |
|
349 |
projects.add(project); |
|
350 |
project.save(); |
|
351 |
} |
|
352 | 357 |
} |
353 | 358 |
|
354 | 359 |
monitor.subTask(TXMUIMessages.restartingThePlatform); |
355 |
|
|
360 |
|
|
356 | 361 |
} catch (ThreadDeath td) { |
357 | 362 |
} catch (Exception e2) { |
358 | 363 |
org.txm.utils.logger.Log.printStackTrace(e2); |
359 | 364 |
} finally { |
360 | 365 |
monitor.done(); |
361 | 366 |
} |
362 |
|
|
367 |
|
|
363 | 368 |
return projects; |
364 | 369 |
} |
365 | 370 |
} |
Formats disponibles : Unified diff