Révision 1889

tmp/org.txm.utils/src/org/txm/utils/Timer.java (revision 1889)
1
package org.txm.utils;
2

  
3
public class Timer {
4
	long start = System.currentTimeMillis();
5
	
6
	public long ellaspeTime() {
7
		return System.currentTimeMillis() - start;
8
	}
9
	
10
	public void reset() {
11
		start = System.currentTimeMillis();
12
	}
13
	
14
	public long getStart() {
15
		return start;
16
	}
17
}
0 18

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages/messages_fr.properties (revision 1889)
1001 1001
seeTheQuoteSectionIn=(voir la section 'Citer le logiciel TXM' de la page d'accueil du site 
1002 1002
selectWorkingDirectory=Répertoire de travail
1003 1003
options=Options...
1004
firstLaunchOfTXM=Premier lancement de TXM
1004
firstLaunchOfTXM=Premier lancement de TXM
1005
selectAnotherTXMCorporaToRestore=Selectionner un autre répertoire de corpus à récupérer...
tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages/TXMUIMessages.java (revision 1889)
538 538
	public static String selectWorkingDirectory;
539 539

  
540 540
	public static String firstLaunchOfTXM;
541

  
542
	public static String selectAnotherTXMCorporaToRestore;
541 543
	
542 544
	static {
543 545
		// initialize resource bundle
tmp/org.txm.rcp/src/main/java/org/txm/rcp/messages/messages.properties (revision 1889)
1005 1005
seeTheQuoteSectionIn=(see the "How to Cite the Textometry project" section in the textometrie.org web site: 
1006 1006
selectWorkingDirectory=Working directory
1007 1007
options=Options...
1008
firstLaunchOfTXM=First launch of TXM
1008
firstLaunchOfTXM=First launch of TXM
1009
selectAnotherTXMCorporaToRestore=Select another TXM corpora to restore...
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/ImportModuleCustomization.java (revision 1889)
294 294
		params.put(TEXTUALPLANS, true);
295 295
		params.put(OPTIONS, true);
296 296
		allParams.put("xtzLoader.groovy", params); //$NON-NLS-1$
297
		names.put("xtzLoader.groovy", "XML-XTZ + CSV"); //$NON-NLS-1$ //$NON-NLS-2$
297
		names.put("xtzLoader.groovy", "XML-TEI Zero + CSV"); //$NON-NLS-1$ //$NON-NLS-2$
298 298
	}
299 299
	
300 300
	/**
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/SelectDirectoryWidget.java (revision 1889)
10 10
import org.eclipse.swt.widgets.Label;
11 11
import org.eclipse.swt.widgets.Text;
12 12

  
13
/**
14
 * Composite to select a directory:
15
 * 
16
 * [optional title] + [text widget] + [button "..."]
17
 * 
18
 * @author mdecorde
19
 *
20
 */
13 21
public class SelectDirectoryWidget extends GLComposite {
14 22

  
15 23
	Text t;
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/parameters/ParametersDialog.java (revision 1889)
33 33
import org.txm.core.preferences.TBXPreferences;
34 34
import org.txm.rcp.messages.TXMUIMessages;
35 35
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
36
import org.txm.utils.Timer;
36 37
import org.txm.utils.logger.Log;
37 38

  
38 39
@SuppressWarnings("rawtypes")
......
412 413
				script.getBinding().setVariable("args", args);
413 414
			}
414 415
		}
415

  
416
		
416 417
		Display.getDefault().syncExec(new Runnable() {
417 418
			public void run() { 
418 419
				boolean okNames = true;
......
447 448
						retOpen = true;
448 449
						errorOpen = false;
449 450
					}
451
					
452
					if (bean instanceof groovy.lang.Script) { // reset the timer binding if already existing
453
						groovy.lang.Script script = (groovy.lang.Script) bean;
454
						if (script.getBinding().hasVariable("timer")) {
455
							Timer timer = (Timer)script.getBinding().getVariable("timer");
456
							timer.reset();
457
						}
458
					}
450 459
				}
451 460
			}
452 461
		});
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/ChangeTXMWorkspace.java (revision 1889)
115 115
		launchData.workspaceSelected(path);
