Révision 3354

TXM/trunk/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/RestoreAnnotations.java (revision 3354)
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

  
TXM/trunk/org.txm.analec.rcp/src/org/txm/annotation/urs/URSCorpora.java (revision 3354)
156 156
	}
157 157
	
158 158
	public static void removeCorpus(CorpusBuild mcorpus) {
159
		
159 160
		mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild
160 161
		
161 162
		if (!vues.containsKey(mcorpus)) {
......
167 168
	}
168 169
	
169 170
	public static void revert(CorpusBuild mcorpus) {
171
		
170 172
		mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild
173
		Corpus acorpus = corpora.get(mcorpus);
174
		if (acorpus == null) return;
171 175
		corpora.remove(mcorpus);
172 176
		vues.remove(mcorpus);
173 177
		mcorpus.setIsModified(false);
TXM/trunk/org.txm.analec.rcp/plugin.xml (revision 3354)
19 19
                  </reference>
20 20
               </visibleWhen>
21 21
            </command>
22
            <command
23
                  commandId="org.txm.annotation.urs.commands.RestoreAnnotations"
24
                  style="push">
25
               <visibleWhen
26
                     checkEnabled="false">
27
                  <reference
28
                        definitionId="OneCorpusSelected">
29
                  </reference>
30
               </visibleWhen>
31
            </command>
22 32
            <menu
23 33
                  id="menu.urs.tools"
24 34
                  label="%menu.label.1">
......
302 312
      </command>
303 313
      <command
304 314
            categoryId="org.txm.rcp.category.txm"
315
            defaultHandler="org.txm.annotation.urs.commands.RestoreAnnotations"
316
            id="org.txm.annotation.urs.commands.RestoreAnnotations"
317
            name="Restore annotations">
318
      </command>
319
      <command
320
            categoryId="org.txm.rcp.category.txm"
305 321
            defaultHandler="org.txm.annotation.urs.commands.LoadVue"
306 322
            id="org.txm.annotation.urs.commands.LoadVue"
307 323
            name="%command.name.5">

Formats disponibles : Unified diff