Révision 1171
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/SearchEngine.java (revision 1171) | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.txm.core.engines.Engine; |
4 | 4 |
import org.txm.objects.CorpusBuild; |
5 |
import org.txm.stat.utils.LogMonitor; |
|
5 | 6 |
|
6 | 7 |
// FIXME: useless class |
7 | 8 |
public abstract class SearchEngine implements Engine { |
... | ... | |
11 | 12 |
@Override |
12 | 13 |
public abstract String getName(); |
13 | 14 |
|
15 |
public boolean start() throws Exception { |
|
16 |
return start(new LogMonitor("Starting "+getName())); |
|
17 |
} |
|
18 |
|
|
14 | 19 |
public abstract Selection query(CorpusBuild corpus, Query query, String name, boolean saveQuery) throws Exception; |
15 | 20 |
|
16 | 21 |
public abstract Query newQuery(); |
tmp/org.txm.utils/src/org/txm/utils/zip/Zip.java (revision 1171) | ||
---|---|---|
301 | 301 |
while (null != (ze = zis.getNextEntry())) { |
302 | 302 |
nEntries++; |
303 | 303 |
} |
304 |
} catch(Exception e) { } finally { |
|
304 |
} catch(Exception e) { e.printStackTrace(); } finally {
|
|
305 | 305 |
if (zis != null) zis.close(); |
306 | 306 |
} |
307 | 307 |
//System.out.println("count entries result: "+nEntries); |
... | ... | |
347 | 347 |
} |
348 | 348 |
} finally { |
349 | 349 |
zis.close(); |
350 |
if (monitor != null) monitor.done(); |
|
350 |
//if (monitor != null) monitor.done();
|
|
351 | 351 |
} |
352 | 352 |
|
353 | 353 |
if (deleteZipAfter) |
... | ... | |
619 | 619 |
// Parcours tous les fichiers |
620 | 620 |
while (null != (ze = zis.getNextEntry())) { |
621 | 621 |
String currentpath = ze.getName(); |
622 |
String filename = currentpath; |
|
623 |
if (filename.endsWith("/")) { |
|
624 |
filename = filename.substring(0, filename.length()-1); |
|
625 |
} |
|
626 |
if (filename.lastIndexOf("/") > 0) { |
|
627 |
filename = filename.substring(filename.lastIndexOf("/")+1); |
|
628 |
} |
|
629 |
if (toFind.contains(filename)) {
|
|
630 |
toFind.remove(filename);
|
|
622 |
// String filename = currentpath;
|
|
623 |
// if (filename.endsWith("/")) {
|
|
624 |
// filename = filename.substring(0, filename.length()-1);
|
|
625 |
// }
|
|
626 |
// if (filename.lastIndexOf("/") > 0) {
|
|
627 |
// filename = filename.substring(filename.lastIndexOf("/")+1);
|
|
628 |
// }
|
|
629 |
if (toFind.contains(currentpath)) {
|
|
630 |
toFind.remove(currentpath);
|
|
631 | 631 |
if (toFind.size() == 0) { |
632 | 632 |
try { |
633 | 633 |
zis.close(); |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CQPCorpus.java (revision 1171) | ||
---|---|---|
823 | 823 |
try { |
824 | 824 |
Subcorpus subcorp = this.createSubcorpus(subcorpusElem); |
825 | 825 |
subcorp._load(subcorpusElem); |
826 |
subcorp.compute(); |
|
826 | 827 |
} catch (CqiClientException ex) { |
827 | 828 |
Log.warning(this.pID + TXMCoreMessages.Corpus_12 + pID |
828 | 829 |
+ " : " + ex); //$NON-NLS-1$ |
... | ... | |
850 | 851 |
|
851 | 852 |
// partition.setSelfElement(partitionElem); |
852 | 853 |
// partition.load(); |
854 |
partition.compute(); |
|
853 | 855 |
} catch (Exception ex) { |
854 | 856 |
Log.warning(this.pID + TXMCoreMessages.Corpus_19 + name |
855 | 857 |
+ " : " + ex); //$NON-NLS-1$ |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/MainCorpus.java (revision 1171) | ||
---|---|---|
108 | 108 |
*/ |
109 | 109 |
public MainCorpus(String parametersNodePath) throws InvalidCqpIdException, CqiClientException { |
110 | 110 |
super(parametersNodePath); |
111 |
|
|
112 |
this.internalPersistable = true; |
|
113 |
|
|
114 |
this.dataDirectory = new File(getProjectDirectory(), "data/"+getID()); |
|
115 |
this.registryFile = new File(getProjectDirectory(), "registry/"+getID().toLowerCase()); |
|
111 | 116 |
} |
112 | 117 |
|
113 | 118 |
|
... | ... | |
143 | 148 |
@Override |
144 | 149 |
public boolean export(File exportzip, IProgressMonitor monitor) |
145 | 150 |
{ |
146 |
if (this.getProject() != null) |
|
147 |
return this.getProject().export(exportzip, monitor); |
|
151 |
if (this.getProject() != null) { |
|
152 |
try { |
|
153 |
this.getProject().saveParameters(true); // write parameters in preferences |
|
154 |
this.getProject().persist(true); // save preferences |
|
155 |
return this.getProject().export(exportzip, monitor); |
|
156 |
} catch (Exception e) { |
|
157 |
// TODO Auto-generated catch block |
|
158 |
e.printStackTrace(); |
|
159 |
} |
|
160 |
} |
|
148 | 161 |
return false; |
149 | 162 |
} |
150 | 163 |
|
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Subcorpus.java (revision 1171) | ||
---|---|---|
39 | 39 |
import org.txm.core.results.Parameter; |
40 | 40 |
import org.txm.core.results.TXMParameters; |
41 | 41 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
42 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
42 | 43 |
import org.txm.searchengine.cqp.NetCqiClient; |
43 | 44 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
44 | 45 |
import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException; |
... | ... | |
498 | 499 |
@Override |
499 | 500 |
public void clean() { |
500 | 501 |
try { |
501 |
CorpusManager.getCorpusManager().getCqiClient().dropSubCorpus(this.getQualifiedCqpId()); |
|
502 |
if (CQPSearchEngine.isInitialized()) { |
|
503 |
CorpusManager.getCorpusManager().getCqiClient().dropSubCorpus(this.getQualifiedCqpId()); |
|
504 |
} |
|
502 | 505 |
} catch (Exception e) { |
503 | 506 |
e.printStackTrace(); |
504 | 507 |
} |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/CQPSearchEngine.java (revision 1171) | ||
---|---|---|
312 | 312 |
((MemCqiClient)cqiClient).dropCorpus(name); |
313 | 313 |
} |
314 | 314 |
} |
315 |
|
|
315 | 316 |
cqiClient.disconnect(); |
316 | 317 |
cqiServer.stop(); |
317 | 318 |
|
tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyScriptedImportEngine.java (revision 1171) | ||
---|---|---|
18 | 18 |
import org.txm.objects.Edition; |
19 | 19 |
import org.txm.objects.Project; |
20 | 20 |
import org.txm.objects.Text; |
21 |
import org.txm.objects.Workspace; |
|
21 | 22 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
22 | 23 |
import org.txm.tokenizer.TokenizerClasses; |
23 | 24 |
import org.txm.utils.ExecTimer; |
... | ... | |
42 | 43 |
|
43 | 44 |
try { |
44 | 45 |
// check if TreeTagger is ready |
46 |
Workspace w = Toolbox.workspace; |
|
45 | 47 |
boolean annotate = project.getAnnotate(); |
46 | 48 |
if (annotate) { |
47 | 49 |
Engine e = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger"); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/ApplicationWorkbenchAdvisor.java (revision 1171) | ||
---|---|---|
85 | 85 |
import org.txm.core.preferences.TBXPreferences; |
86 | 86 |
import org.txm.core.preferences.TXMPreferences; |
87 | 87 |
import org.txm.objects.Project; |
88 |
import org.txm.objects.Project; |
|
89 | 88 |
import org.txm.rcp.commands.OpenWelcomePage; |
90 | 89 |
import org.txm.rcp.commands.RestartTXM; |
91 | 90 |
import org.txm.rcp.commands.workspace.LoadBinaryCorpus; |
... | ... | |
101 | 100 |
import org.txm.searchengine.core.SearchEnginesManager; |
102 | 101 |
import org.txm.utils.BundleUtils; |
103 | 102 |
import org.txm.utils.DeleteDir; |
103 |
import org.txm.utils.io.FileCopy; |
|
104 | 104 |
import org.txm.utils.logger.Log; |
105 | 105 |
import org.txm.utils.zip.Zip; |
106 | 106 |
|
... | ... | |
256 | 256 |
// restore corpora if TXMHOME has been created |
257 | 257 |
if (txmHomeRestored) { |
258 | 258 |
//createBackUpDirectory(monitor); |
259 |
reloadCorporaFromBackUpDirectory(monitor);
|
|
259 |
installCorporaFromSamplesDirectory(monitor);
|
|
260 | 260 |
this.syncExec(new Runnable() { |
261 | 261 |
@Override |
262 | 262 |
public void run() { |
263 | 263 |
try { |
264 |
// Toolbox.restartWorkspace(monitor); |
|
264 | 265 |
SearchEnginesManager.getCQPSearchEngine().stop(); |
265 | 266 |
SearchEnginesManager.getCQPSearchEngine().start(monitor); |
266 | 267 |
CorporaView.refresh(); |
... | ... | |
793 | 794 |
} |
794 | 795 |
} |
795 | 796 |
|
796 |
private void reloadCorporaFromBackUpDirectory(IProgressMonitor monitor) { |
|
797 |
ArrayList<String> basenames = new ArrayList<String>(); |
|
798 |
ArrayList<String> sampleCorpusLoaded = new ArrayList<String>(); |
|
797 |
/** |
|
798 |
* Copy sample corpora in TXM corpora directory |
|
799 |
* @param monitor |
|
800 |
*/ |
|
801 |
private void installCorporaFromSamplesDirectory(IProgressMonitor monitor) { |
|
799 | 802 |
|
800 | 803 |
String installdirpath = Toolbox.getInstallDirectory(); |
801 | 804 |
File sampleCorporaDirectory = new File(installdirpath, "samples"); |
805 |
|
|
806 |
if (txmhomedir == null) { |
|
807 |
txmhomedir = new File(Toolbox.getTxmHomePath().trim()); |
|
808 |
} |
|
809 |
corporaDir = new File(txmhomedir, "corpora"); //$NON-NLS-1$ |
|
810 |
corporaDir.mkdir(); |
|
811 |
|
|
802 | 812 |
// load corpora from the install directory |
803 | 813 |
if (sampleCorporaDirectory.exists()) { //$NON-NLS-1$ |
804 | 814 |
Log.info(TXMUIMessages.ApplicationWorkbenchAdvisor_11); |
805 | 815 |
monitor.setTaskName(TXMUIMessages.ApplicationWorkbenchAdvisor_11); |
806 | 816 |
//File corporaDir = new File(txmhomedir.getAbsolutePath(), "corpora"); //$NON-NLS-1$ |
807 |
if (txmhomedir == null) { |
|
808 |
txmhomedir = new File(Toolbox.getTxmHomePath().trim()); |
|
809 |
} |
|
810 |
corporaDir = new File(txmhomedir, "corpora"); //$NON-NLS-1$ |
|
811 |
corporaDir.mkdir(); |
|
817 |
|
|
812 | 818 |
|
813 | 819 |
File[] sampleCorpusFiles = sampleCorporaDirectory.listFiles(); //$NON-NLS-1$ |
814 | 820 |
|
... | ... | |
833 | 839 |
System.out.println(NLS.bind(TXMUIMessages.AddBase_31, e)); |
834 | 840 |
} |
835 | 841 |
} else if (zipFile.isDirectory()) { |
836 |
basedir = zipFile; |
|
842 |
//basedir = zipFile; |
|
843 |
// basedir = new File(corporaDir, zipFile.getName().toUpperCase()); |
|
844 |
// if (basedir.exists()) { |
|
845 |
// System.out.println("Updating "+basedir.getName()+" corpus from TXM sample directory corpus."); |
|
846 |
// DeleteDir.deleteDirectory(basedir); |
|
847 |
// } |
|
848 |
// FileCopy.copyFiles(zipFile, basedir); // copy the sample corpus to load |
|
837 | 849 |
} else { |
838 | 850 |
System.out.println(NLS.bind(TXMUIMessages.AddBase_22, zipFile)); |
839 | 851 |
System.out.println(TXMUIMessages.AddBase_25); |
840 | 852 |
continue; |
841 | 853 |
} |
842 |
|
|
843 |
Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(basedir); |
|
844 |
if (base != null) { |
|
845 |
basenames.add(base.getName()); |
|
846 |
sampleCorpusLoaded.add(base.getName()); |
|
847 |
} |
|
854 |
|
|
855 |
// Project project = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(basedir, monitor); |
|
856 |
// if (project != null) { |
|
857 |
// basenames.add(project.getName()); |
|
858 |
// sampleCorpusLoaded.add(project.getName()); |
|
859 |
// } |
|
860 |
|
|
848 | 861 |
} catch (Exception e) { |
849 | 862 |
System.out.println(TXMUIMessages.ApplicationWorkbenchAdvisor_51+zipFile); |
850 | 863 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
851 | 864 |
} |
852 | 865 |
} |
853 | 866 |
} |
867 |
|
|
868 |
// for (File projectDir : corporaDir.listFiles()) { // load sample corpus and previous corpus as well |
|
869 |
// if (projectDir.isDirectory()) { |
|
870 |
// Project project; |
|
871 |
// try { |
|
872 |
// |
|
873 |
// } catch (Exception e) { |
|
874 |
// // TODO Auto-generated catch block |
|
875 |
// e.printStackTrace(); |
|
876 |
// } |
|
877 |
// } |
|
878 |
// } |
|
854 | 879 |
|
855 | 880 |
// after loading sample corpora, restore older corpus |
856 | 881 |
// if (backup.exists()) { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/corpuswizard/ImportWizard.java (revision 1171) | ||
---|---|---|
89 | 89 |
//project._load(params); |
90 | 90 |
} |
91 | 91 |
|
92 |
project.save(); |
|
92 |
project.saveParameters();
|
|
93 | 93 |
return true; |
94 | 94 |
} catch (Exception e) { |
95 | 95 |
e.printStackTrace(); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 1171) | ||
---|---|---|
172 | 172 |
|
173 | 173 |
Workspace w = Toolbox.workspace; |
174 | 174 |
if (w == null) return; |
175 |
treeViewer.setInput(w); |
|
176 |
treeViewer.refresh(); |
|
175 |
treeViewer.setInput(w); treeViewer.refresh(); |
|
177 | 176 |
} |
178 | 177 |
} |
179 | 178 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/results/DeleteObject.java (revision 1171) | ||
---|---|---|
184 | 184 |
if (allObjectDeleted.size() > 0) { |
185 | 185 |
|
186 | 186 |
if (shouldRestartToolbox) { |
187 |
org.txm.Toolbox.restartWorkspace(null); |
|
187 |
// org.txm.Toolbox.restartWorkspace(null);
|
|
188 | 188 |
Toolbox.getEngineManager(EngineType.SEARCH).restartEngines(); |
189 | 189 |
|
190 | 190 |
Log.info(TXMUIMessages.info_txmIsReady); |
... | ... | |
216 | 216 |
|
217 | 217 |
/** |
218 | 218 |
* Deletes the specified object. |
219 |
* |
|
220 |
* Warning: if the object is a MainCorpus then the MainCorpus' project is deleted |
|
219 | 221 |
* |
220 | 222 |
* @param o the o |
221 | 223 |
* @return the list |
... | ... | |
257 | 259 |
// } |
258 | 260 |
// // FIXME: when TXMResult will be implemented, only this code must be left |
259 | 261 |
if (o instanceof TXMResult) { |
260 |
((TXMResult) o).delete(); |
|
262 |
if (o instanceof MainCorpus) { |
|
263 |
((MainCorpus)o).getProject().delete(); |
|
264 |
} else { |
|
265 |
((TXMResult) o).delete(); |
|
266 |
} |
|
261 | 267 |
Log.info(NLS.bind(TXMUIMessages.DeleteObject_10, ((TXMResult) o))); |
262 | 268 |
deleted.add(o); |
263 | 269 |
} else { |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/CorpusPage.java (revision 1171) | ||
---|---|---|
974 | 974 |
|
975 | 975 |
if (successfulSave) { |
976 | 976 |
try { |
977 |
project.save(); |
|
977 |
project.saveParameters();
|
|
978 | 978 |
// DomUtils.save(params.root.getOwnerDocument(), paramFile); |
979 | 979 |
} catch (Exception e1) { |
980 | 980 |
org.txm.rcp.utils.Logger.printStackTrace(e1); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/Load080BinaryCorpus.java (revision 1171) | ||
---|---|---|
59 | 59 |
|
60 | 60 |
String basedirname = Zip.getRoot(zipFile); |
61 | 61 |
|
62 |
if (!Zip.hasEntries(zipFile, ".settings/", ".project")) { |
|
62 |
if (!Zip.hasEntries(zipFile, basedirname+"/.settings/", basedirname+"/.project", basedirname+"/data/", basedirname+"/txm/", basedirname+"/HTML/", basedirname+"/registry/")) { |
|
63 |
System.out.println("Binary corpus is not a TXM 0.8.0 corpus (no .settings nor .project file)"); |
|
63 | 64 |
return null; |
64 | 65 |
} |
65 | 66 |
|
... | ... | |
106 | 107 |
return null; |
107 | 108 |
} |
108 | 109 |
|
109 |
Toolbox.workspace.save(); |
|
110 |
Toolbox.workspace.saveParameters();
|
|
110 | 111 |
return base; |
111 | 112 |
} |
112 | 113 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/ConvertCorpus.java (revision 1171) | ||
---|---|---|
53 | 53 |
converter.start(); |
54 | 54 |
this.releaseSemaphore(); |
55 | 55 |
|
56 |
Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(outdir); |
|
56 |
Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(outdir, monitor);
|
|
57 | 57 |
if (base == null) { |
58 | 58 |
System.out.println(TXMUIMessages.ConvertCorpus_0); |
59 | 59 |
return Status.CANCEL_STATUS; |
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
this.acquireSemaphore(); |
63 |
org.txm.Toolbox.restartWorkspace(monitor); |
|
63 |
// org.txm.Toolbox.restartWorkspace(monitor);
|
|
64 | 64 |
Toolbox.getEngineManager(EngineType.SEARCH).restartEngines(); |
65 | 65 |
this.releaseSemaphore(); |
66 | 66 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/LoadBinaryCorporaDirectory.java (revision 1171) | ||
---|---|---|
28 | 28 |
package org.txm.rcp.commands.workspace; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.util.ArrayList; |
|
32 | 31 |
|
33 | 32 |
import org.eclipse.core.commands.AbstractHandler; |
34 | 33 |
import org.eclipse.core.commands.ExecutionEvent; |
... | ... | |
36 | 35 |
import org.eclipse.core.runtime.IProgressMonitor; |
37 | 36 |
import org.eclipse.core.runtime.IStatus; |
38 | 37 |
import org.eclipse.core.runtime.Status; |
39 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
40 |
import org.eclipse.osgi.util.NLS; |
|
41 | 38 |
import org.eclipse.swt.SWT; |
42 | 39 |
import org.eclipse.swt.widgets.DirectoryDialog; |
43 |
import org.eclipse.swt.widgets.Display; |
|
44 |
import org.eclipse.swt.widgets.FileDialog; |
|
45 | 40 |
import org.eclipse.swt.widgets.Shell; |
46 | 41 |
import org.eclipse.ui.handlers.HandlerUtil; |
47 | 42 |
import org.txm.Toolbox; |
48 |
import org.txm.Toolbox; |
|
49 | 43 |
import org.txm.core.engines.EngineType; |
50 |
import org.txm.core.preferences.TBXPreferences; |
|
51 | 44 |
import org.txm.objects.Project; |
52 |
import org.txm.objects.Project; |
|
53 |
import org.txm.objects.Workspace; |
|
54 | 45 |
import org.txm.rcp.StatusLine; |
55 | 46 |
import org.txm.rcp.commands.RestartTXM; |
56 | 47 |
import org.txm.rcp.messages.TXMUIMessages; |
57 | 48 |
import org.txm.rcp.swt.dialog.LastOpened; |
58 | 49 |
import org.txm.rcp.utils.JobHandler; |
59 |
import org.txm.rcp.views.corpora.CorporaView; |
|
60 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
61 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
62 |
import org.txm.utils.DeleteDir; |
|
63 |
import org.txm.utils.io.FileCopy; |
|
64 |
import org.txm.utils.logger.Log; |
|
65 |
import org.txm.utils.zip.Zip; |
|
50 |
import org.txm.searchengine.core.SearchEngine; |
|
51 |
import org.txm.searchengine.core.SearchEnginesManager; |
|
66 | 52 |
|
67 |
// TODO: Auto-generated Javadoc |
|
68 | 53 |
/** |
69 |
* Create a base from binary files of a base. |
|
54 |
* Create projects from one binary corpus directory |
|
55 |
* |
|
56 |
* calls LoadBinaryCorpus methods |
|
70 | 57 |
* |
71 | 58 |
* @author mdecorde |
72 | 59 |
*/ |
... | ... | |
94 | 81 |
if (directory.exists()) { |
95 | 82 |
|
96 | 83 |
LastOpened.set(ID, directory); |
97 |
return loadBinaryCorporaDirectory(directory); |
|
84 |
return loadBinaryCorpusFromCorporaDirectory(directory);
|
|
98 | 85 |
} |
99 | 86 |
} |
100 | 87 |
return null; |
... | ... | |
106 | 93 |
* @param directory |
107 | 94 |
* @return |
108 | 95 |
*/ |
109 |
public static JobHandler loadBinaryCorporaDirectory(final File directory) { |
|
110 |
|
|
96 |
public static JobHandler loadBinaryCorpusFromCorporaDirectory(final File directory) {
|
|
97 |
|
|
111 | 98 |
JobHandler jobhandler = new JobHandler("Scanning "+directory+"...", true) { |
112 | 99 |
@Override |
113 | 100 |
protected IStatus run(IProgressMonitor monitor) { |
114 | 101 |
this.runInit(monitor); |
115 | 102 |
|
103 |
try { |
|
104 |
SearchEnginesManager.getCQPSearchEngine().stop(); |
|
105 |
} catch (Exception e1) { |
|
106 |
// TODO Auto-generated catch block |
|
107 |
e1.printStackTrace(); |
|
108 |
} |
|
109 |
|
|
116 | 110 |
File corporaDirectory = new File(Toolbox.getTxmHomePath(), "corpora"); |
117 | 111 |
if (!corporaDirectory.exists()) { |
118 | 112 |
System.out.println("Corpora directory not found. Aborting."); |
113 |
try { |
|
114 |
SearchEnginesManager.getCQPSearchEngine().start(null); |
|
115 |
} catch (Exception e) { |
|
116 |
// TODO Auto-generated catch block |
|
117 |
e.printStackTrace(); |
|
118 |
} |
|
119 | 119 |
return Status.CANCEL_STATUS; |
120 | 120 |
} |
121 |
|
|
122 |
final Project newProject2 = loadBinaryCorpusFromCorporaDirectory(corporaDirectory, this, monitor); |
|
123 |
|
|
124 |
this.acquireSemaphore(); |
|
121 | 125 |
try { |
122 |
monitor.beginTask(TXMUIMessages.AddBase_27, 100); |
|
123 |
this.acquireSemaphore(); |
|
124 |
Toolbox.getEngineManager(EngineType.SEARCH).stopEngines(); |
|
125 |
this.releaseSemaphore(); |
|
126 |
SearchEnginesManager.getCQPSearchEngine().start(null); |
|
127 |
} catch (Exception e) { |
|
128 |
// TODO Auto-generated catch block |
|
129 |
e.printStackTrace(); |
|
130 |
} |
|
131 |
this.releaseSemaphore(); |
|
126 | 132 |
|
127 |
monitor.subTask(TXMUIMessages.AddBase_32); |
|
128 |
for (File corpusDirectory : directory.listFiles()) { |
|
129 |
|
|
130 |
if (corpusDirectory.isDirectory() && new File(corpusDirectory, "import.xml").exists()) { |
|
131 |
// seems like a binary corpus directory |
|
132 |
// copy files in the new current corpora directory |
|
133 |
File destDir = new File(corporaDirectory, corpusDirectory.getName()); |
|
134 |
if (destDir.exists()) { |
|
135 |
System.out.println("Le répertoire "+destDir+" existe déjà. Chargement du corpus de répertoire "+corpusDirectory.getName()+" ignoré."); |
|
136 |
continue; |
|
137 |
} |
|
138 |
|
|
139 |
FileCopy.copyFiles(corpusDirectory, destDir); |
|
140 |
|
|
141 |
corpusDirectory = destDir; |
|
142 |
} else if (corpusDirectory.getName().endsWith(".txm")) { |
|
143 |
// corpusDirectory is a TXM archive |
|
144 |
String basedirname = Zip.getRoot(corpusDirectory); |
|
145 |
File destDir = new File(corporaDirectory, basedirname); |
|
146 |
if (destDir.exists()) { |
|
147 |
System.out.println("Le répertoire "+destDir+" existe déjà. Chargement du corpus "+corpusDirectory.getName()+" ignoré."); |
|
148 |
continue; |
|
149 |
} |
|
150 |
Zip.decompress(corpusDirectory.getAbsolutePath(), corporaDirectory.getAbsolutePath(), false, this); |
|
151 |
corpusDirectory = destDir; |
|
152 |
} else { |
|
153 |
continue; // not a corpus |
|
133 |
this.syncExec(new Runnable() { |
|
134 |
@Override |
|
135 |
public void run() { |
|
136 |
|
|
137 |
if (newProject2 != null) { |
|
138 |
Project.loadTXMResultsFromProjectScope(newProject2.getRCPProject()); |
|
154 | 139 |
} |
155 |
|
|
156 |
if (!corpusDirectory.exists()) { |
|
157 |
continue; |
|
158 |
} |
|
159 |
|
|
160 |
Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory); |
|
161 |
if (base == null) { |
|
162 |
System.out.println("Fail to load binary corpus: "+corpusDirectory); |
|
163 |
} |
|
140 |
|
|
141 |
RestartTXM.reloadViews(); |
|
142 |
System.err.println(TXMUIMessages.info_txmIsReady); |
|
143 |
StatusLine.setMessage(TXMUIMessages.info_txmIsReady); |
|
164 | 144 |
} |
145 |
}); |
|
146 |
|
|
147 |
return Status.OK_STATUS; |
|
148 |
} |
|
149 |
}; |
|
165 | 150 |
|
166 |
monitor.subTask(TXMUIMessages.AddBase_33); |
|
151 |
jobhandler.schedule(); |
|
152 |
return jobhandler; |
|
153 |
} |
|
167 | 154 |
|
168 |
this.acquireSemaphore(); |
|
169 |
org.txm.Toolbox.restartWorkspace(monitor); |
|
170 |
Toolbox.getEngineManager(EngineType.SEARCH).startEngines(monitor); |
|
171 |
this.releaseSemaphore(); |
|
155 |
/** |
|
156 |
* dont manage SearchEngine state |
|
157 |
* |
|
158 |
* @param corporaDirectory |
|
159 |
* @param job |
|
160 |
* @param monitor |
|
161 |
* @return |
|
162 |
*/ |
|
163 |
protected static Project loadBinaryCorpusFromCorporaDirectory(File corporaDirectory, JobHandler job, IProgressMonitor monitor) { |
|
164 |
Project project = null; |
|
165 |
|
|
166 |
try { |
|
167 |
|
|
168 |
SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
169 |
if (engine.isRunning()) { |
|
170 |
engine.stop(); |
|
171 |
} |
|
172 |
|
|
173 |
monitor.beginTask(TXMUIMessages.AddBase_27, 100); |
|
174 |
job.acquireSemaphore(); |
|
175 |
Toolbox.getEngineManager(EngineType.SEARCH).stopEngines(); |
|
176 |
job.releaseSemaphore(); |
|
172 | 177 |
|
178 |
monitor.subTask(TXMUIMessages.AddBase_32); |
|
179 |
for (File corpusDirectory : corporaDirectory.listFiles()) { |
|
173 | 180 |
|
174 |
syncExec(new Runnable() { |
|
175 |
@Override |
|
176 |
public void run() { |
|
177 |
RestartTXM.reloadViews(); |
|
178 |
System.err.println(TXMUIMessages.info_txmIsReady); |
|
179 |
StatusLine.setMessage(TXMUIMessages.info_txmIsReady); |
|
180 |
} |
|
181 |
}); |
|
182 |
} catch (ThreadDeath td) { |
|
183 |
return Status.CANCEL_STATUS; |
|
184 |
} catch (Exception e2) { |
|
185 |
org.txm.rcp.utils.Logger.printStackTrace(e2); |
|
186 |
return Status.CANCEL_STATUS; |
|
187 |
} finally { |
|
188 |
monitor.done(); |
|
181 |
if (corpusDirectory.isDirectory()) { |
|
182 |
project = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory, monitor); |
|
183 |
} else if (corpusDirectory.getName().endsWith(".txm")) { |
|
184 |
project = LoadBinaryCorpus.loadBinaryCorpusArchive(corpusDirectory, job, monitor); |
|
185 |
} else { |
|
186 |
continue; // not a corpus |
|
189 | 187 |
} |
190 | 188 |
|
191 |
return Status.OK_STATUS; |
|
189 |
// Project base = LoadBinaryCorpus.loadBinaryCorpusAsDirectory(corpusDirectory); |
|
190 |
// if (base == null) { |
|
191 |
// System.out.println("Fail to load binary corpus: "+corpusDirectory); |
|
192 |
// } |
|
192 | 193 |
} |
193 |
}; |
|
194 | 194 |
|
195 |
jobhandler.schedule(); |
|
196 |
return jobhandler; |
|
195 |
monitor.subTask(TXMUIMessages.AddBase_33); |
|
196 |
|
|
197 |
} catch (ThreadDeath td) { |
|
198 |
return null; |
|
199 |
} catch (Exception e2) { |
|
200 |
org.txm.rcp.utils.Logger.printStackTrace(e2); |
|
201 |
return null; |
|
202 |
} finally { |
|
203 |
monitor.done(); |
|
204 |
} |
|
205 |
|
|
206 |
return project; |
|
197 | 207 |
} |
198 | 208 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/Load079BinaryCorpus.java (revision 1171) | ||
---|---|---|
64 | 64 |
|
65 | 65 |
String basedirname = Zip.getRoot(zipFile); |
66 | 66 |
|
67 |
if (!Zip.hasEntries(zipFile, "import.xml", "data")) { |
|
67 |
if (!Zip.hasEntries(zipFile, basedirname+"/import.xml", basedirname+"/data/", basedirname+"/txm/", basedirname+"/HTML/", basedirname+"/registry/")) { |
|
68 |
System.out.println("Binary corpus is not a TXM 0.7.9 corpus (no import.xml file)"); |
|
68 | 69 |
return null; |
69 | 70 |
} |
70 | 71 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/LoadBinaryCorpus.java (revision 1171) | ||
---|---|---|
55 | 55 |
import org.txm.searchengine.core.SearchEnginesManager; |
56 | 56 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
57 | 57 |
import org.txm.utils.DeleteDir; |
58 |
import org.txm.utils.io.FileCopy; |
|
58 | 59 |
import org.txm.utils.logger.Log; |
59 | 60 |
import org.txm.utils.zip.Zip; |
60 | 61 |
|
61 |
// TODO: Auto-generated Javadoc |
|
62 | 62 |
/** |
63 |
* Create a base from binary files of a base.
|
|
63 |
* Create a project from one binary file (zip or directory)
|
|
64 | 64 |
* |
65 | 65 |
* @author mdecorde |
66 | 66 |
*/ |
... | ... | |
100 | 100 |
return null; |
101 | 101 |
} |
102 | 102 |
|
103 |
private void restoreCorpus(File backup, File basedir) { |
|
104 |
System.out.println(TXMUIMessages.LoadBinaryCorpus_10+basedir.getName()+TXMUIMessages.LoadBinaryCorpus_11); |
|
105 |
if (backup.exists()) { |
|
106 |
System.out.println(TXMUIMessages.LoadBinaryCorpus_12); |
|
107 |
DeleteDir.deleteDirectory(basedir); |
|
108 |
if (basedir.exists()) { |
|
109 |
System.out.println(TXMUIMessages.LoadBinaryCorpus_13+basedir+TXMUIMessages.LoadBinaryCorpus_14+backup); |
|
110 |
return; |
|
111 |
} |
|
112 |
if (!backup.renameTo(basedir)) { |
|
113 |
System.out.println(TXMUIMessages.LoadBinaryCorpus_15+backup); |
|
114 |
return; |
|
115 |
} |
|
116 |
org.txm.Toolbox.restartWorkspace(null); |
|
117 |
Toolbox.getEngineManager(EngineType.SEARCH).restartEngines(); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 | 103 |
/** |
122 | 104 |
* Load a binary corpus archive: |
123 | 105 |
* |
... | ... | |
127 | 109 |
* 4- load the binary corpus directory |
128 | 110 |
* 5- restart TXM engines |
129 | 111 |
*/ |
130 |
public boolean loadBinaryCorpusArchive(final File zipFile) throws ExecutionException { |
|
112 |
public static boolean loadBinaryCorpusArchive(final File zipFile) throws ExecutionException {
|
|
131 | 113 |
|
132 | 114 |
String filename = zipFile.getName(); |
133 | 115 |
final File corporaDir = Toolbox.workspace.getLocation(); |
... | ... | |
144 | 126 |
return false; |
145 | 127 |
} |
146 | 128 |
|
147 |
SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
148 |
if (engine.isRunning()) { |
|
149 |
try { |
|
150 |
engine.stop(); |
|
151 |
} catch (Exception e) { |
|
152 |
// TODO Auto-generated catch block |
|
153 |
e.printStackTrace(); |
|
154 |
} |
|
129 |
try { |
|
130 |
SearchEnginesManager.getCQPSearchEngine().stop(); |
|
131 |
} catch (Exception e1) { |
|
132 |
// TODO Auto-generated catch block |
|
133 |
e1.printStackTrace(); |
|
155 | 134 |
} |
156 | 135 |
|
157 | 136 |
//build binary dir path |
158 |
basedirname = Zip.getRoot(zipFile); |
|
137 |
String basedirname = Zip.getRoot(zipFile);
|
|
159 | 138 |
|
160 |
corpusdir = new File(corporaDir, basedirname); |
|
139 |
File corpusdir = new File(corporaDir, basedirname);
|
|
161 | 140 |
|
162 | 141 |
if (corpusdir.exists()) { |
163 | 142 |
boolean b = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), TXMUIMessages.AddBase_19, NLS.bind(TXMUIMessages.AddBase_20, corpusdir.getName().toUpperCase())); |
... | ... | |
176 | 155 |
|
177 | 156 |
Project p = Toolbox.workspace.getProject(basedirname); |
178 | 157 |
if (p != null) { |
179 |
p.clean();
|
|
158 |
p.delete();
|
|
180 | 159 |
} else { |
181 | 160 |
DeleteDir.deleteDirectory(corpusdir); |
182 | 161 |
} |
183 | 162 |
|
184 | 163 |
if (corpusdir.exists()) { |
185 | 164 |
System.out.println("Error: previous binary corpus directory was not deleted: "+corpusdir); |
165 |
try { |
|
166 |
SearchEnginesManager.getCQPSearchEngine().start(null); |
|
167 |
} catch (Exception e) { |
|
168 |
// TODO Auto-generated catch block |
|
169 |
e.printStackTrace(); |
|
170 |
} |
|
186 | 171 |
return false; |
187 | 172 |
} |
188 | 173 |
} else { |
174 |
try { |
|
175 |
SearchEnginesManager.getCQPSearchEngine().start(null); |
|
176 |
} catch (Exception e) { |
|
177 |
// TODO Auto-generated catch block |
|
178 |
e.printStackTrace(); |
|
179 |
} |
|
189 | 180 |
return false; // abandon |
190 | 181 |
} |
191 | 182 |
} |
... | ... | |
196 | 187 |
@Override |
197 | 188 |
protected IStatus run(final IProgressMonitor monitor) { |
198 | 189 |
this.runInit(monitor); |
199 |
try { |
|
200 |
//CHECK ZIPPED FILE |
|
201 |
Project newProject = Load080BinaryCorpus.loadBinaryCorpus(zipFile, monitor); |
|
202 |
if (newProject == null) { |
|
203 |
newProject = Load079BinaryCorpus.loadBinaryCorpusArchive(zipFile, monitor); |
|
204 |
} |
|
205 |
if (newProject == null) { |
|
206 |
System.out.println("Error: cant load corpus from file="+zipFile); |
|
207 |
return Status.CANCEL_STATUS; |
|
208 |
} |
|
209 |
|
|
210 |
final Project newProject2 = newProject; |
|
211 |
syncExec(new Runnable() { |
|
212 |
@Override |
|
213 |
public void run() { |
|
214 |
|
|
215 |
SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
216 |
if (!engine.isRunning()) { |
|
217 |
try { |
|
218 |
engine.start(monitor); |
|
219 |
} catch (Exception e) { |
|
220 |
// TODO Auto-generated catch block |
|
221 |
e.printStackTrace(); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
190 |
final Project newProject2 = loadBinaryCorpusArchive(zipFile, this, monitor); |
|
191 |
|
|
192 |
this.syncExec(new Runnable() { |
|
193 |
@Override |
|
194 |
public void run() { |
|
195 |
|
|
196 |
try { |
|
197 |
SearchEnginesManager.getCQPSearchEngine().start(); |
|
198 |
} catch (Exception e) { |
|
199 |
e.printStackTrace(); |
|
200 |
} |
|
201 |
|
|
202 |
if (newProject2 != null) { |
|
203 |
Project.loadTXMResultsFromProjectScope(newProject2.getRCPProject()); |
|
225 | 204 |
RestartTXM.reloadViews(); |
226 | 205 |
//System.out.println("Select newly loaded corpus: "+base2.getCorpora().values()); |
227 | 206 |
CorporaView.select(newProject2.getChildren(MainCorpus.class)); |
228 | 207 |
System.err.println(TXMUIMessages.info_txmIsReady); |
229 | 208 |
StatusLine.setMessage(TXMUIMessages.info_txmIsReady); |
209 |
} else { |
|
210 |
System.out.println("Error: no project loaded."); |
|
230 | 211 |
} |
231 |
}); |
|
232 |
} catch (ThreadDeath td) { |
|
233 |
return Status.CANCEL_STATUS; |
|
234 |
} catch (Exception e2) { |
|
235 |
org.txm.rcp.utils.Logger.printStackTrace(e2); |
|
236 |
} finally { |
|
237 |
SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
238 |
if (!engine.isRunning()) { |
|
239 |
try { |
|
240 |
engine.start(monitor); |
|
241 |
} catch (Exception e) { |
|
242 |
// TODO Auto-generated catch block |
|
243 |
e.printStackTrace(); |
|
244 |
} |
|
245 | 212 |
} |
246 |
monitor.done(); |
|
247 |
} |
|
213 |
}); |
|
248 | 214 |
return Status.OK_STATUS; |
249 | 215 |
//return Status.CANCEL_STATUS; |
250 | 216 |
} |
... | ... | |
258 | 224 |
|
259 | 225 |
return true; |
260 | 226 |
} |
227 |
|
|
228 |
/** |
|
229 |
* don't manage the SearchEngine restart |
|
230 |
* |
|
231 |
* @param zipFile |
|
232 |
* @param jobhandler |
|
233 |
* @param monitor |
|
234 |
* @return |
|
235 |
*/ |
|
236 |
public static Project loadBinaryCorpusArchive(File zipFile, JobHandler jobhandler, final IProgressMonitor monitor) { |
|
237 |
Project project = null; |
|
238 |
try { |
|
239 |
SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
240 |
if (engine.isRunning()) { |
|
241 |
engine.stop(); |
|
242 |
} |
|
243 |
|
|
244 |
//CHECK ZIPPED FILE |
|
245 |
project = Load080BinaryCorpus.loadBinaryCorpus(zipFile, monitor); |
|
246 |
if (project == null) { |
|
247 |
project = Load079BinaryCorpus.loadBinaryCorpusArchive(zipFile, monitor); |
|
248 |
} |
|
249 |
if (project == null) { |
|
250 |
System.out.println("Error: cant load corpus from file="+zipFile); |
|
251 |
return null; |
|
252 |
} |
|
253 |
|
|
254 |
// final Project newProject2 = project; |
|
255 |
// jobhandler.syncExec(new Runnable() { |
|
256 |
// @Override |
|
257 |
// public void run() { |
|
258 |
// |
|
259 |
// SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
260 |
// if (!engine.isRunning()) { |
|
261 |
// try { |
|
262 |
// engine.start(monitor); |
|
263 |
// } catch (Exception e) { |
|
264 |
// // TODO Auto-generated catch block |
|
265 |
// e.printStackTrace(); |
|
266 |
// } |
|
267 |
// } |
|
268 |
// |
|
269 |
// RestartTXM.reloadViews(); |
|
270 |
// //System.out.println("Select newly loaded corpus: "+base2.getCorpora().values()); |
|
271 |
// CorporaView.select(newProject2.getChildren(MainCorpus.class)); |
|
272 |
// System.err.println(TXMUIMessages.info_txmIsReady); |
|
273 |
// StatusLine.setMessage(TXMUIMessages.info_txmIsReady); |
|
274 |
// } |
|
275 |
// }); |
|
276 |
} catch (ThreadDeath td) { |
|
277 |
return null; |
|
278 |
} catch (Exception e2) { |
|
279 |
org.txm.rcp.utils.Logger.printStackTrace(e2); |
|
280 |
return null; |
|
281 |
} finally { |
|
282 |
|
|
283 |
} |
|
284 |
return project; |
|
285 |
} |
|
261 | 286 |
|
262 | 287 |
/** |
263 | 288 |
* load the content of the file if its a directory containing at least the sub folders : |
... | ... | |
267 | 292 |
* @return the base |
268 | 293 |
* @throws Exception the exception |
269 | 294 |
*/ |
270 |
public static Project loadBinaryCorpusAsDirectory(File binCorpusDirectory) throws Exception {
|
|
271 |
if (!(binCorpusDirectory.exists() && binCorpusDirectory.isDirectory())) {
|
|
272 |
Log.severe(NLS.bind(TXMUIMessages.AddBase_24, binCorpusDirectory.getAbsolutePath()));
|
|
273 |
System.out.println(NLS.bind(TXMUIMessages.AddBase_24, binCorpusDirectory.getAbsolutePath()));
|
|
295 |
public static Project loadBinaryCorpusAsDirectory(File corpusDirectory, IProgressMonitor monitor) throws Exception {
|
|
296 |
if (!(corpusDirectory.exists() && corpusDirectory.isDirectory())) {
|
|
297 |
Log.severe(NLS.bind(TXMUIMessages.AddBase_24, corpusDirectory.getAbsolutePath()));
|
|
298 |
System.out.println(NLS.bind(TXMUIMessages.AddBase_24, corpusDirectory.getAbsolutePath()));
|
|
274 | 299 |
return null; |
275 | 300 |
} |
276 | 301 |
|
277 |
//File txmregistry = new File(Toolbox.getTxmHomePath(), "registry"); //$NON-NLS-1$ |
|
278 |
//txmregistry.mkdir(); |
|
279 |
File txmcorpora = new File(Toolbox.getTxmHomePath(), "corpora"); //$NON-NLS-1$ |
|
280 |
txmcorpora.mkdir(); |
|
281 |
Project base = Toolbox.workspace.scanDirectory(binCorpusDirectory); |
|
282 |
if (base == null) { |
|
283 |
Log.severe(NLS.bind(TXMUIMessages.AddBase_2, binCorpusDirectory)); |
|
284 |
return null; |
|
302 |
SearchEngine engine = SearchEnginesManager.getCQPSearchEngine(); |
|
303 |
if (engine.isRunning()) { |
|
304 |
engine.stop(); |
|
285 | 305 |
} |
286 |
|
|
287 |
Toolbox.workspace.save(); |
|
288 |
return base; |
|
306 |
|
|
307 |
// //File txmregistry = new File(Toolbox.getTxmHomePath(), "registry"); //$NON-NLS-1$ |
|
308 |
// //txmregistry.mkdir(); |
|
309 |
// File txmcorpora = new File(Toolbox.getTxmHomePath(), "corpora"); //$NON-NLS-1$ |
|
310 |
// txmcorpora.mkdir(); |
|
311 |
// Project base = Toolbox.workspace.scanDirectory(binCorpusDirectory); |
|
312 |
// if (base == null) { |
|
313 |
// Log.severe(NLS.bind(TXMUIMessages.AddBase_2, binCorpusDirectory)); |
|
314 |
// return null; |
|
315 |
// } |
|
316 |
// |
|
317 |
// Toolbox.workspace.save(); |
|
318 |
|
|
319 |
// seems like a binary corpus directory |
|
320 |
// copy files in the new current corpora directory |
|
321 |
File destDir = new File(Toolbox.workspace.getLocation(), corpusDirectory.getName().toUpperCase()); |
|
322 |
if (!destDir.equals(corpusDirectory) && !destDir.exists()) { |
|
323 |
FileCopy.copyFiles(corpusDirectory, destDir); // the corpus directory is not in the corpora directory |
|
324 |
} |
|
325 |
|
|
326 |
Project project = null; |
|
327 |
File paramFile = new File(destDir, ".settings"); |
|
328 |
if (paramFile.exists() && paramFile.isDirectory()) { |
|
329 |
project = Load080BinaryCorpus.loadBinaryCorpusAsDirectory(destDir); |
|
330 |
// continue; |
|
331 |
} |
|
332 |
|
|
333 |
paramFile = new File(destDir, "import.xml"); |
|
334 |
if (paramFile.exists()) { |
|
335 |
project = Load079BinaryCorpus.loadBinaryCorpusAsDirectory(destDir, null); |
|
336 |
// continue; |
|
337 |
} |
|
338 |
|
|
339 |
return project; |
|
289 | 340 |
} |
290 | 341 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/ImportSelectedText.java (revision 1171) | ||
---|---|---|
43 | 43 |
import org.txm.Toolbox; |
44 | 44 |
import org.txm.core.preferences.TBXPreferences; |
45 | 45 |
import org.txm.objects.Project; |
46 |
import org.txm.objects.Workspace; |
|
46 | 47 |
import org.txm.rcp.handlers.scripts.ExecuteImportScript; |
47 | 48 |
import org.txm.rcp.messages.TXMUIMessages; |
48 | 49 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
... | ... | |
127 | 128 |
|
128 | 129 |
|
129 | 130 |
// configure project |
130 |
Project project = Toolbox.workspace.getProject(clipboardDirectory.getName()); |
|
131 |
Workspace w = Toolbox.workspace; |
|
132 |
Project project = w.getProject(clipboardDirectory.getName()); |
|
131 | 133 |
if (project == null) { |
132 |
project = new Project(Toolbox.workspace, clipboardDirectory.getName());
|
|
134 |
project = new Project(w, clipboardDirectory.getName());
|
|
133 | 135 |
} |
134 | 136 |
project.setSourceDirectory(clipboardDirectory.getAbsolutePath()); |
135 | 137 |
project.setImportModuleName("txt"); |
tmp/org.txm.rcp/plugin.xml (revision 1171) | ||
---|---|---|
29 | 29 |
<product |
30 | 30 |
application="org.txm.rcp.Application" |
31 | 31 |
description="%product.description" |
32 |
name="%product.name.3">
|
|
32 |
name="TXM">
|
|
33 | 33 |
<property |
34 | 34 |
name="appName" |
35 | 35 |
value="TXM"> |
... | ... | |
2074 | 2074 |
</command> |
2075 | 2075 |
<command |
2076 | 2076 |
commandId="org.txm.rcp.handlers.results.SetTXMResultPersistentState" |
2077 |
icon="icons/decorators/bullet_green.png" |
|
2078 | 2077 |
mode="FORCE_TEXT" |
2079 | 2078 |
style="toggle"> |
2080 | 2079 |
<visibleWhen |
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 1171) | ||
---|---|---|
106 | 106 |
* Parameters node path. Concatenation of the Project scope path + the result uuid |
107 | 107 |
*/ |
108 | 108 |
protected String parametersNodePath; |
109 |
|
|
109 |
|
|
110 | 110 |
/** |
111 | 111 |
* If set, allows the command to notify its progress. |
112 | 112 |
*/ |
... | ... | |
124 | 124 |
// The problem is since the result is already computing, the parameters are already updated and the method hasParameterChanged() will always return false. Using this stack fix the problem. |
125 | 125 |
// But this stack is also the start for an UNDO command on TXMResult. |
126 | 126 |
protected ArrayList<HashMap<String, Object>> parametersHistory = new ArrayList<HashMap<String, Object>>(); |
127 |
|
|
128 | 127 |
|
128 |
|
|
129 | 129 |
/** |
130 | 130 |
* Internal persistable state. |
131 | 131 |
*/ |
... | ... | |
136 | 136 |
*/ |
137 | 137 |
protected boolean userPersistable; |
138 | 138 |
|
139 |
|
|
140 |
|
|
139 |
|
|
140 |
|
|
141 | 141 |
/** |
142 | 142 |
* The visibility state. |
143 | 143 |
*/ |
... | ... | |
159 | 159 |
|
160 | 160 |
|
161 | 161 |
|
162 |
|
|
163 | 162 |
|
163 |
|
|
164 | 164 |
/** |
165 | 165 |
* Creates a new TXMResult, child of the specified parent. |
166 | 166 |
* @param parent |
... | ... | |
177 | 177 |
public TXMResult(String parametersNodePath) { |
178 | 178 |
this(parametersNodePath, null); |
179 | 179 |
} |
180 |
|
|
180 |
|
|
181 | 181 |
/** |
182 | 182 |
* Creates a new TXMResult, child of the specified parent. |
183 | 183 |
* If the parameters node path is null, a new path is generated from the project root path ending by a new generated UUID. |
... | ... | |
192 | 192 |
if (parent != null) { |
193 | 193 |
parent.addChild(this); |
194 | 194 |
} |
195 |
|
|
195 |
|
|
196 | 196 |
if (parametersNodePath == null) { |
197 | 197 |
this.uniqueID = createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$ |
198 | 198 |
if (this.getProject() != null) { |
... | ... | |
213 | 213 |
|
214 | 214 |
Log.finest("TXMResult.TXMResult(): parameters node path: " + this.parametersNodePath); |
215 | 215 |
|
216 |
|
|
216 |
|
|
217 | 217 |
this.weight = 0; |
218 | 218 |
|
219 | 219 |
this.children = new ArrayList<TXMResult>(1); |
... | ... | |
222 | 222 |
this.commandPreferencesNodePath = FrameworkUtil.getBundle(getClass()).getSymbolicName(); //$NON-NLS-1$ |
223 | 223 |
Log.finest("TXMResult.TXMResult(): command preferences node path: " + this.commandPreferencesNodePath); |
224 | 224 |
|
225 |
|
|
225 |
|
|
226 | 226 |
this.visible = true; |
227 | 227 |
this.dirty = true; |
228 | 228 |
this.internalPersistable = false; |
... | ... | |
231 | 231 |
|
232 | 232 |
// retrieving parent from UUID |
233 | 233 |
String parentUUID = this.getStringParameterValue(TXMPreferences.PARENT_UUID); |
234 |
|
|
234 |
|
|
235 | 235 |
//System.out.println("TXMResult.TXMResult(): parent UUID = " + parentUUID); |
236 |
|
|
236 |
|
|
237 | 237 |
if (!("ROOT".equals(this.uniqueID)) && // search for parent only if UUID != "ROOT" |
238 | 238 |
parent == null && |
239 | 239 |
this.uniqueID != null && |
... | ... | |
260 | 260 |
Log.severe("Fail to load " + uniqueID + "result: " + e); |
261 | 261 |
Log.printStackTrace(e); |
262 | 262 |
} |
263 |
|
|
263 |
|
|
264 | 264 |
// Log |
265 | 265 |
if (this.parent == null) { |
266 | 266 |
Log.warning("Warning: the TXMResult of " + this.getClass() + " is attached to no parent. (uuid = " + this.getUUID() + ")"); |
267 | 267 |
} |
268 |
|
|
268 |
|
|
269 | 269 |
try { |
270 | 270 |
this.parametersHistory.add(new HashMap<String, Object>()); |
271 | 271 |
//this.updateLastParameters(); |
... | ... | |
294 | 294 |
//this.uniqueID = this.getClass().getName() + '@' + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + UUID.randomUUID(); |
295 | 295 |
return UUID_PREFIX + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + UUID.randomUUID(); |
296 | 296 |
} |
297 |
|
|
297 |
|
|
298 | 298 |
/** |
299 | 299 |
* Checks if the result at least one child. |
300 | 300 |
* @return |
... | ... | |
303 | 303 |
return this.children.size() > 0; |
304 | 304 |
} |
305 | 305 |
|
306 |
|
|
306 |
|
|
307 | 307 |
/** |
308 | 308 |
* Gets the preferences node path of the result command. |
309 | 309 |
* |
... | ... | |
313 | 313 |
return this.commandPreferencesNodePath; |
314 | 314 |
} |
315 | 315 |
|
316 |
|
|
316 |
|
|
317 | 317 |
public String[] getCommandPreferencesKeys() throws BackingStoreException { |
318 | 318 |
return TXMPreferences.getCommandScopeKeys(this.commandPreferencesNodePath); |
319 | 319 |
} |
... | ... | |
331 | 331 |
public Object getParameter(String key) { |
332 | 332 |
return getParameter(key, false); |
333 | 333 |
} |
334 |
|
|
334 |
|
|
335 | 335 |
/** |
336 | 336 |
* Gets a current parameter specified by its annotation "key" attribute and its annotation "type" attribute. |
337 | 337 |
* @param key |
... | ... | |
392 | 392 |
|
393 | 393 |
List<Field> fields = new ArrayList<Field>(); |
394 | 394 |
Class<?> clazz = this.getClass(); |
395 |
|
|
395 |
|
|
396 | 396 |
while (clazz != Object.class) { |
397 | 397 |
fields.addAll(Arrays.asList(clazz.getDeclaredFields())); |
398 | 398 |
clazz = clazz.getSuperclass(); |
... | ... | |
419 | 419 |
protected void updateLastParameters(int parameterType, boolean appendToLastParameters) throws Exception { |
420 | 420 |
|
421 | 421 |
HashMap<String, Object> lastParameters; |
422 |
|
|
422 |
|
|
423 | 423 |
if(appendToLastParameters) { |
424 | 424 |
lastParameters = this.getLastParametersFromHistory(); |
425 | 425 |
} |
426 | 426 |
else { |
427 | 427 |
lastParameters = new HashMap<>(); |
428 | 428 |
} |
429 |
|
|
429 |
|
|
430 | 430 |
List<Field> fields = this.getAllFields(); |
431 | 431 |
|
432 | 432 |
for (Field f : fields) { |
... | ... | |
446 | 446 |
f.setAccessible(true); |
447 | 447 |
lastParameters.put(name, f.get(this)); |
448 | 448 |
} |
449 |
|
|
449 |
|
|
450 | 450 |
if(!appendToLastParameters) { |
451 | 451 |
this.parametersHistory.add(lastParameters); |
452 | 452 |
} |
453 |
|
|
453 |
|
|
454 | 454 |
// truncate the stack to the max count |
455 | 455 |
// FIXME: store this in a TBX preference |
456 | 456 |
if(this.parametersHistory.size() > 5) { |
... | ... | |
458 | 458 |
this.parametersHistory.remove(0); |
459 | 459 |
this.parametersHistory.remove(0); |
460 | 460 |
} |
461 |
|
|
461 |
|
|
462 | 462 |
} |
463 |
|
|
463 |
|
|
464 | 464 |
/** |
465 | 465 |
* Stores the last parameters used for computing. |
466 | 466 |
* @throws Exception |
... | ... | |
547 | 547 |
if (this.isDirty()) { |
548 | 548 |
return true; |
549 | 549 |
} |
550 |
|
|
550 |
|
|
551 | 551 |
Object lastValue = lastParameters.get(key); |
552 | 552 |
Object newValue = this.getParameter(key); |
553 | 553 |
if (lastValue == null) { |
... | ... | |
680 | 680 |
* @throws IllegalArgumentException |
681 | 681 |
*/ |
682 | 682 |
public final boolean isDirtyFromHistory() throws Exception { |
683 |
|
|
683 |
|
|
684 | 684 |
Class clazz = this.getClass(); |
685 | 685 |
|
686 | 686 |
Field[] fields = clazz.getDeclaredFields(); |
... | ... | |
703 | 703 |
} |
704 | 704 |
|
705 | 705 |
f.setAccessible(true); // to be able to test the field values |
706 |
|
|
706 |
|
|
707 | 707 |
Object previousValue = this.getLastParametersFromHistory().get(name); |
708 | 708 |
Object newValue = f.get(this); |
709 | 709 |
|
710 |
// // FIXME: debug |
|
711 |
// Log.finest("TXMResult.isDirtyFromHistory(): checking parameter: " + name); |
|
710 |
// // FIXME: debug
|
|
711 |
// Log.finest("TXMResult.isDirtyFromHistory(): checking parameter: " + name);
|
|
712 | 712 |
|
713 | 713 |
this.updateDirty(previousValue, newValue); |
714 | 714 |
if (this.dirty) { |
... | ... | |
719 | 719 |
return this.dirty; |
720 | 720 |
} |
721 | 721 |
|
722 |
|
|
722 |
|
|
723 | 723 |
public HashMap<String, Object> getLastParametersFromHistory() { |
724 | 724 |
return this.parametersHistory.get(this.parametersHistory.size() - 1); |
725 | 725 |
} |
726 |
|
|
726 |
|
|
727 | 727 |
/** |
728 | 728 |
* Gets the dirty state. |
729 | 729 |
* |
... | ... | |
820 | 820 |
public boolean parameterExists(String key) { |
821 | 821 |
return TXMPreferences.keyExists(this.parametersNodePath, key); |
822 | 822 |
} |
823 |
|
|
823 |
|
|
824 | 824 |
/** |
825 | 825 |
* Checks if a preference is empty (equals to "") in the command preference node. |
826 | 826 |
* An empty preference can be used to disable a functionality for a kind of result |
... | ... | |
871 | 871 |
|
872 | 872 |
// internal data to save for unserialization |
873 | 873 |
this.saveParameter("class", this.getClass().getName()); //$NON-NLS-1$ |
874 |
|
|
874 |
|
|
875 | 875 |
this.saveParameter(TXMPreferences.RESULT_PARAMETERS_NODE_PATH, this.parametersNodePath); |
876 | 876 |
this.saveParameter(TXMPreferences.RESULT_UUID, this.uniqueID); |
877 | 877 |
this.saveParameter(TXMPreferences.BUNDLE_ID, this.commandPreferencesNodePath); |
... | ... | |
898 | 898 |
f.getType().isAssignableFrom(float.class) || f.getType().isAssignableFrom(Float.class) || |
899 | 899 |
f.getType().isAssignableFrom(boolean.class) || f.getType().isAssignableFrom(Boolean.class) || |
900 | 900 |
f.getType().isAssignableFrom(String.class) |
901 |
|
|
901 |
|
|
902 | 902 |
// FIXME: do not pass a Serializable for now |
903 | 903 |
//|| !f.getType().isAssignableFrom(Serializable.class) |
904 | 904 |
//|| !Serializable.class.isInstance(f) |
905 |
|
|
905 |
|
|
906 | 906 |
) { |
907 |
|
|
908 |
|
|
907 |
|
|
908 |
|
|
909 | 909 |
f.setAccessible(true); // set accessible to test the field values |
910 | 910 |
try { |
911 | 911 |
Object value = f.get(this); |
... | ... | |
929 | 929 |
*/ |
930 | 930 |
public abstract boolean saveParameters() throws Exception; |
931 | 931 |
|
932 |
/** |
|
933 |
* calls saveParameters() on this and children if childrenAsWell is set to true |
|
934 |
* |
|
935 |
* only children |
|
936 |
* |
|
937 |
* @param childrenAsWell save the children parameters as well |
|
938 |
* @return true if all saves were successful |
|
939 |
* @throws Exception |
|
940 |
*/ |
|
941 |
public boolean saveParameters(boolean childrenAsWell) throws Exception { |
|
932 | 942 |
|
943 |
boolean ret = true; |
|
944 |
|
|
945 |
if (this.mustBePersisted()) { |
|
946 |
ret = this.saveParameters(); |
|
947 |
if (childrenAsWell) { |
|
948 |
for (TXMResult r : getChildren()) { |
|
949 |
ret = ret && r.saveParameters(childrenAsWell); |
|
950 |
} |
|
951 |
} |
|
952 |
} |
|
953 |
return ret; |
|
954 |
} |
|
955 |
|
|
956 |
public void persist(boolean childrenAsWell) { |
|
957 |
if (this.mustBePersisted()) { |
|
958 |
TXMPreferences.flush(this); |
|
959 |
for (TXMResult r : getChildren()) { |
|
960 |
r.persist(childrenAsWell); |
|
961 |
} |
|
962 |
} |
|
963 |
} |
|
964 |
|
|
933 | 965 |
/** |
934 | 966 |
* |
935 | 967 |
* @return |
... | ... | |
1040 | 1072 |
public boolean setParameter(String key, Object value) throws Exception { |
1041 | 1073 |
return setParameter(key, value, false); |
1042 | 1074 |
} |
1043 |
|
|
1075 |
|
|
1044 | 1076 |
/** |
1045 | 1077 |
* Sets a parameters from its parameter annotation "key". |
1046 | 1078 |
* @param key |
... | ... | |
1101 | 1133 |
while (this.children.size() > 0) { |
1102 | 1134 |
TXMResult c = this.children.get(0); |
1103 | 1135 |
c.delete(); // should call parent.removeResult(child) |
1104 |
// TXMPreferences.delete(this.children.get(i)); |
|
1105 |
// this.removeChild(i); |
|
1136 |
// TXMPreferences.delete(this.children.get(i));
|
|
1137 |
// this.removeChild(i);
|
|
1106 | 1138 |
this.children.remove(c); // but should be done already... |
1107 | 1139 |
} |
1108 | 1140 |
this.children.clear(); |
1109 |
|
|
1141 |
|
|
1110 | 1142 |
//THEN FINISH WITH THIS |
1111 | 1143 |
// delete the local node |
1112 | 1144 |
TXMPreferences.delete(this); |
1113 |
|
|
1145 |
|
|
1114 | 1146 |
// specific cleaning |
1115 | 1147 |
this.clean(); |
1116 | 1148 |
|
... | ... | |
1319 | 1351 |
children.get(i).delete(); |
1320 | 1352 |
} |
1321 | 1353 |
} |
1322 |
|
|
1323 | 1354 |
|
1355 |
|
|
1324 | 1356 |
/** |
1325 | 1357 |
* Gets the first child. |
1326 | 1358 |
* @param classSimpleName |
... | ... | |
1407 | 1439 |
&& (onlyVisible == false || child.isVisible())) { |
1408 | 1440 |
nodes.add(child); |
1409 | 1441 |
} |
1410 |
|
|
1442 |
|
|
1411 | 1443 |
// add children of a non visible result |
1412 | 1444 |
else if (!child.isVisible() && child.hasChildren()) { |
1413 | 1445 |
List<TXMResult> subChidlren = child.getChildren(type, onlyVisible); |
... | ... | |
1427 | 1459 |
public int getChildrenCount() { |
1428 | 1460 |
return this.children.size(); |
1429 | 1461 |
} |
1430 |
|
|
1431 |
|
|
1462 |
|
|
1463 |
|
|
1432 | 1464 |
/** |
1433 | 1465 |
* Gets the root parent of the branch. |
1434 | 1466 |
* @return |
... | ... | |
1458 | 1490 |
if(parent.getClass().equals(type)) { |
1459 | 1491 |
node = parent; |
1460 | 1492 |
} |
1461 |
|
|
1493 |
|
|
1462 | 1494 |
parent = parent.getParent(); |
1463 | 1495 |
} |
1464 | 1496 |
} while (parent != null && node == null); |
... | ... | |
1466 | 1498 |
return node; |
1467 | 1499 |
} |
1468 | 1500 |
|
1469 |
|
|
1470 | 1501 |
|
1502 |
|
|
1471 | 1503 |
// /** |
1472 | 1504 |
// * Gets the first parent of the specified class, eg. this.getFirstParent(Partition.class); |
1473 | 1505 |
// * Returns the object itself if it is of the specified class. |
... | ... | |
1788 | 1820 |
protected boolean compute(IProgressMonitor monitor, boolean deepComputing) { |
1789 | 1821 |
|
1790 | 1822 |
try { |
1791 |
|
|
1792 |
|
|
1823 |
|
|
1824 |
|
|
1793 | 1825 |
Log.finest("*** TXMResult.compute(): " + this.getClass().getSimpleName() + ": starting computing process..."); |
1794 |
|
|
1826 |
|
|
1795 | 1827 |
// FIXME: see if this skipComputing tests is still useful? is it possible to directly return instead? |
1796 | 1828 |
// en fait voir ChartResult.compute() if(super.compute(monitor, true, false)), je pense que le prob vient du fait que si on retourne false dans TXMResult.compute() alors renderChart() ne sera pas appelé |
1797 | 1829 |
boolean skipComputing = false; |
... | ... | |
1804 | 1836 |
// SJ: other way, test the object itself |
1805 | 1837 |
// FIXME: this code shoud be moved back in the !skipComputing section ? |
1806 | 1838 |
if (this.parent != null && !(this.parent instanceof Project)) { |
1807 |
|
|
1839 |
|
|
1808 | 1840 |
Log.finest("TXMResult.compute(): " + this.getClass().getSimpleName() + ": starting parent (" + this.parent.getClass().getSimpleName() + ") computing process..."); |
1809 |
|
|
1841 |
|
|
1810 | 1842 |
if (!this.parent.compute(monitor, true)) { |
1811 | 1843 |
Log.severe("TXMResult.compute(): " + this.getClass().getSimpleName() + ": failed to compute parent result."); |
1812 | 1844 |
|
1813 | 1845 |
return false; |
1814 | 1846 |
} |
1815 | 1847 |
} |
1816 |
|
|
1848 |
|
|
1817 | 1849 |
boolean d1 = this.isDirtyFromHistory(); |
1818 | 1850 |
boolean d2 = this.isDirty(); |
1819 | 1851 |
if (!d1 && !d2) { |
... | ... | |
1831 | 1863 |
// TODO where do we put this parent compute ? :o |
1832 | 1864 |
// if (parent != null && !parent.getHasBeenComputedOnce()) { // parent must be computed at least one time |
1833 | 1865 |
// SJ: other way, test the object itself |
1834 |
// if (this.parent != null && !(this.parent instanceof Project)) { |
|
1835 |
// if (!this.parent.compute(monitor, true)) { |
|
1836 |
// Log.severe("TXMResult.compute(): " + this.getClass().getSimpleName() + ": failed to compute parent result."); |
|
1837 |
// |
|
1838 |
// //return false; |
|
1839 |
// } |
|
1840 |
// } |
|
1866 |
// if (this.parent != null && !(this.parent instanceof Project)) {
|
|
1867 |
// if (!this.parent.compute(monitor, true)) {
|
|
1868 |
// Log.severe("TXMResult.compute(): " + this.getClass().getSimpleName() + ": failed to compute parent result.");
|
|
1869 |
//
|
|
1870 |
// //return false;
|
|
1871 |
// }
|
|
1872 |
// }
|
|
1841 | 1873 |
|
1842 |
|
|
1874 |
|
|
1843 | 1875 |
// Computing requirements test |
1844 | 1876 |
if (!this.canCompute()) { |
1845 | 1877 |
Log.severe("TXMResult.compute(): " + this.getClass().getSimpleName() + ": can not compute, missing or wrong parameters or error with parent computing, computing aborted."); |
Formats disponibles : Unified diff