17 |
17 |
import org.txm.annotation.kr.core.AnnotationManager;
|
18 |
18 |
import org.txm.annotation.kr.core.KRAnnotationEngine;
|
19 |
19 |
import org.txm.annotation.kr.core.preferences.KRAnnotationPreferences;
|
20 |
|
import org.txm.concordance.rcp.editors.ConcordanceEditor;
|
21 |
|
import org.txm.core.results.TXMResult;
|
22 |
|
import org.txm.objects.CorpusBuild;
|
23 |
20 |
import org.txm.objects.Workspace;
|
24 |
21 |
import org.txm.rcp.commands.workspace.UpdateCorpus;
|
25 |
22 |
import org.txm.rcp.messages.TXMUIMessages;
|
... | ... | |
33 |
30 |
|
34 |
31 |
public static final String ID = SaveAnnotationsAndUpdateCorpus.class.getCanonicalName();
|
35 |
32 |
|
|
33 |
LinkedHashMap<String, MainCorpus> selectedCorporaToSave = null;
|
|
34 |
|
36 |
35 |
@Override
|
37 |
36 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
38 |
37 |
|
39 |
|
// ISelection sel = HandlerUtil.getCurrentSelection(event);
|
40 |
|
// if (!(sel instanceof IStructuredSelection)) {
|
41 |
|
// Log.info("No available selection to target the corpus annotations to save");
|
42 |
|
// return null;
|
43 |
|
// }
|
44 |
|
// IStructuredSelection selection = (IStructuredSelection) sel;
|
45 |
|
//
|
46 |
|
// MainCorpus corpus = null;
|
47 |
|
//
|
48 |
|
// if (HandlerUtil.getActiveEditor(event) instanceof ConcordanceEditor) {
|
49 |
|
// corpus = ((ConcordanceEditor) HandlerUtil.getActiveEditor(event)).getCorpus().getMainCorpus();
|
50 |
|
// } else {
|
51 |
|
// Object s = selection.getFirstElement();
|
52 |
|
// if (s == null) {
|
53 |
|
// Log.info("No available selection to target the corpus annotations to save");
|
54 |
|
// return null;
|
55 |
|
// } else if ((s instanceof MainCorpus)) {
|
56 |
|
// corpus = (MainCorpus) s;
|
57 |
|
// } else if (s instanceof TXMResult) {
|
58 |
|
// corpus = ((TXMResult) s).getFirstParent(MainCorpus.class);
|
59 |
|
// } else {
|
60 |
|
// Log.info("No available selection to target the corpus annotations to save");
|
61 |
|
// return null;
|
62 |
|
// }
|
63 |
|
// }
|
64 |
|
//
|
|
38 |
selectedCorporaToSave = null;
|
|
39 |
ISelection sel = HandlerUtil.getCurrentSelection(event);
|
|
40 |
IStructuredSelection selection = null;
|
|
41 |
if (sel instanceof IStructuredSelection) {
|
|
42 |
selection = (IStructuredSelection) sel;
|
|
43 |
}
|
|
44 |
if (selection.size() > 0) {
|
|
45 |
if (selection.getFirstElement() instanceof MainCorpus) {
|
|
46 |
MainCorpus corpus = (MainCorpus) selection.getFirstElement();
|
|
47 |
|
|
48 |
AnnotationManager am;
|
|
49 |
try {
|
|
50 |
am = KRAnnotationEngine.getAnnotationManager(corpus);
|
|
51 |
if (am == null) {
|
|
52 |
Log.warning("No annotation to save for: "+corpus);
|
|
53 |
return null; // nothing to do
|
|
54 |
}
|
|
55 |
|
|
56 |
if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) {
|
|
57 |
Log.warning("No annotation to save for: "+corpus);
|
|
58 |
return null;
|
|
59 |
}
|
|
60 |
|
|
61 |
selectedCorporaToSave = new LinkedHashMap<>();
|
|
62 |
selectedCorporaToSave.put(corpus.getName(), corpus);
|
|
63 |
}
|
|
64 |
catch (Exception e) {
|
|
65 |
// TODO Auto-generated catch block
|
|
66 |
e.printStackTrace();
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
}
|
|
72 |
}
|
|
73 |
//
|
|
74 |
// MainCorpus corpus = null;
|
|
75 |
//
|
|
76 |
// if (HandlerUtil.getActiveEditor(event) instanceof ConcordanceEditor) {
|
|
77 |
// corpus = ((ConcordanceEditor) HandlerUtil.getActiveEditor(event)).getCorpus().getMainCorpus();
|
|
78 |
// } else {
|
|
79 |
// Object s = selection.getFirstElement();
|
|
80 |
// if (s == null) {
|
|
81 |
// Log.info("No available selection to target the corpus annotations to save");
|
|
82 |
// return null;
|
|
83 |
// } else if ((s instanceof MainCorpus)) {
|
|
84 |
// corpus = (MainCorpus) s;
|
|
85 |
// } else if (s instanceof TXMResult) {
|
|
86 |
// corpus = ((TXMResult) s).getFirstParent(MainCorpus.class);
|
|
87 |
// } else {
|
|
88 |
// Log.info("No available selection to target the corpus annotations to save");
|
|
89 |
// return null;
|
|
90 |
// }
|
|
91 |
// }
|
|
92 |
//
|
65 |
93 |
|
66 |
|
|
67 |
|
LinkedHashMap<String, MainCorpus> corporaWithAnnotationsToSave = new LinkedHashMap<>();
|
68 |
|
for (MainCorpus corpus : Workspace.getInstance().getDeepChildren(MainCorpus.class)) {
|
69 |
|
if (!corpus.getProject().isOpen()) continue;
|
70 |
|
AnnotationManager am;
|
71 |
|
try {
|
72 |
|
am = KRAnnotationEngine.getAnnotationManager(corpus);
|
|
94 |
LinkedHashMap<String, MainCorpus> corporaWithAnnotationsToSave = null;
|
|
95 |
if (selectedCorporaToSave == null) {
|
|
96 |
|
|
97 |
corporaWithAnnotationsToSave = new LinkedHashMap<>();
|
|
98 |
for (MainCorpus corpus : Workspace.getInstance().getDeepChildren(MainCorpus.class)) {
|
|
99 |
if (!corpus.getProject().isOpen()) continue;
|
|
100 |
AnnotationManager am;
|
|
101 |
try {
|
|
102 |
am = KRAnnotationEngine.getAnnotationManager(corpus);
|
|
103 |
}
|
|
104 |
catch (Exception e) {
|
|
105 |
// TODO Auto-generated catch block
|
|
106 |
e.printStackTrace();
|
|
107 |
continue;
|
|
108 |
}
|
|
109 |
if (am == null) {
|
|
110 |
continue; // nothing to do
|
|
111 |
}
|
|
112 |
|
|
113 |
if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) {
|
|
114 |
continue;
|
|
115 |
}
|
|
116 |
|
|
117 |
corporaWithAnnotationsToSave.put(corpus.getName(), corpus);
|
73 |
118 |
}
|
74 |
|
catch (Exception e) {
|
75 |
|
// TODO Auto-generated catch block
|
76 |
|
e.printStackTrace();
|
77 |
|
continue;
|
78 |
|
}
|
79 |
|
if (am == null) {
|
80 |
|
continue; // nothing to do
|
81 |
|
}
|
82 |
119 |
|
83 |
|
if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) {
|
84 |
|
continue;
|
|
120 |
if (corporaWithAnnotationsToSave.size() == 0) {
|
|
121 |
Log.info("No CQP annotation found to save in the corpora.");
|
|
122 |
return null;
|
85 |
123 |
}
|
86 |
|
|
87 |
|
corporaWithAnnotationsToSave.put(corpus.getName(), corpus);
|
88 |
124 |
}
|
89 |
125 |
|
90 |
|
if (corporaWithAnnotationsToSave.size() == 0) {
|
91 |
|
Log.info("No CQP annotation found to save in the corpora.");
|
92 |
|
return null;
|
93 |
|
}
|
94 |
|
|
95 |
126 |
try {
|
96 |
|
// if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) {
|
97 |
|
// Log.info(NLS.bind("No CQP annotation found to save in the {0} corpus.", corpus));
|
98 |
|
// return null;
|
99 |
|
// }
|
|
127 |
// if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) {
|
|
128 |
// Log.info(NLS.bind("No CQP annotation found to save in the {0} corpus.", corpus));
|
|
129 |
// return null;
|
|
130 |
// }
|
100 |
131 |
|
101 |
132 |
// System.out.println("DISPLAY="+Display.getDefault());
|
102 |
133 |
final Boolean[] doit = new Boolean[1];
|
... | ... | |
116 |
147 |
@Override
|
117 |
148 |
public void run() {
|
118 |
149 |
|
119 |
|
|
120 |
150 |
doit[0] = dialog.open() == Window.OK;
|
121 |
151 |
doupdateedition[0] = dialog.getDoUpdateEdition();
|
|
152 |
if (dialog.getSelectedCorpus() != null) {
|
|
153 |
selectedCorporaToSave = dialog.getSelectedCorpus();
|
|
154 |
}
|
122 |
155 |
}
|
123 |
156 |
});
|
124 |
157 |
if (doit[0] == false) {
|
125 |
158 |
return null;
|
126 |
159 |
}
|
127 |
160 |
|
128 |
|
if (dialog.getSelectedCorpus().size() == 0) {
|
|
161 |
if (selectedCorporaToSave.size() == 0) {
|
129 |
162 |
Log.info("No corpus selected. Aborting.");
|
130 |
163 |
return null;
|
131 |
164 |
}
|
... | ... | |
133 |
166 |
|
134 |
167 |
JobHandler job = null;
|
135 |
168 |
|
136 |
|
Log.info(NLS.bind("Saving {0} annotations...", dialog.getSelectedCorpus().keySet()));
|
137 |
|
for (MainCorpus corpus : dialog.getSelectedCorpus().values()) {
|
|
169 |
Log.info(NLS.bind("Saving {0} annotations...", selectedCorporaToSave.keySet()));
|
|
170 |
for (MainCorpus corpus : selectedCorporaToSave.values()) {
|
138 |
171 |
try {
|
139 |
172 |
job = SaveAnnotations.save(corpus);
|
140 |
173 |
if (job == null) {
|
... | ... | |
149 |
182 |
return null;
|
150 |
183 |
}
|
151 |
184 |
}
|
152 |
|
|
|
185 |
|
153 |
186 |
if (job != null && job.getState() == Status.OK_STATUS.getCode()) {
|
154 |
187 |
if (KRAnnotationPreferences.getInstance().getBoolean(KRAnnotationPreferences.UPDATE)) {
|
155 |
188 |
|
... | ... | |
160 |
193 |
this.runInit(monitor);
|
161 |
194 |
|
162 |
195 |
try {
|
163 |
|
monitor.setTaskName("Updating corpora: "+dialog.getSelectedCorpus().values());
|
164 |
|
for (MainCorpus fcorpus : dialog.getSelectedCorpus().values()) {
|
|
196 |
monitor.setTaskName("Updating corpora: "+selectedCorporaToSave.values());
|
|
197 |
for (MainCorpus fcorpus : selectedCorporaToSave.values()) {
|
165 |
198 |
JobHandler job2 = UpdateCorpus.update(fcorpus, false, doupdateedition[0]);
|
166 |
199 |
if (fcorpus != null && job2 != null) {
|
167 |
200 |
try {
|