116 116
		
117 117
		// Switch workspace :
118
		URL url = null;
119 118
		try {
120
			url = new URL("file", "", path);
119
			URL url = new URL("file", "", path);
121 120
			launchData.writePersistedData();
122 121
			ChooseWorkspaceData.setShowDialogValue(false);
123 122
			PlatformUI.getWorkbench().restart(); // need to restart TXM to apply changes
tmp/org.txm.rcp/src/main/java/org/txm/rcp/ApplicationWorkbenchAdvisor.java (revision 1889)
38 38
import java.util.ArrayList;
39 39
import java.util.Arrays;
40 40
import java.util.Date;
41
import java.util.HashMap;
41 42
import java.util.List;
42 43
import java.util.Locale;
43 44
import java.util.logging.Handler;
......
45 46
import java.util.logging.LogRecord;
46 47

  
47 48
import org.apache.commons.lang.StringUtils;
49
import org.eclipse.core.resources.ResourcesPlugin;
48 50
import org.eclipse.core.runtime.IAdaptable;
49 51
import org.eclipse.core.runtime.IProgressMonitor;
50 52
import org.eclipse.core.runtime.IStatus;
......
62 64
import org.eclipse.jface.viewers.LabelProvider;
63 65
import org.eclipse.osgi.util.NLS;
64 66
import org.eclipse.swt.graphics.Color;
67
import org.eclipse.swt.widgets.DirectoryDialog;
65 68
import org.eclipse.swt.widgets.Display;
66 69
import org.eclipse.swt.widgets.Event;
67 70
import org.eclipse.swt.widgets.Shell;
......
679 682
			try {
680 683
				Log.info(NLS.bind(TXMUIMessages.installPathColonP0, Toolbox.getInstallDirectory()));
681 684

  
682
				Log.info("Checking TXM user directory...");
683
				if (Toolbox.getTxmHomePath().trim().isEmpty()) {
684
					Version v = BundleUtils.getBundleVersion("org.txm.rcp");//$NON-NLS-1$
685
					if (v == null) {
686
						System.out.println("Error: no 'org.txm.rcp' version found.");
687
						return false;
688
					}
689
					String version = v.getMajor()+"."+v.getMinor()+"."+v.getMicro();
690
					if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) { //$NON-NLS-1$
691
						System.out.println("RUNNING TXM FROM ECLIPSE - DEV MODE ACTIVATED");
692
						version += "-dev";
693
					}
694
					txmhomedir = new File(System.getProperty("user.home"), "TXM-"+version); //$NON-NLS-1$ //$NON-NLS-2$
695
				} else {
696
					txmhomedir = new File(Toolbox.getTxmHomePath().trim());
697
				}
685
				txmhomedir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalFile();
686
				txmhomedir.mkdirs(); // creates the directory if needed
698 687

  
699 688
				txmhomedir.mkdirs(); // creates the directory if needed
700 689

  
......
732 721
	 * @param monitor
733 722
	 */
734 723
	private void installCorporaDirectory(IProgressMonitor monitor) {
735
		if (Toolbox.getTxmHomePath().endsWith("-dev")) {
736
			System.out.println("DEV MODE: no corpus restored!");
737
			return; // dev mode
738
		}
724
		//		if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) {
725
		//			System.out.println("DEV MODE: no corpus restored!");
726
		//			return; // dev mode
727
		//		}
739 728
		monitor.setTaskName("Restoring corpora...");
740 729
		String installdirpath = Toolbox.getInstallDirectory();
741 730
		File sampleCorporaDirectory = new File(installdirpath, "samples"); //$NON-NLS-1$
......
753 742
		String SAMPLES = "1. "+TXMUIMessages.bind(TXMUIMessages.sampleCorporaOfCurrentTXMP0, vv);
754 743
		String V080 = "2. "+TXMUIMessages.bind(TXMUIMessages.corporaOfPreviousTXMP0, vv);
755 744
		String V079 = "3. "+TXMUIMessages.bind(TXMUIMessages.corporaOfPreviousTXMP0, "0.7.9");
756
		
757
		
745
		String OTHER = "4. "+TXMUIMessages.selectAnotherTXMCorporaToRestore;
746

  
747

  
758 748
		final ArrayList<Object> corporaDirs = new ArrayList<Object>();
759 749
		corporaDirs.add(SAMPLES);
760 750
		corporaDirs.add(V080);
761 751
		corporaDirs.add(V079);
762
		
752
		corporaDirs.add(OTHER);
753

  
763 754
		Display.getDefault().syncExec(new Runnable() {
764 755
			@Override
765 756
			public void run() {
......
778 769
				}
779 770
			}
780 771
		});
781
		
772

  
782 773
		// move previous TXM 0.8.0 corpora
783 774
		File backupDir = new File(corporaDir.getAbsolutePath()+"-previous");
784 775
		if (corporaDir.exists()) {
......
789 780
				dir.renameTo(bdir);
790 781
			}
791 782
		}
