Index: tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/URSAnnotationReIndexer.java
===================================================================
--- tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/URSAnnotationReIndexer.java	(revision 2904)
+++ tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/URSAnnotationReIndexer.java	(revision 2905)
@@ -26,40 +26,45 @@
  *
  */
 public class URSAnnotationReIndexer {
+	
 	MainCorpus corpus;
+	
 	Corpus analecCorpus;
+	
 	File aafile;
+	
 	public boolean debug = false;
-
+	
 	public URSAnnotationReIndexer(MainCorpus corpus, Corpus analecCorpus) {
 		this.corpus = corpus;
 		this.analecCorpus = analecCorpus;
 	}
-
+	
 	public boolean process() throws CqiClientException, IOException, CqiServerError {
-
+		
 		int corpusSize = corpus.getSize();
-
+		
 		String text = analecCorpus.getTexte();
 		int isearch = 0; // the current search start position
-
+		
 		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
 		Property word = corpus.getProperty("word");
-
+		
 		int positions[] = new int[corpusSize];
-		for (int i = 0 ; i < corpusSize ; i++) positions[i] = i;
+		for (int i = 0; i < corpusSize; i++)
+			positions[i] = i;
 		
 		int positionsCorrespondances[] = new int[corpusSize];
 		String strs[] = CQI.cpos2Str(word.getQualifiedName(), positions);
-
-		for (int i = 0 ; i < corpusSize ; i++) {
+		
+		for (int i = 0; i < corpusSize; i++) {
 			int idx = text.indexOf(strs[i], isearch);
 			if (idx < 0) {
-				System.out.println("Error: cannot find word='"+strs[i]+"' (word with position in CQP corpus="+positions[i]+") in text with current carret="+isearch+". Aborting.");
+				System.out.println("Error: cannot find word='" + strs[i] + "' (word with position in CQP corpus=" + positions[i] + ") in text with current carret=" + isearch + ". Aborting.");
 				
 				System.out.println("Current text slice is (-20, +20 characters): ");
-				System.out.println("* before: "+text.substring(Math.max(0, isearch-20), Math.min(isearch+20, isearch)));
-				System.out.println("* after: "+text.substring(isearch, Math.min(isearch+20, text.length()-1)));
+				System.out.println("* before: " + text.substring(Math.max(0, isearch - 20), Math.min(isearch + 20, isearch)));
+				System.out.println("* after: " + text.substring(isearch, Math.min(isearch + 20, text.length() - 1)));
 				
 				return false;
 			}
@@ -69,15 +74,18 @@
 		
 		if (debug) System.out.println(Arrays.toString(positions));
 		if (debug) System.out.println(Arrays.toString(positionsCorrespondances));
-
+		
 		isearch = 0;
 		ArrayList<Unite> unites = analecCorpus.getToutesUnites();
 		if (debug) System.out.println("units not-sorted: ");
 		if (debug) printUnits(unites);
 		Collections.sort(unites, new Comparator<Unite>() {
+			
 			@Override
 			public int compare(Unite o1, Unite o2) {
-				return o1.getDeb() - o2.getDeb();
+				int d = o1.getDeb() - o2.getDeb();
+				if (d == 0) return o1.getFin() - o2.getFin();
+				else return d;
 			}
 		});
 		if (debug) System.out.println("units sorted: ");
@@ -93,41 +101,41 @@
 			boolean startFound = false;
 			boolean endFound = false;
 			int i = 0; // or not : unites are sorted by start position, we don't need to browse all words \o/
-			for (; i < positionsCorrespondances.length ; i++) {
+			for (; i < positionsCorrespondances.length; i++) {
 				if (startFound && endFound) break; // no need to go further
-				if (debug) System.out.println("i="+i+" positionsCorrespondances[i]="+positionsCorrespondances[i]);
+				if (debug) System.out.println("i=" + i + " positionsCorrespondances[i]=" + positionsCorrespondances[i]);
 				if (!startFound && start < positionsCorrespondances[i]) {
-					unite.setDeb(i-1);
+					unite.setDeb(i - 1);
 					startFound = true;
 				}
 				if (!endFound && end <= positionsCorrespondances[i]) {
-					unite.setFin(i-1);
+					unite.setFin(i - 1);
 					endFound = true;
 				}
 			}
 			
 			if (!endFound && i == positionsCorrespondances.length) {
-				unite.setFin(i-1);
+				unite.setFin(i - 1);
 				endFound = true;
 			}
 			if (!startFound && i == positionsCorrespondances.length) {
-				unite.setDeb(i-1);
+				unite.setDeb(i - 1);
 				startFound = true;
 			}
 			
 			if (!(startFound && endFound)) {
-				String s = "Error: cannot find words positions for unite of type="+unite.getType()+" and unit carret positions=["+start+", "+end+"]. Aborting";
+				String s = "Error: cannot find words positions for unite of type=" + unite.getType() + " and unit carret positions=[" + start + ", " + end + "]. Aborting";
 				System.out.println(s);
 				
 				System.out.println("5 last found units are: ");
-				for (int j = 4 ; j >= 0 ; j--) {
-					if (iunite-j >= 0) {
-						printUnite(unites.get(iunite-j));
+				for (int j = 4; j >= 0; j--) {
+					if (iunite - j >= 0) {
+						printUnite(unites.get(iunite - j));
 					}
 				}
 				return false;
 			}
-			//if (i > 0) i--; // restart at previous word
+			// if (i > 0) i--; // restart at previous word
 			iunite++;
 		}
 		if (debug) System.out.println("units updated: ");
@@ -136,7 +144,7 @@
 	}
 	
 	public static void printUnite(Unite unite) {
-		System.out.print(unite.getType()+ "["+unite.getDeb()+", "+unite.getFin()+"]");
+		System.out.print(unite.getType() + "[" + unite.getDeb() + ", " + unite.getFin() + "]");
 	}
 	
 	public static void printUnits(List<Unite> units) {
Index: tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ImportGlozzCorpus.java
===================================================================
--- tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ImportGlozzCorpus.java	(revision 2904)
+++ tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ImportGlozzCorpus.java	(revision 2905)
@@ -11,7 +11,10 @@
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
 import org.kohsuke.args4j.Option;
 import org.txm.Toolbox;
 import org.txm.annotation.urs.URSAnnotationReIndexer;
@@ -19,6 +22,7 @@
 import org.txm.annotation.urs.Messages;
 import org.txm.objects.Project;
 import org.txm.rcp.handlers.scripts.ExecuteImportScript;
+import org.txm.rcp.messages.TXMUIMessages;
 import org.txm.rcp.swt.widget.parameters.ParametersDialog;
 import org.txm.rcp.utils.JobHandler;
 import org.txm.searchengine.cqp.CQPSearchEngine;
@@ -33,24 +37,26 @@
 import visuAnalec.fichiers.FichiersGlozz;
 import visuAnalec.fichiers.FichiersJava;
 
-public class ImportGlozzCorpus  extends AbstractHandler {
-
-
-
-	//	@Option(name="aafile",usage="an example file", widget="File", required=true, def="text.aa")
-	//	File aafile;
-
-	//	@Option(name="acfile",usage="an example file", widget="File", required=true, def="annotations.ac")
-	//	File acfile
-
-	@Option(name="glozzDirectory",usage="A folder containing the Glozz files: aa ac and aam", widget="Folder", required=true, def="glozz")
+public class ImportGlozzCorpus extends AbstractHandler {
+	
+	
+	
+	// @Option(name="aafile",usage="an example file", widget="File", required=true, def="text.aa")
+	// File aafile;
+	
+	// @Option(name="acfile",usage="an example file", widget="File", required=true, def="annotations.ac")
+	// File acfile
+	
+	@Option(name = "glozzDirectory", usage = "A folder containing the Glozz files: aa ac and aam", widget = "Folder", required = true, def = "glozz")
 	File glozzDirectory;
-
-	@Option(name="aamfile",usage="The aam file to use", widget="File", required=true, def="model.aam")
+	
+	@Option(name = "aamfile", usage = "The aam file to use", widget = "File", required = true, def = "model.aam")
 	File aamfile;
+	
 	private String name;
-
-	/* (non-Javadoc)
+	
+	/*
+	 * (non-Javadoc)
 	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 	 */
 	@Override
@@ -58,51 +64,62 @@
 		try {
 			// Open the parameters input dialog box
 			if (!ParametersDialog.open(this)) return null;
-
+			
 			// END OF PARAMETERS
 			if (!glozzDirectory.exists()) {
 				System.out.println(Messages.ImportGlozzCorpus_0);
 				return null;
 			}
-
+			
 			name = glozzDirectory.getName();
 			name = AsciiUtils.buildId(name);
-
+			String newCorpusName = name.toUpperCase();
+			if (Toolbox.workspace.getProject(newCorpusName) != null) {
+				boolean b = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), TXMUIMessages.warning, NLS.bind(TXMUIMessages.theP0CorpusDirectoryAlreadyExistsDoYouWantToReplaceIt,
+						newCorpusName));
+				if (!b) {
+					Log.info("Import aborted.");
+					return null;
+				}
+			}
+			
 			final File srcDir = new File(glozzDirectory, name);
 			System.out.println(NLS.bind(Messages.ImportGlozzCorpus_1, srcDir));
 			DeleteDir.deleteDirectory(srcDir);
 			srcDir.mkdir();
-
+			
 			final File ecDir = new File(glozzDirectory, "ec"); //$NON-NLS-1$
 			System.out.println(NLS.bind(Messages.ImportGlozzCorpus_3, ecDir));
 			DeleteDir.deleteDirectory(ecDir);
 			ecDir.mkdir();
-
-
+			
+			
 			if (!srcDir.exists()) {
 				System.out.println(Messages.ImportGlozzCorpus_4);
 				return null;
 			}
-
+			
 			if (!ecDir.exists()) {
 				System.out.println(Messages.ImportGlozzCorpus_5);
 				return null;
 			}
-
+			
 			// write the TXT file WITH paragraphs
 			File[] aaFiles = glozzDirectory.listFiles(new FilenameFilter() {
+				
 				@Override
 				public boolean accept(File dir, String name) {
 					return name.endsWith(".aa"); //$NON-NLS-1$
 				}
 			});
 			File[] acFiles = glozzDirectory.listFiles(new FilenameFilter() {
+				
 				@Override
 				public boolean accept(File dir, String name) {
 					return name.endsWith(".ac"); //$NON-NLS-1$
 				}
 			});
-
+			
 			if (aaFiles == null || aaFiles.length == 0) {
 				System.out.println(NLS.bind(Messages.ImportGlozzCorpus_8, glozzDirectory));
 				return false;
@@ -115,51 +132,51 @@
 				System.out.println(NLS.bind(Messages.ImportGlozzCorpus_10, glozzDirectory));
 				return false;
 			}
-
+			
 			System.out.println(NLS.bind(Messages.ImportGlozzCorpus_11, glozzDirectory));
 			Arrays.sort(acFiles);
 			Arrays.sort(aaFiles);
-			for (int i = 0 ; i < aaFiles.length ; i++) {
+			for (int i = 0; i < aaFiles.length; i++) {
 				File acFile = acFiles[i];
 				File aaFile = aaFiles[i];
 				String name = acFile.getName();
 				int idx = name.indexOf("."); //$NON-NLS-1$
 				if (idx > 0) name = name.substring(0, idx);
-
-				File txtFile = new File(srcDir, name+".txt"); //$NON-NLS-1$
-				File ecFile = new File(ecDir, name+".ec"); //$NON-NLS-1$
+				
+				File txtFile = new File(srcDir, name + ".txt"); //$NON-NLS-1$
+				File ecFile = new File(ecDir, name + ".ec"); //$NON-NLS-1$
 				Corpus tmpAnalecCorpus = new Corpus(); // need a temporary corpus
-
+				
 				if (!FichiersGlozz.importerGlozz(tmpAnalecCorpus, acFile, aaFile)) {
 					System.out.println(Messages.ImportGlozzCorpus_15);
 					return null;
 				}
-
+				
 				final String texte = tmpAnalecCorpus.getTexte();
 				int debParag = 0;
 				Integer[] finPars = tmpAnalecCorpus.getFinParagraphes();
 				StringBuffer newTexte = new StringBuffer(texte.length() + finPars.length);
-				for (int iParagraph = 0 ; iParagraph < finPars.length ; iParagraph++) {
+				for (int iParagraph = 0; iParagraph < finPars.length; iParagraph++) {
 					newTexte.append(texte.substring(debParag, finPars[iParagraph])).append("\n"); //$NON-NLS-1$
 					debParag = finPars[iParagraph];
 				}
-
+				
 				IOUtils.write(txtFile, newTexte.toString()); // write the TXT file for TXM TXT import module
 				FichiersJava.enregistrerCorpus(tmpAnalecCorpus, ecFile); // write for later
-
+				
 				if (!txtFile.exists()) {
 					System.out.println(Messages.ImportGlozzCorpus_17);
 					return null;
 				}
 			}
-
-			Project project = Toolbox.workspace.getProject(name.toUpperCase());
+			
+			Project project = Toolbox.workspace.getProject(newCorpusName);
 			if (project != null) {
-//				CQPSearchEngine.getEngine().stop();
+				// CQPSearchEngine.getEngine().stop();
 				project.delete();
 			}
-			project = new Project(Toolbox.workspace, name.toUpperCase());
-			project.setName(name.toUpperCase());
+			project = new Project(Toolbox.workspace, newCorpusName);
+			project.setName(newCorpusName);
 			project.setSourceDirectory(srcDir.getAbsolutePath());
 			project.setImportModuleName("txt");
 			project.getEditionDefinition("default").setBuildEdition(true);
@@ -169,9 +186,9 @@
 				System.out.println(Messages.ImportGlozzCorpus_23);
 				return null;
 			}
-
+			
 			JobHandler job2 = new JobHandler(Messages.ImportGlozzCorpus_24) {
-
+				
 				@Override
 				protected IStatus run(IProgressMonitor monitor) {
 					try {
@@ -180,6 +197,7 @@
 							System.out.println("The CQP corpus was not created. Aborting.");
 							return Status.CANCEL_STATUS;
 						}
+						corpus.compute(false);
 						Corpus analecCorpus = URSCorpora.getCorpus(corpus);
 						analecCorpus.clearAll(); // remove all : annotations, structure
 						File[] ecFiles = ecDir.listFiles(IOUtils.HIDDENFILE_FILTER);
@@ -187,28 +205,28 @@
 						for (File ecFile : ecFiles) {
 							FichiersJava.concatener(ecFile, analecCorpus);
 						}
-
+						
 						System.out.println(NLS.bind(Messages.ImportGlozzCorpus_25, aamfile));
 						if (!FichiersGlozz.importerModeleGlozz(analecCorpus, aamfile)) {
 							System.out.println(Messages.ImportGlozzCorpus_26);
 							return Status.CANCEL_STATUS;
 						}
-						//					
-						//					System.out.println("Importing Glozz corpus from: "+acfile+" and "+aafile);
-						//					if (!FichiersGlozz.importerGlozz(analecCorpus, acfile, aafile)) {
-						//						System.out.println("Error while importing Glozz corpus.");
-						//						return null;
-						//					}
-
+						//
+						// System.out.println("Importing Glozz corpus from: "+acfile+" and "+aafile);
+						// if (!FichiersGlozz.importerGlozz(analecCorpus, acfile, aafile)) {
+						// System.out.println("Error while importing Glozz corpus.");
+						// return null;
+						// }
+						
 						System.out.println(Messages.ImportGlozzCorpus_27);
 						URSCorpora.removeCorpus(corpus); // remove old corpus if any
-
+						
 						URSAnnotationReIndexer aari = new URSAnnotationReIndexer(corpus, analecCorpus);
 						if (!aari.process()) {
 							System.out.println(Messages.ImportGlozzCorpus_28);
 							return Status.CANCEL_STATUS;
 						}
-
+						
 						System.out.println(Messages.ImportGlozzCorpus_29);
 						URSCorpora.saveCorpus(analecCorpus);
 						URSCorpora.getVue(analecCorpus).retablirVueParDefaut();
@@ -216,18 +234,26 @@
 						analecCorpus.setTexte(""); // free memory //$NON-NLS-1$
 						DeleteDir.deleteDirectory(ecDir); // cleaning
 						DeleteDir.deleteDirectory(srcDir); // cleaning
-
+						
 						return Status.OK_STATUS;
-					} catch (Exception e) {
+					}
+					catch (Exception e) {
 						System.out.println(NLS.bind(Messages.ImportGlozzCorpus_32, e.getLocalizedMessage()));
 						Log.printStackTrace(e);
 						return Status.CANCEL_STATUS;
 					}
 				}
 			};
-			job2.startJob(true); // wait for the TXT import job to finish
+			job.join(0, null);
+			if (job.getResult() == Status.OK_STATUS) {
+				job2.startJob(true); // wait for the TXT import job to finish
+			}
+			else {
+				Log.warning("Export could not be finished since the corpus import failed.");
+			}
 			return null;
-		} catch (Exception e) {
+		}
+		catch (Exception e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
Index: tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ExportGlozzCorpus.java
===================================================================
--- tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ExportGlozzCorpus.java	(revision 2904)
+++ tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ExportGlozzCorpus.java	(revision 2905)
@@ -21,14 +21,16 @@
 import org.txm.searchengine.cqp.serverException.CqiServerError;
 import org.txm.utils.logger.Log;
 
-public class ExportGlozzCorpus  extends AbstractHandler {
-
-	@Option(name="exportDirectory",usage="the result directory ", widget="Folder", required=true, def="result directory")
+public class ExportGlozzCorpus extends AbstractHandler {
+	
+	@Option(name = "exportDirectory", usage = "the result directory ", widget = "Folder", required = true, def = "result directory")
 	File exportDirectory;
-	@Option(name="unit_type",usage="A unit type to export", widget="String", required=true, def="MENTION")
+	
+	@Option(name = "unit_type", usage = "A unit type to export", widget = "String", required = true, def = "MENTION")
 	String unit_type;
-
-	/* (non-Javadoc)
+	
+	/*
+	 * (non-Javadoc)
 	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 	 */
 	@Override
@@ -36,25 +38,33 @@
 		try {
 			// Open the parameters input dialog box
 			if (!ParametersDialog.open(this)) return null;
-
+			
 			Object first = CorporaView.getFirstSelectedObject();
 			if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
 				System.out.println(NLS.bind(Messages.ExportGlozzCorpus_0, first));
 				return null;
 			}
-
-			final MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
-
+			
+			final MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus) first).getMainCorpus();
+			
 			JobHandler job = new JobHandler(NLS.bind(Messages.ExportGlozzCorpus_1, mainCorpus.getName())) {
-
+				
 				@Override
 				protected IStatus run(IProgressMonitor monitor) {
 					this.runInit(monitor);
 					try {
+						if (exportDirectory == null) {
+							Log.warning("No export directory set. aBorting");
+							return Status.CANCEL_STATUS;
+						}
+						exportDirectory.mkdirs();
+						
 						export(exportDirectory, mainCorpus, unit_type);
-					} catch (ThreadDeath e) {
+					}
+					catch (ThreadDeath e) {
 						System.out.println(Messages.ExportGlozzCorpus_2);
-					} catch (Throwable e) {
+					}
+					catch (Throwable e) {
 						System.out.println(NLS.bind(Messages.ExportGlozzCorpus_3, e.getLocalizedMessage()));
 						Log.printStackTrace(e);
 						return Status.CANCEL_STATUS;
@@ -63,9 +73,10 @@
 				}
 			};
 			job.schedule();
-
+			
 			return null;
-		} catch (Throwable e) {
+		}
+		catch (Throwable e) {
 			System.out.println(NLS.bind(Messages.ExportGlozzCorpus_3, e.getLocalizedMessage()));
 			Log.printStackTrace(e);
 		}
