|
1 |
package org.txm.annotation.urs.commands;
|
|
2 |
|
|
3 |
import java.io.File;
|
|
4 |
|
|
5 |
import org.eclipse.core.commands.AbstractHandler;
|
|
6 |
import org.eclipse.core.commands.ExecutionEvent;
|
|
7 |
import org.eclipse.core.commands.ExecutionException;
|
|
8 |
import org.eclipse.osgi.util.NLS;
|
|
9 |
import org.eclipse.ui.IEditorPart;
|
|
10 |
import org.eclipse.ui.IEditorReference;
|
|
11 |
import org.eclipse.ui.IWorkbenchPage;
|
|
12 |
import org.eclipse.ui.handlers.HandlerUtil;
|
|
13 |
import org.txm.annotation.urs.URSCorpora;
|
|
14 |
import org.txm.annotation.urs.view.ElementPropertiesView;
|
|
15 |
import org.txm.annotation.urs.view.ElementSearchView;
|
|
16 |
import org.txm.annotation.rcp.editor.AnnotationExtension;
|
|
17 |
import org.txm.annotation.urs.Messages;
|
|
18 |
import org.txm.edition.rcp.editors.SynopticEditionEditor;
|
|
19 |
import org.txm.rcp.TXMWindows;
|
|
20 |
import org.txm.rcp.views.corpora.CorporaView;
|
|
21 |
import org.txm.searchengine.cqp.corpus.MainCorpus;
|
|
22 |
import org.txm.utils.logger.Log;
|
|
23 |
|
|
24 |
import visuAnalec.donnees.Corpus;
|
|
25 |
import visuAnalec.fichiers.FichiersJava;
|
|
26 |
|
|
27 |
public class RestoreAnnotations extends AbstractHandler {
|
|
28 |
|
|
29 |
/** The ID. */
|
|
30 |
public static String ID = RestoreAnnotations.class.getSimpleName(); //$NON-NLS-1$
|
|
31 |
Corpus corpus;
|
|
32 |
/** The selection. */
|
|
33 |
|
|
34 |
/* (non-Javadoc)
|
|
35 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
|
36 |
*/
|
|
37 |
@Override
|
|
38 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
39 |
|
|
40 |
Object first = CorporaView.getFirstSelectedObject();
|
|
41 |
if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
|
|
42 |
System.out.println(NLS.bind(Messages.SaveCorpus_0, first));
|
|
43 |
return null;
|
|
44 |
}
|
|
45 |
final MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
|
|
46 |
if (restore(mainCorpus, event)) {
|
|
47 |
Log.info("Annotations restored.");
|
|
48 |
} else {
|
|
49 |
Log.info("No annotations to restore.");
|
|
50 |
}
|
|
51 |
|
|
52 |
return null;
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
*
|
|
57 |
* @param mainCorpus
|
|
58 |
* @param event
|
|
59 |
* @return true is annotations have been modified
|
|
60 |
*/
|
|
61 |
public static boolean restore(final MainCorpus mainCorpus, ExecutionEvent event) {
|
|
62 |
|
|
63 |
|
|
64 |
Corpus acorpus = URSCorpora.getCorpus(mainCorpus);
|
|
65 |
if (!acorpus.isModifie()) return false; // nothing to do
|
|
66 |
|
|
67 |
acorpus.fermer();
|
|
68 |
URSCorpora.revert(mainCorpus);
|
|
69 |
|
|
70 |
mainCorpus.setIsModified(false);
|
|
71 |
|
|
72 |
if (event != null) {
|
|
73 |
|
|
74 |
HandlerUtil.getActiveShell(event).getDisplay().syncExec(new Runnable() {
|
|
75 |
@Override
|
|
76 |
public void run() {
|
|
77 |
|
|
78 |
CorporaView.refreshObject(mainCorpus);
|
|
79 |
|
|
80 |
ElementPropertiesView.closeView();
|
|
81 |
|
|
82 |
ElementSearchView.closeView();
|
|
83 |
|
|
84 |
// find out which editor is using the MainCorpus
|
|
85 |
for (IWorkbenchPage page : TXMWindows.getActiveWindow().getPages()) {
|
|
86 |
for (IEditorReference editor_ref : page.getEditorReferences()) {
|
|
87 |
IEditorPart editor = editor_ref.getEditor(false);
|
|
88 |
if (editor != null && editor instanceof SynopticEditionEditor) {
|
|
89 |
SynopticEditionEditor seditor = ((SynopticEditionEditor)editor);
|
|
90 |
if (seditor.getTXMEditorExtensions(AnnotationExtension.class).size() > 0) {
|
|
91 |
if (mainCorpus.equals(seditor.getCorpus())) {
|
|
92 |
seditor.setDirty(false);
|
|
93 |
seditor.close();
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
});
|
|
101 |
}
|
|
102 |
return true;
|
|
103 |
}
|
|
104 |
}
|
0 |
105 |
|