792
		
783

  
793 784
		// load TXM-0.8.0 sample corpora (from the install directory)
794
				if (corporaDirs.contains(SAMPLES) && sampleCorporaDirectory.exists()) {
785
		if (corporaDirs.contains(SAMPLES) && sampleCorporaDirectory.exists()) {
795 786

  
796
					Log.info(TXMUIMessages.installingSampleCorpus);
787
			Log.info(TXMUIMessages.installingSampleCorpus);
797 788

  
798
					JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(sampleCorporaDirectory, false, true, false);
799
					try {
800
						job.join();
801
					} catch (InterruptedException e) {
802
						// TODO Auto-generated catch block
803
						e.printStackTrace();
804
					}
805
				}
806
		
789
			JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(sampleCorporaDirectory, false, true, false);
790
			try {
791
				job.join();
792
			} catch (InterruptedException e) {
793
				// TODO Auto-generated catch block
794
				e.printStackTrace();
795
			}
796
		}
797

  
807 798
		// TXM-0.8.0 previous installation corpora
808 799
		if (corporaDirs.contains(V080) && backupDir.listFiles(IOUtils.HIDDENFILE_FILTER).length > 0) { // not a new install, restore corpus from the corpora-previous directory
809 800
			Log.info(NLS.bind(TXMUIMessages.installingPreviousCorpusFromP0, "0.8.0", corporaDir));
......
814 805
				e.printStackTrace();
815 806
			}
816 807
		}
817
		
808

  
818 809
		// TXM previous installation corpora
819 810
		if (corporaDirs.contains(V079) && previousCorporaDirectory.exists()) { // new installation (empty corpora directory)
820 811
			Log.info(NLS.bind(TXMUIMessages.installingPreviousCorpusFromP0, "0.7.9", previousCorporaDirectory));
......
826 817
			}
827 818
		}
828 819

  
820
		// TXM previous installation corpora
821
		if (corporaDirs.contains(OTHER)) { // new installation (empty corpora directory)
822
			final HashMap<String, String> bindings = new HashMap<String, String>();
823
			Display.getDefault().syncExec(new Runnable() {
824
				@Override
825
				public void run() {
826
					Display display = Display.getDefault();
827
					Shell shell = display.getActiveShell();
828
					DirectoryDialog dialog = new DirectoryDialog(shell);
829
					String path = dialog.open();
830
					if (path == null) return;
831

  
832
					bindings.put("path", path);
833
				}
834
			});
835
			if (bindings.containsKey("path")) {
836
				File dir = new File(bindings.get("path"));
837
				Log.info(NLS.bind("Restoring corpora from the {0} directory...", dir));
838
				JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(dir, true, true, true);
839
				try {
840
					job.join();
841
				} catch (InterruptedException e) {
842
					e.printStackTrace();
843
				}
844
			}
845
		}
846

  
829 847
		Display.getDefault().syncExec(new Runnable() {
830 848
			@Override
831 849
			public void run() {
832 850
				RestartTXM.reloadViews();
833 851
			}
834 852
		});
835
		
853

  
836 854
		monitor.setTaskName("");
837 855
	}
838 856

  
......
915 933
									monitor.setTaskName("Calling Groovy prestart script...");
916 934
									callPreStartScript();
