Révision 3285

TXM/main/org.txm.rcp/plugin.xml (revision 3285)
577 577
                     </and>
578 578
                  </visibleWhen>
579 579
               </command>
580
               <command
581
                     commandId="org.txm.rcp.commands.ExportXMLTXMFiles"
582
                     icon="icons/functions/export.png"
583
                     style="push">
584
                  <visibleWhen
585
                        checkEnabled="false">
586
                     <and>
587
                        <reference
588
                              definitionId="OneMainCorpusSelected">
589
                        </reference>
590
                     </and>
591
                  </visibleWhen>
592
               </command>
580 593
            </menu>
581 594
            <separator
582 595
                  name="menu.file.separator.file"
......
2603 2616
            id="org.txm.rcp.handlers.export.ImportResultParameters"
2604 2617
            name="%command.name.40">
2605 2618
      </command>
2619
      <command
2620
            defaultHandler="org.txm.rcp.commands.ExportXMLTXMFiles"
2621
            id="org.txm.rcp.commands.ExportXMLTXMFiles"
2622
            name="XML-TXM files...">
2623
      </command>
2606 2624
   </extension>
2607 2625
   <extension
2608 2626
         id="links"
TXM/main/org.txm.rcp/src/main/java/org/txm/rcp/commands/ExportXMLTXMFiles.java (revision 3285)
1
package org.txm.rcp.commands;
2

  
3
import java.io.File;
4
import java.io.IOException;
5

  
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.swt.SWT;
9
import org.eclipse.swt.widgets.FileDialog;
10
import org.eclipse.swt.widgets.Shell;
11
import org.eclipse.ui.handlers.HandlerUtil;
12
import org.txm.core.results.TXMResult;
13
import org.txm.objects.Project;
14
import org.txm.rcp.handlers.BaseAbstractHandler;
15
import org.txm.utils.ConsoleProgressBar;
16
import org.txm.utils.logger.Log;
17
import org.txm.utils.zip.Zip;
18

  
19
public class ExportXMLTXMFiles extends BaseAbstractHandler {
20

  
21
	@Override
22
	public Object execute(ExecutionEvent event) throws ExecutionException {
23
		
24
		Object o = getCorporaViewSelectedObject(event);
25
		if (o instanceof TXMResult) {
26
			Project p = ((TXMResult)o).getProject();
27
			
28
			Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
29
			
30
			FileDialog d = new FileDialog(shell, SWT.SAVE);
31
			d.setFilterExtensions(new String[] {"*.zip"});
32
			
33
			String path = d.open();
34
			if (path != null) {
35
				File targetZipFile = new File(path);
36
				File txmDir = new File(p.getProjectDirectory(), "txm/"+p.getName());
37
				try {
38
					File[] files = txmDir.listFiles();
39
					if (files == null) {
40
						Log.warning("Warning: no 'txm' directory: "+txmDir);
41
						return false;
42
					}
43
					int s = files.length;
44
					if (s == 0) {
45
						Log.warning("Warning: no XML-TXM files in directory: "+txmDir);
46
						return false;
47
					}
48
					Zip.compress(txmDir, targetZipFile, new ConsoleProgressBar(s));
49
					Log.info("XML-TXM files exported in: "+targetZipFile);
50
				}
51
				catch (IOException e) {
52
					Log.printStackTrace(e);
53
				}
54
			}
55
		}
56
		return null;
57
	}
58
	
59
}
0 60

  

Formats disponibles : Unified diff