917 935
									monitor.worked(20);
918
									
936

  
919 937
									monitor.setTaskName("Initializing Toolbox (engines and corpora)...");
920 938
									if (Toolbox.initialize(TBXPreferences.class, monitor)) {
921 939
										StatusLine.setMessage(TXMUIMessages.ready);
......
928 946
										return;
929 947
									}
930 948
									monitor.worked(20);
931
									
949

  
932 950
									monitor.setTaskName("Calling Groovy start script...");
933 951
									callStartScript();
934 952
									monitor.worked(20);
935
									
953

  
936 954
									// restore corpora if TXMHOME has been created
937 955
									if (txmHomeRestored) {
938 956
										installCorporaDirectory(monitor);
......
947 965
							monitor.done(); 
948 966
						}
949 967
					});
950
					
968

  
951 969
					Log.fine(TXMUIMessages.loadingViews);
952 970
					RestartTXM.reloadViews(); // reload views
953
					
971

  
954 972
					setDefaultTheme();
955 973

  
956 974
					// CLOSE Empty&Error editors
......
966 984
				}
967 985
			}
968 986
		});
969
		
987

  
970 988
		jobHandler.setTaskName("");
971 989
		//TxmPreferences.dump();
972 990
		return true;
tmp/org.txm.rcp/src/main/java/org/txm/rcp/Application.java (revision 1889)
102 102
		//		} else {
103 103
		// in Release mode only : platform workspace selection on startup
104 104
		// then restart if needed (on workspace error...)
105
		Integer ret = openCGU();
106
		if (ret == IApplication.EXIT_RESTART) {
107
			System.out.println("** Working directory set by user.");
108
			return IApplication.EXIT_RESTART;
109
		} else if (ret == IApplication.EXIT_OK) {
110
			System.out.println("** Fail to open CGU or set working directory.");
111
			return IApplication.EXIT_OK; // an error occurred or user canceled
112
		} else {
113
			// OK
105

  
106
		System.out.println("instance location="+Platform.getInstanceLocation().getURL());
107
		if (Platform.getInstanceLocation().getURL() == null) {
108

  
109
			Integer ret = openCGU();
110
			if (ret == IApplication.EXIT_RESTART) {
111
				System.out.println("** Working directory set by user.");
112
				return IApplication.EXIT_RESTART;
113
			} else if (ret == IApplication.EXIT_OK) {
114
				System.out.println("** Fail to open CGU or set working directory.");
115
				return IApplication.EXIT_OK; // an error occurred or user canceled
116
			} else {
117
				// OK
118
			}
114 119
		}
115
		//		}
116 120

  
117 121
		// Die if platform WS not set (user cancel)
118 122
		// ---------------------------
......
250 254

  
251 255
	private Integer openCGU() {
252 256
		try {
253
			
257

  
254 258
			Version v = BundleUtils.getBundleVersion("org.txm.rcp");//$NON-NLS-1$
255 259
			if (v == null) {
256 260
				System.out.println("Error: no 'org.txm.rcp' version found.");
......
262 266
				version += "-dev";
263 267
			}
264 268
			System.out.println("Version="+version);
265
			
269

  
266 270
			File txmhomedir = new File(System.getProperty("user.home"), "TXM-"+version); //$NON-NLS-1$ //$NON-NLS-2$
267 271

  
268
			
269
			
272

  
273

  
270 274
			//System.out.println("CGU="+ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false));
271 275
			if (!ConfigurationScope.INSTANCE.getNode(IDEWorkbenchPlugin.IDE_WORKBENCH).getBoolean(RCPPreferences.CGU, false)) {
272 276
				ChooseWorkspaceData launchData = new ChooseWorkspaceData(txmhomedir.getAbsolutePath());
......
301 305
				ChooseWorkspaceData launchData = new ChooseWorkspaceData(txmhomedir.getAbsolutePath());
302 306
				String[] recent = launchData.getRecentWorkspaces();
303 307

  
304
		        // If the selection dialog was not used then the workspace to use is either the
305
		        // most recent selection or the initialDefault (if there is no history).
306
		        String workspace = null;
307
		        if (recent != null && recent.length > 0) {
308
				// If the selection dialog was not used then the workspace to use is either the
309
				// most recent selection or the initialDefault (if there is no history).
310
				String workspace = null;
311
				if (recent != null && recent.length > 0) {
308 312
					workspace = recent[0];
309 313
				}
310
		        if (workspace == null || workspace.length() == 0) {
314
				if (workspace == null || workspace.length() == 0) {
311 315
					workspace = launchData.getInitialDefault();
312 316
				}
313
		        launchData.workspaceSelected(TextProcessor.deprocess(workspace));
314
				
317
				launchData.workspaceSelected(TextProcessor.deprocess(workspace));
318

  
315 319
				return setInstanceLocation(launchData);
316 320
			}
317 321
		} catch(Exception e) {
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyScript.java (revision 1889)
56 56
import org.txm.rcp.swt.widget.parameters.UIParameterException;
57 57
import org.txm.rcp.utils.JobHandler;
58 58
import org.txm.rcp.views.corpora.CorporaView;
59
import org.txm.utils.Timer;
59 60
import org.txm.utils.logger.Log;
60 61

  
61 62
import groovy.lang.Binding;
......
250 251
					binding.setProperty("MONITOR", this); //$NON-NLS-1$
251 252
					binding.setProperty("stringArgs", stringArgs); //$NON-NLS-1$
252 253
					binding.setProperty("gse", gse);
254
					Timer timer = new Timer();
255
					binding.setProperty("timer", timer); //$NON-NLS-1$
253 256
					
254 257
					Log.info(NLS.bind(TXMUIMessages.executingGroovyScript, scriptfile.getName()));
255
					long time = System.currentTimeMillis();
258
					
256 259
					gse.run(relativepath, binding);
257
					
258
					Log.info(TXMUIMessages.bind(TXMUIMessages.doneP0Ms, System.currentTimeMillis()-time));
260
					Log.info(TXMUIMessages.bind(TXMUIMessages.doneP0Ms, timer.ellaspeTime()));
259 261
				} catch (ThreadDeath td) {
260 262
					return Status.CANCEL_STATUS;
261 263
				} catch (UIParameterException e) {
tmp/org.txm.rcp/build.properties (revision 1889)
16 16
               p2.inf,\
17 17
               TXM.sh,\
18 18
               icons/,\
19
               OSGI-INF/
19
               OSGI-INF/,\
20
               OSGI-INF/l10n/bundle.properties
20 21
source..=src/main/java/
21 22
bin.excludes = lib/batik/
22 23
qualifier=svn
tmp/org.txm.rcp/plugin.xml (revision 1889)
2448 2448
            categoryId="org.txm.rcp.category.txm"
2449 2449
            defaultHandler="org.txm.rcp.commands.ChangeTXMWorkspace"
2450 2450
            id="org.txm.rcp.commands.ChangeTXMWorkspace"
2451
            name="Change working directory...">
2451
            name="%command.name.64">
2452 2452
      </command>
2453 2453
   </extension>
2454 2454
   <extension
tmp/org.txm.rcp/OSGI-INF/l10n/bundle_fr.properties (revision 1889)
208 208
command.label.9         = XML-TEI Frantext
209 209
command.label.90        = Fermer
210 210
command.label.91        = Afficher les parents cach\u00E9s
211
command.label.92        = XML-TEI Z\u00E9ro + CSV
211
command.label.92        = XML-TEI Zero + CSV
212 212
command.label.93        = Fermer tout
213 213
command.label.94        = Table lexicale
214 214
command.label.95        = Cacher les parents interm\u00E9diaires
......
548 548
wizard.name          = Corpus
549 549
wizard.name.0        = Corpus
550 550
wizard.name.1        = Corpus
551

  
552
command.name.64 = Changer le r?pertoire de travail...
tmp/org.txm.rcp/OSGI-INF/l10n/bundle.properties (revision 1889)
515 515
wizard.name          = Corpus
516 516
wizard.name.0        = Corpus
517 517
wizard.name.1        = Corpus
518

  
519
command.name.64 = Change working directory...

Formats disponibles : Unified diff