Revision 2602

tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 2602)
20 20
import org.apache.commons.lang.StringUtils;
21 21
import org.eclipse.core.runtime.IProgressMonitor;
22 22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.SubMonitor;
23 24
import org.eclipse.core.runtime.preferences.DefaultScope;
24 25
import org.eclipse.osgi.util.NLS;
25 26
import org.osgi.framework.Bundle;
......
68 69
 * 
69 70
 * @author sjacquot
70 71
 */
71
public abstract class TXMResult implements Cloneable, IProgressMonitor, Comparable<TXMResult> {
72
public abstract class TXMResult implements Cloneable, Comparable<TXMResult> {
72 73
	
73
	public static final DateFormat ID_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmssSSS");
74
	public static final DateFormat ID_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmssSSS"); //$NON-NLS-1$
74 75
	
75
	public static final DateFormat PRETTY_TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
76
	public static final DateFormat PRETTY_TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //$NON-NLS-1$
76 77
	
77
	public static final DateFormat PRETTY_LOCALIZED_TIME_FORMAT = new SimpleDateFormat("dd MMMM yyyy, HH'h'mm", Locale.getDefault());
78
	public static final DateFormat PRETTY_LOCALIZED_TIME_FORMAT = new SimpleDateFormat("dd MMMM yyyy, HH'h'mm", Locale.getDefault()); //$NON-NLS-1$
78 79
	
79 80
	public static final String UUID_PREFIX = "txm_res_"; //$NON-NLS-1$
80 81
	
......
132 133
	/**
133 134
	 * If set, allows the command to notify its progress.
134 135
	 */
135
	protected IProgressMonitor monitor;
136
	private SubMonitor monitor;
136 137
	
137 138
	/**
138 139
	 * Thread used when calling compute().
......
172 173
	 * To store the simple name for unserialization and lazy loading.
173 174
	 * This string can be used, for example, to display some information in UI even if the result has not yet been recomputed.
174 175
	 */
175
	// TODO: we should do the same with getDetails() method
176
	// TODO: SJ: we should do the same with getDetails() method
176 177
	@Parameter(key = TXMPreferences.LAZY_NAME, type = Parameter.INTERNAL)
177 178
	private String lazyName;
178 179
	
......
221 222
	 * Creates a new TXMResult with no parent.
222 223
	 * If a local node exist with the parent_uuid, the parent will be retrieved and this result will be added to it.
223 224
	 * 
224
	 * @param uuid
225
	 * @param parametersNodePath
225 226
	 */
226 227
	public TXMResult(String parametersNodePath) {
227 228
		this(parametersNodePath, null);
......
231 232
	 * Creates a new TXMResult, child of the specified parent.
232 233
	 * If the parameters node path is null, a new path is generated from the project root path ending by a new generated UUID.
233 234
	 * 
234
	 * @param uuid
235
	 * @param parametersNodePath
235 236
	 * @param parent
236 237
	 */
237 238
	public TXMResult(String parametersNodePath, TXMResult parent) {
......
242 243
			parent.addChild(this);
243 244
		}
244 245
		
245
		// no parametersNodePath -> new result
246
		
247
		if (parametersNodePath == null) { // new object
246
		// new result
247
		if (parametersNodePath == null) {
248 248
			if (this.getProject() != null) {
249 249
				parametersNodePath = this.getProject().getParametersNodeRootPath();
250 250
			}
......
254 254
			
255 255
			this.parametersNodePath = parametersNodePath + createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$ ;
256 256
		}
257
		// lazy or linked result
257 258
		else {
258 259
			this.parametersNodePath = parametersNodePath;
259 260
		}
......
2330 2331
		// FIXME: SJ: we may not override the current thread member if it already exists?
2331 2332
		this.computingThread = Thread.currentThread();
2332 2333
		
2334
		// FIXME: SJ: Debug tests
2335
		boolean debugSlowingProcess = false;
2336
		int sleepDuration = 500;
2337
		
2333 2338
		// skip the process if the result is already in computing stage
2334 2339
		if (this.computing) {
2335 2340
			Log.finest(NLS.bind("--- TXMResult.compute(): {0}: The result is already computing, compute process aborted.", this.getClass().getSimpleName())); // $NON-NLS-1$
2336 2341
			return true;
2337 2342
		}
2338 2343
		
2344
		this.computing = true;
2345
		
2339 2346
		// no changes to do
2340 2347
		// FIXME: SJ: we need to do do some actions even if the object is locked, eg. updating parameters, saving parameters, etc.
2341 2348
		// FIXME: MD: nope the parameters must not move and will be saved in the current state
......
2344 2351
			return true;
2345 2352
		}
2346 2353
		
2347
		this.computing = true;
2348 2354
		
2349 2355
		Log.finest("*** TXMResult.compute(): " + this.getClass().getSimpleName() + ": starting computing process...");
2350 2356
		
2351 2357
		
2352
		// FIXME: SJ: see if this skipComputing tests is still useful? is it possible to directly return instead?
2358
		// convert the monitor into a sub-monitor that is dedicated only to the TXMResult.compute() method process
2359
		SubMonitor mainSubMonitor = SubMonitor.convert(monitor, this.getComputingStartMessage(), 3);
2360
		
2361
		// FIXME: SJ: see if this skipComputing tests is still useful? is it possible to directly returns instead?
2353 2362
		// en fait voir ChartResult.compute() if(super.compute(monitor, true, false)), je pense que le prob vient du fait que si on retourne false dans TXMResult.compute() alors renderChart() ne
2354 2363
		// sera pas appelé
2355 2364
		// il faudrait retourner un état: skipped, computed, error, etc.
......
2358 2367
		
2359 2368
		try {
2360 2369
			
2361
			this.monitor = monitor;
2362
			
2363 2370
			// compute the parent if needed
2364
			if (this.parent != null && !(this.parent instanceof Project) && !(this.parent instanceof Workspace)) {
2371
			if (this.parent != null && !(this.parent instanceof Project) && !(this.parent instanceof Workspace)
2372
					&& !this.parent.isComputing()) {
2365 2373
				
2374
				mainSubMonitor.setTaskName("Copmputing parents branch...");
2375
				
2366 2376
				Log.finest("TXMResult.compute(): " + this.getClass().getSimpleName() + ": starting parent (" + this.parent.getClass().getSimpleName() + ") computing process...");
2367 2377
				
2368
				if (!this.parent.compute(monitor, deepComputing)) {
2378
				if (!this.parent.compute(mainSubMonitor.split(1).setWorkRemaining(100), deepComputing)) {
2369 2379
					Log.finest("TXMResult.compute(): " + this.getClass().getSimpleName() + ": failed to compute parent result.");
2370 2380
					this.computing = false;
2371 2381
					return false;
......
2383 2393
			
2384 2394
			if (!skipComputing) {
2385 2395
				
2386
				
2387 2396
				// Debug
2388 2397
				Log.finest("+++ TXMResult.compute(): " + this.getClass().getSimpleName() + ": computing result of type " + this.getClass() + "...");
2389 2398
				
......
2394 2403
					return false;
2395 2404
				}
2396 2405
				
2397
				// log
2398
				if (!this.getComputingStartMessage().isEmpty()) {
2399
					
2400
					// console log, only for visible result or if the log level is superior to info level
2401
					if (this.isVisible() || Log.isLoggingFineLevel()) {
2402
						Log.info(this.getComputingStartMessage());
2403
					}
2404
					
2405
					// monitor
2406
					if (monitor != null) {
2407
						monitor.subTask(this.getComputingStartMessage());
2408
					}
2406
				// console log, only for visible result or if the log level is superior to info level
2407
				if (!this.getComputingStartMessage().isEmpty() && (this.isVisible() || Log.isLoggingFineLevel())) {
2408
					Log.info(this.getComputingStartMessage());
2409 2409
				}
2410 2410
				
2411
				// monitor log
2412
				// this.setTaskName(this.getComputingStartMessage());
2413
				mainSubMonitor.subTask(this.getComputingStartMessage());
2414
				// FIXME: SJ: debug tests
2415
				if (debugSlowingProcess) {
2416
					Thread.sleep(sleepDuration);
2417
				}
2411 2418
				
2412
				// FIXME: SJ: tests for long processing, eg. to see progress bar subtask or to test the user canceling
2413
				// monitor.beginTask("long process simulation test", 10);
2414
				// for (int i = 0; i < 1200; i++) {
2415
				// try {
2416
				// Thread.sleep(10);
2417
				// }
2418
				// catch (InterruptedException e) {
2419
				// // TODO Auto-generated catch block
2420
				// e.printStackTrace();
2421
				// }
2422
				// monitor.worked(1);
2423
				// }
2419
				// Computing
2420
				// SubMonitor m = subMonitor.split(1);
2421
				// m = SubMonitor.convert(m, this.getComputingStartMessage(), 100);
2424 2422
				
2423
				// store a new sub-monitor dedicated to subclasses computation method
2424
				this.monitor = mainSubMonitor.split(1).setWorkRemaining(100);
2425 2425
				
2426
				// Computing
2427 2426
				if (!this._compute()) {
2428 2427
					Log.finest("TXMResult.compute(): " + this.getClass().getSimpleName() + ": computing failed.");
2429 2428
					this.computing = false;
2430 2429
					return false;
2431 2430
				}
2432 2431
				
2432
				// subMonitor.worked(1);
2433
				
2433 2434
			}
2434 2435
			
2435 2436
			// clear the lazy name, no more needed since the object has been computed and getSimpleName() can now work
......
2475 2476
			
2476 2477
			
2477 2478
			// Children computing
2478
			if (!skipComputing
2479
					|| this.altered // FIXME: SJ: fix for computing LexicalTable children even if the LT is not dirty but only altered, need to define if it's a temporary fix or not
2480
			// e.g. can't we use the dirty state rather than a new member "altered"?
2481
			) {
2479
			if ((!skipComputing
2480
					|| this.altered) // FIXME: SJ: fix for computing LexicalTable children even if the LT is not dirty but only altered, need to define if it's a temporary fix or not
2481
					// e.g. can't we use the dirty state rather than a new member "altered"?
2482
					&& this.hasChildren()) {
2482 2483
				
2483
				if (monitor != null && children.size() > 1) {
2484
					monitor.beginTask(TXMCoreMessages.bind(TXMCoreMessages.info_computingChildrenOfP0, this), children.size());
2485
					// monitor.subTask(TXMCoreMessages.bind(TXMCoreMessages.info_computingChildrenOfP0, this));
2486
				}
2484
				// monitor log
2485
				mainSubMonitor.setTaskName(TXMCoreMessages.bind(TXMCoreMessages.info_computingChildrenOfP0P1, this, this.getClass().getSimpleName()));
2487 2486
				
2487
				// create a monitor for children computing loop
2488
				SubMonitor loopMonitor = mainSubMonitor.split(1).setWorkRemaining(this.children.size());
2489
				
2488 2490
				// set the children as dirty since the result has changed
2489 2491
				for (int i = 0; i < this.children.size(); i++) {
2490 2492
					this.children.get(i).setDirty();
......
2494 2496
				if (this.parent != null) {
2495 2497
					
2496 2498
					Log.finest("TXMResult.compute(): " + this.getClass().getSimpleName() + ": cascade computing of " + this.children.size() + " child(ren).");
2497
					// SubMonitor subMonitor = SubMonitor.convert(monitor, this.children.size());
2498 2499
					
2499 2500
					for (int i = 0; i < this.children.size(); i++) {
2500 2501
						
......
2502 2503
						// lazy loading test
2503 2504
						// only compute the child if it has already been computed one time ("loaded" one time)
2504 2505
						// or if this result always needs its children synchronized/computed to be consistent (e.g. Partition and children parts)
2505
						if ((deepComputing && child.hasBeenComputedOnce()) || child.mustBeSynchronizedWithParent()) {
2506
							child.compute(monitor, deepComputing);
2507
							// subMonitor.worked(1);
2506
						if (!child.isComputing() && ((deepComputing && child.hasBeenComputedOnce()) || child.mustBeSynchronizedWithParent())) {
2507
							child.compute(loopMonitor.split(1).setWorkRemaining(100), deepComputing);
2508 2508
						}
2509
						
2510
						if (monitor != null && this.children.size() > 1) {
2511
							monitor.worked(1);
2512
						}
2513 2509
					}
2514 2510
				}
2515 2511
			}
2516 2512
		}
2513
		// FIXME: SJ: in case of ThreadDeath we could for example call a method as Engine.interrupt(TXMResult)
2514
		// so the engine can do some clean up, e.g. R destroying some objects, etc.
2515
		// But we also have a TXMResult.clean() method that we could use
2517 2516
		catch (ThreadDeath e) {
2518
			// set parent and its children as canceled
2517
			// set result and its children as canceled
2519 2518
			this.resetComputingState();
2520
			throw new InterruptedException("TXMResult computing thread stopped.");
2519
			throw new InterruptedException("TXMResult computing thread stopped."); //$NON-NLS-1$
2521 2520
		}
2522 2521
		catch (InterruptedException e) {
2523
			// set parent and its children as canceled
2522
			// set result and its children as canceled
2524 2523
			this.resetComputingState();
2525 2524
			throw e;
2526 2525
		}
2527 2526
		catch (Exception e) {
2527
			// set result and its children as canceled
2528
			this.resetComputingState();
2528 2529
			e.printStackTrace();
2529 2530
			Log.severe(TXMCoreMessages.bind("TXMResult.compute(): Exception occurs during computing: {0}.", e));
2530 2531
			this.computing = false;
2531 2532
			return false;
2532 2533
		}
2533 2534
		
2534
		this.computing = false;
2535
		
2536
		
2537
		// log
2535
		// console log, only for visible result or if the log level is superior to info level
2538 2536
		if (!skipComputing && !this.getComputingDoneMessage().isEmpty() && (this.isVisible() || Log.isLoggingFineLevel())) {
2539
			// console log
2540 2537
			Log.info(this.getComputingDoneMessage());
2541
			
2542
			// monitor
2543
			if (monitor != null) {
2544
				monitor.subTask(this.getComputingDoneMessage());
2545
			}
2546 2538
		}
2547 2539
		
2548
		// FIXME: SJ: need to add this? problem is that it's already called in TXMEditor.compute()
2549
		// monitor.done();
2540
		// monitor log
2541
		mainSubMonitor.subTask(this.getComputingDoneMessage());
2542
		mainSubMonitor.done();
2550 2543
		
2544
		// delete the monitor used by subclasses computation method
2545
		if (this.monitor != null) {
2546
			this.monitor.done();
2547
		}
2548
		this.monitor = null;
2551 2549
		
2550
		this.computing = false;
2551
		
2552 2552
		return true;
2553 2553
	}
2554 2554
	
......
2580 2580
	
2581 2581
	
2582 2582
	/**
2583
	 * This method is dedicated to be implemented by the inherited result classes to define the computing steps.
2583
	 * This method is dedicated to be implemented by the inherited result classes to run the computing steps.
2584
	 * Subclasses can monitor progress using the dedicated methods.
2585
	 * At the start of this method call, the internal monitor have 100 ticks of remaining work to consume.
2584 2586
	 * 
2585 2587
	 * @return true if the result was computed
2586 2588
	 * 
......
2608 2610
		return new String[] { "*.csv" };
2609 2611
	}
2610 2612
	
2611
	/**
2612
	 * Checks if the monitor is canceled.
2613
	 * 
2614
	 * @return true if the monitor has been canceled by the user
2615
	 */
2616
	@Override
2617
	public boolean isCanceled() {
2618
		if (monitor != null) {
2619
			return monitor.isCanceled();
2620
		}
2621
		return false;
2622
	}
2623 2613
	
2614
	
2624 2615
	/**
2625 2616
	 * 
2626 2617
	 * @return
......
2636 2627
		this.progressSemaphore.release();
2637 2628
	}
2638 2629
	
2639
	/**
2640
	 * You must set the current monitor to be available to manage the process
2641
	 * progress
2642
	 * 
2643
	 * @param monitor
2644
	 *            can be null
2645
	 */
2646
	public boolean setCurrentMonitor(IProgressMonitor monitor) {
2647
		if (monitor == null) {
2648
			return false;
2649
		}
2650
		if (monitor.isCanceled()) {
2651
			return false;
2652
		}
2653
		this.monitor = monitor;
2654
		return true;
2655
	}
2656 2630
	
2631
	
2657 2632
	@Deprecated
2658 2633
	// FIXME: SJ: should be moved in an exporter extension
2659 2634
	public abstract boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception;
2660 2635
	
2661 2636
	
2637
	
2638
	// /**
2639
	// * Increments the progress of the specified amount of work and displays a message.
2640
	// *
2641
	// * @param amount
2642
	// * @param message
2643
	// */
2644
	// public void worked(int amount, String message) {
2645
	// if (monitor != null) {
2646
	// monitor.worked(amount);
2647
	// this.subTask(message);
2648
	// }
2649
	// Log.fine(message);
2650
	// }
2651
	
2652
	
2653
	// /**
2654
	// * Checks if the monitor is canceled.
2655
	// *
2656
	// * @return true if the monitor has been canceled by the user
2657
	// */
2658
	// @Override
2659
	// public boolean isCanceled() {
2660
	// if (monitor != null) {
2661
	// return monitor.isCanceled();
2662
	// }
2663
	// return false;
2664
	// }
2665
	//
2666
	//
2667
	// @Override
2668
	// public void beginTask(String name, int totalWork) {
2669
	// if (monitor != null) {
2670
	// monitor.beginTask(name, totalWork);
2671
	// }
2672
	// Log.fine(name);
2673
	// }
2674
	//
2675
	//
2676
	// @Override
2677
	// public void internalWorked(double work) {
2678
	// if (monitor != null) {
2679
	// monitor.internalWorked(work);
2680
	// }
2681
	// }
2682
	//
2683
	// @Override
2684
	// public void subTask(String name) {
2685
	// if (monitor != null) {
2686
	// monitor.subTask(name);
2687
	// }
2688
	// Log.fine(name);
2689
	// }
2690
	
2662 2691
	/**
2663
	 * Increments the progress of the specified amount of work.
2692
	 * Sets the monitor state as canceled.
2664 2693
	 * 
2665
	 * @param amount of work
2694
	 * @param value
2666 2695
	 */
2667
	@Override
2668
	public void worked(int amount) {
2669
		if (monitor != null) {
2670
			// System.out.println("worked "+amount);
2671
			monitor.worked(amount);
2696
	public void setCanceled(boolean value) {
2697
		if (this.monitor != null) {
2698
			Log.info(NLS.bind("Canceling computing of {0} ({1})...", this.getName(), this.getClass().getSimpleName()));
2699
			this.monitor.setCanceled(value);
2672 2700
		}
2673 2701
	}
2674 2702
	
2675 2703
	/**
2676
	 * Increments the progress of the specified amount of work and displays a message.
2704
	 * Sets the monitor current task name.
2677 2705
	 * 
2678
	 * @param amount
2679
	 * @param message
2706
	 * @param name
2680 2707
	 */
2681
	public void worked(int amount, String message) {
2682
		if (monitor != null) {
2683
			monitor.worked(amount);
2684
			this.subTask(message);
2708
	public void setTask(String name) {
2709
		if (this.monitor != null) {
2710
			this.monitor.subTask(name);
2685 2711
		}
2686
		Log.fine(message);
2712
		Log.fine(name);
2687 2713
	}
2688 2714
	
2689
	@Override
2690
	public void beginTask(String name, int totalWork) {
2691
		if (monitor != null) {
2692
			monitor.beginTask(name, totalWork);
2715
	/**
2716
	 * Increments the progress monitor of the specified amount of work.
2717
	 *
2718
	 * @param amount of work
2719
	 */
2720
	public void worked(int amount) {
2721
		if (this.monitor != null) {
2722
			this.monitor.worked(amount);
2693 2723
		}
2694
		Log.fine(name);
2695 2724
	}
2696 2725
	
2697
	@Override
2698
	public void done() {
2699
		if (monitor != null) {
2700
			monitor.done();
2726
	
2727
	/**
2728
	 * Checks if the monitor is canceled.
2729
	 *
2730
	 * @return true if the monitor has been canceled by the user
2731
	 */
2732
	public boolean isCanceled() {
2733
		if (this.monitor != null) {
2734
			return this.monitor.isCanceled();
2701 2735
		}
2736
		return false;
2702 2737
	}
2703 2738
	
2704
	@Override
2705
	public void internalWorked(double work) {
2706
		if (monitor != null) {
2707
			monitor.internalWorked(work);
2739
	/**
2740
	 * Sets the monitor state as done.
2741
	 */
2742
	public void done() {
2743
		if (this.monitor != null) {
2744
			this.monitor.done();
2708 2745
		}
2709 2746
	}
2710 2747
	
2711
	@Override
2712
	public void setCanceled(boolean value) {
2713
		if (monitor != null) {
2714
			Log.info(NLS.bind("Canceling computing of {0} ({1})...", this.getName(), this.getClass().getSimpleName()));
2715
			monitor.setCanceled(value);
2748
	/**
2749
	 * Sets the work remaining for the internal SubMonitor instance.
2750
	 * 
2751
	 * @param workRemaining number of ticks
2752
	 */
2753
	public void setWorkRemaining(int workRemaining) {
2754
		if (this.monitor != null) {
2755
			this.monitor.setWorkRemaining(workRemaining);
2716 2756
		}
2717 2757
	}
2718 2758
	
2719
	@Override
2720
	public void setTaskName(String name) {
2721
		if (monitor != null) {
2722
			monitor.setTaskName(name);
2723
		}
2724
		Log.fine(name);
2759
	/**
2760
	 * Splits the current monitor and returns a new SubMonitor with 100 ticks of remaining work.
2761
	 * 
2762
	 * @param totalWork
2763
	 * @return
2764
	 */
2765
	public SubMonitor splitMonitor(int totalWork) {
2766
		return this.monitor.split(totalWork).setWorkRemaining(100);
2725 2767
	}
2726 2768
	
2727
	@Override
2728
	public void subTask(String name) {
2729
		if (monitor != null) {
2730
			monitor.subTask(name);
2769
	
2770
	/**
2771
	 * You must set the current monitor to be available to manage the process
2772
	 * progress
2773
	 * 
2774
	 * @param monitor
2775
	 *            can be null
2776
	 */
2777
	public boolean setCurrentMonitor(SubMonitor monitor) {
2778
		if (monitor == null) {
2779
			return false;
2731 2780
		}
2732
		Log.fine(name);
2781
		if (monitor.isCanceled()) {
2782
			return false;
2783
		}
2784
		this.monitor = monitor;
2785
		return true;
2733 2786
	}
2734 2787
	
2788
	
2735 2789
	/**
2736 2790
	 * Gets the user defined name.
2737 2791
	 * 
......
2746 2800
	 * This method can be used for logging or UI.
2747 2801
	 * This method can also be used to sort the result by type (alphanumeric order) according to the current language.
2748 2802
	 * 
2749
	 * @return
2803
	 * @return an intended localized result type
2750 2804
	 */
2751 2805
	public abstract String getResultType();
2752 2806
	
tmp/org.txm.core/src/java/org/txm/core/messages/TXMCoreMessages.java (revision 2602)
81 81
	
82 82
	public static String info_p0P1Deleted;
83 83
	
84
	public static String info_computingChildrenOfP0;
84
	public static String info_computingChildrenOfP0P1;
85 85
	
86 86
	public static String error_error2;
87 87
	
tmp/org.txm.core/src/java/org/txm/core/messages/messages_fr.properties (revision 2602)
161 161

  
162 162
in = \ dans\	\	\	\	\	\	\	\	
163 163

  
164
info_computingChildrenOfP0 = Calcul des enfants de {0}
165
info_p0P1Deleted           = {0} "{1}" supprimé(e).
164
info_computingChildrenOfP0P1 = Calcul des enfants de {0} ({1})...
165
info_p0P1Deleted             = {0} "{1}" supprimé(e).
166 166

  
167 167
initializationOfGroovyImportScriptRunner = Initialisation de GroovyImportScriptRunner
168 168

  
tmp/org.txm.core/src/java/org/txm/core/messages/messages.properties (revision 2602)
165 165

  
166 166
in = \ in \	\	\	\	\	\	\	\	
167 167

  
168
info_computingChildrenOfP0 = Computing children of {0}
169
info_p0P1Deleted           = {0} "{1}" deleted.
168
info_computingChildrenOfP0P1 = Computing children of {0} ({1})...
169
info_p0P1Deleted             = {0} "{1}" deleted.
170 170

  
171 171
initializationOfGroovyImportScriptRunner = Initialization of GroovyImportScriptRunner
172 172

  
tmp/org.txm.core/src/java/org/txm/objects/Project.java (revision 2602)
51 51
import org.eclipse.core.runtime.IProgressMonitor;
52 52
import org.eclipse.core.runtime.Path;
53 53
import org.eclipse.core.runtime.Platform;
54
import org.eclipse.core.runtime.SubMonitor;
54 55
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
55 56
import org.eclipse.osgi.util.NLS;
56 57
import org.osgi.framework.Bundle;
57 58
import org.osgi.service.prefs.BackingStoreException;
58 59
import org.osgi.service.prefs.Preferences;
59 60
import org.txm.Toolbox;
60
import org.txm.core.engines.EngineType;
61 61
import org.txm.core.engines.ImportEngine;
62 62
import org.txm.core.engines.ImportEngines;
63 63
import org.txm.core.messages.TXMCoreMessages;
......
383 383
				return true;
384 384
			}
385 385
			
386
			if (monitor == null || monitor.isCanceled()) {
387
				monitor = new LogMonitor("computing " + this);
386
			SubMonitor monitor = null;
387
			if (this.isCanceled()) {
388
				monitor = SubMonitor.convert(new LogMonitor(), "computing " + this, 100);
388 389
			}
389 390
			
390 391
			Log.finest("RUNNING IMPORT MODULE WITH NAME = " + getImportModuleName());
......
453 454
		description.setLocation(folder.getLocation());
454 455
		description.setNatureIds(new String[] { TXMCORPUSNATURE });
455 456
		
457
		SubMonitor monitor = this.splitMonitor(100);
458
		
456 459
		rcpProject.create(description, monitor);
457 460
		rcpProject.open(monitor);
458 461
		// TODO might fail if corpus source directory changed
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditor.java (revision 2602)
311 311
		boolean needInit = (this.chartComposite.getChartComponent() == null) && (this.getResult().getChart() != null);
312 312
		
313 313
		// loading chart
314
		this.getResult().subTask(TXMCoreMessages.bind("Loading chart of type {0}...", this.getResult().getResultType())); //$NON-NLS-1$
314
		this.getResult().setTask(TXMCoreMessages.bind("Loading chart of type {0}...", this.getResult().getResultType())); //$NON-NLS-1$
315 315
		this.loadChart();
316 316
		
317 317
		
tmp/org.txm.edition.rcp/src/org/txm/edition/rcp/handlers/OpenEdition.java (revision 2602)
63 63
 * choose one of the text used in the partition @ author mdecorde.
64 64
 */
65 65
public class OpenEdition extends AbstractHandler {
66

  
66
	
67 67
	/** The Constant ID. */
68 68
	public final static String ID = "org.txm.synopticedition.rcp.handlers.OpenEdition"; //$NON-NLS-1$
69

  
69
	
70 70
	/** The lastopenedfile. */
71 71
	public static String lastopenedfile;
72

  
73
	/* (non-Javadoc)
72
	
73
	/*
74
	 * (non-Javadoc)
74 75
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
75 76
	 */
76 77
	@Override
77 78
	public Object execute(ExecutionEvent event) throws ExecutionException {
78

  
79
		
79 80
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
80 81
		if (selection.getFirstElement() instanceof CQPCorpus) {
81 82
			try {
82 83
				CQPCorpus c = (CQPCorpus) selection.getFirstElement();
83
				//				Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
84

  
85
				//EditionSelectorDialog d = new EditionSelectorDialog(shell, c, null);
84
				// Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
85
				
86
				// EditionSelectorDialog d = new EditionSelectorDialog(shell, c, null);
86 87
				SynopticEditionEditor editor = null;
87
				//				if (c.getEditionNames().size() > 1 && d.open() == Window.OK) {
88
				//					Object[] rez = d.getResult();
89
				//					String[] rezS = new String[rez.length];
90
				//					for (int i =0 ; i < rez.length ; i++) rezS[i] = rez[i].toString();
91
				//					editor = openEdition(c, rezS);
92
				//				} else 
88
				// if (c.getEditionNames().size() > 1 && d.open() == Window.OK) {
89
				// Object[] rez = d.getResult();
90
				// String[] rezS = new String[rez.length];
91
				// for (int i =0 ; i < rez.length ; i++) rezS[i] = rez[i].toString();
92
				// editor = openEdition(c, rezS);
93
				// } else
93 94
				String[] editionsToOpen = getDefaultEditions(c);
94

  
95
				
95 96
				if (editionsToOpen.length == 0) { // the defaultEdition parameter is not set
96 97
					List<String> editionNames = c.getProject().getEditionNames();
97 98
					if (editionNames.size() > 0) { // use the first edition declared
98 99
						editionsToOpen = new String[1];
99 100
						editionsToOpen[0] = editionNames.get(0);
100 101
						Log.info(NLS.bind(EditionUIMessages.openingWithFirstEditionNoDefaultEditionSetColonP0, editionNames.get(0)));
101
					} else { // no edition in the corpus
102
					}
103
					else { // no edition in the corpus
102 104
						Log.warning(EditionUIMessages.noEditionToOpen);
103 105
						editionsToOpen = new String[0];
104 106
						return false;
105 107
					}
106
				} else {
108
				}
109
				else {
107 110
					Log.info(NLS.bind(EditionUIMessages.openingDefaultEditionsColonP0, StringUtils.join(editionsToOpen, ", ")));
108 111
				}
109

  
112
				
110 113
				editor = openEdition(c, editionsToOpen);
111

  
112
				//				if (editor != null)
113
				//					editor.firstPage();
114
			} catch (Exception e) {
114
				
115
				// if (editor != null)
116
				// editor.firstPage();
117
			}
118
			catch (Exception e) {
115 119
				Log.severe(NLS.bind(EditionUIMessages.errorWhileOpeningEditionColonP0, e));
116 120
				org.txm.utils.logger.Log.printStackTrace(e);
117 121
			}
118
		} else {
122
		}
123
		else {
119 124
			Log.warning(EditionUIMessages.abortingColonSelectionIsNotACorpus);
120 125
		}
121 126
		return null;
122 127
	}
123

  
128
	
124 129
	public static String[] getDefaultEditions(Project p) {
125
		return p.getDefaultEdition().split(","); //$NON-NLS-1$ //$NON-NLS-2$
130
		return p.getDefaultEdition().split(","); //$NON-NLS-1$
126 131
	}
127

  
132
	
128 133
	public static String[] getDefaultEditions(CQPCorpus c) {
129 134
		return getDefaultEditions(c.getProject());
130 135
	}
131

  
136
	
132 137
	/**
133
	 * Open edition, but don't show a page 
138
	 * Open edition, but don't show a page
134 139
	 *
135 140
	 * @param corpus the corpus
136 141
	 * @return the object
......
140 145
	}
141 146
	
142 147
	/**
143
	 * Open edition, but don't show a page 
148
	 * Open edition, but don't show a page
144 149
	 *
145 150
	 * @param corpus the corpus
146 151
	 * @return the object
147 152
	 */
148 153
	public static SynopticEditionEditor openEdition(CQPCorpus corpus, List<String> editions) {
149 154
		String textid = null;
150

  
151
		Log.fine("Opening edition of "+corpus); //$NON-NLS-1$
155
		
156
		Log.fine("Opening edition of " + corpus); //$NON-NLS-1$
152 157
		try {
153 158
			Text text = null;
154 159
			if (corpus instanceof Subcorpus) {
155
				Subcorpus sub = (Subcorpus)corpus;
160
				Subcorpus sub = (Subcorpus) corpus;
156 161
				sub.compute(false);
157 162
				List<Match> matches = sub.getMatches();
158 163
				if (matches.size() > 0) {
159 164
					StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$
160 165
					Property text_id = text_su.getProperty("id"); //$NON-NLS-1$
161

  
166
					
162 167
					textid = matches.get(0).getValueForProperty(text_id);
163 168
					if (textid != null) text = corpus.getProject().getText(textid);
164 169
				}
165 170
			}
166
			//			QueryResult result = corpus.query(new Query("<text> []"), "get_edition", false); //$NON-NLS-1$ //$NON-NLS-2$ 
167
			//			StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$
168
			//			Property text_id = text_su.getProperty("id"); //$NON-NLS-1$
169

  
170
			// 			if (result.getNMatch() > 0) textid = result.getMatches(0, 1).get(0).getValueForProperty(text_id);
171
			// QueryResult result = corpus.query(new Query("<text> []"), "get_edition", false); //$NON-NLS-1$ //$NON-NLS-2$
172
			// StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$
173
			// Property text_id = text_su.getProperty("id"); //$NON-NLS-1$
174
			
175
			// if (result.getNMatch() > 0) textid = result.getMatches(0, 1).get(0).getValueForProperty(text_id);
171 176
			MainCorpus maincorpus = corpus.getMainCorpus();
172

  
173
			//			if (textid != null) text = maincorpus.getText(textid);
174

  
177
			
178
			// if (textid != null) text = maincorpus.getText(textid);
179
			
175 180
			if (text == null) {
176 181
				text = maincorpus.getProject().getFirstText();
177

  
182
				
178 183
				if (text == null) {
179 184
					System.out.println(NLS.bind(EditionUIMessages.couldNotFindFirstTextOfP0IDInTheCorpus, textid));
180 185
					return null;
181 186
				}
182

  
187
				
183 188
				textid = text.getName();
184 189
			}
185

  
186
			//String[] editions = {maincorpus.getDefaultEdition()};
190
			
191
			// String[] editions = {maincorpus.getDefaultEdition()};
187 192
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
188 193
			IWorkbenchPage page = window.getActivePage();
189

  
194
			
190 195
			SynopticEditorInput editorInput = new SynopticEditorInput(text, corpus, editions);
191 196
			SynopticEditionEditor editor = (SynopticEditionEditor) page.openEditor(editorInput, SynopticEditionEditor.ID, true);
192

  
197
			
193 198
			return editor;
194

  
195
		} catch (Exception e) {
199
			
200
		}
201
		catch (Exception e) {
196 202
			Log.printStackTrace(e);
197 203
			System.out.println(NLS.bind(EditionUIMessages.errorWhileOpeningEditorColonP0, e));
198 204
			return null;
199 205
		}
200 206
	}
201
}
207
}
tmp/org.txm.ahc.core/src/org/txm/ahc/core/functions/AHC.java (revision 2602)
336 336
	 * @param encoding
337 337
	 * @return
338 338
	 */
339
	// FIXME: extract to future exporter extension
339
	// FIXME: SJ: to extract to future exporter extension
340 340
	@Deprecated
341 341
	public boolean toTxt(File outfile, String encoding) {
342 342
		boolean ret = true;
......
359 359
		return true;
360 360
	}
361 361
	
362
	// FIXME: extract to future exporter extension
362
	// FIXME: SJ: to extract to future exporter extension
363 363
	@Override
364 364
	@Deprecated
365 365
	public boolean toTxt(File outfile, String encoding, String colsep, String txtsep) {
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/ComputePartition.java (revision 2602)
35 35
import org.eclipse.core.runtime.IProgressMonitor;
36 36
import org.eclipse.core.runtime.IStatus;
37 37
import org.eclipse.core.runtime.Status;
38
import org.eclipse.core.runtime.SubMonitor;
38 39
import org.eclipse.jface.viewers.IStructuredSelection;
39 40
import org.eclipse.jface.window.Window;
40 41
import org.eclipse.osgi.util.NLS;
......
156 157
					
157 158
					@Override
158 159
					protected IStatus run(IProgressMonitor monitor) {
159
						this.runInit(monitor);
160
						
161
						// convert the monitor into sub-monitor
162
						SubMonitor subMonitor = SubMonitor.convert(monitor, NLS.bind(TXMUIMessages.creatingANewPartitionWithP0, corpus.getName()), 100);
163
						
164
						this.runInit(subMonitor);
165
						
160 166
						try {
161 167
							JobsTimer.start();
162
							monitor.beginTask(NLS.bind(TXMUIMessages.creatingANewPartitionWithP0, corpus.getName()), 100);
163 168
							
164 169
							partition = d.getPartition();
165 170
							if (partition == null) {
166
								monitor.done();
171
								subMonitor.done();
167 172
								Log.warning(TXMUIMessages.errorColonThePartitionWasNotCreated);
168 173
								return Status.CANCEL_STATUS;
169 174
							}
170
							partition.compute(monitor);
171 175
							
176
							// compute the partition and children parts
177
							partition.compute(subMonitor.split(10));
178
							
172 179
							// ensure the partition viability
173 180
							if (partition.getPartsCount() == 0) {
174 181
								Log.warning(TXMUIMessages.errorColonThePartitionCreatedHasNoPart);
......
187 194
							else if (emptyParts.size() != 0) {
188 195
								Log.warning(NLS.bind("Warning: some parts are empty: {0}", emptyParts));
189 196
							}
190
							monitor.worked(95);
191 197
							
192
							monitor.subTask(TXMUIMessages.refreshingCorpora);
198
							subMonitor.subTask(TXMUIMessages.refreshingCorpora);
199
							
193 200
							syncExec(new Runnable() {
194 201
								
195 202
								@Override
......
198 205
									CorporaView.expand(partition.getParent());
199 206
								}
200 207
							});
201
							monitor.worked(100);
208
							
202 209
						}
203 210
						// for user direct canceling
204 211
						catch (ThreadDeath | InterruptedException e) {
......
211 218
							return Status.CANCEL_STATUS;
212 219
						}
213 220
						finally {
214
							monitor.done();
221
							subMonitor.done();
215 222
							JobsTimer.stopAndPrint();
216 223
						}
217 224
						return Status.OK_STATUS;
tmp/org.txm.cooccurrence.core/src/org/txm/cooccurrence/core/functions/Cooccurrence.java (revision 2602)
259 259
		// FIXME: debug
260 260
		// System.out.println("cooc: "+corpus+" "+query+" "+properties+" "+limit+" "+maxLeft+" "+minLeft+" "+minRight+" "+maxRight+" "+minFreq+" "+minCof+" "+minScore+" "+includeXpivot);
261 261
		
262
		this.subTask(CooccurrenceCoreMessages.info_buildingQueries);
262
		this.setTask(CooccurrenceCoreMessages.info_buildingQueries);
263 263
		
264 264
		// clear data
265 265
		try {
......
283 283
			return false;
284 284
		}
285 285
		
286
		this.subTask(CooccurrenceCoreMessages.info_retreivingMatches);
286
		this.setTask(CooccurrenceCoreMessages.info_retreivingMatches);
287 287
		if (!this.stepGetMatches()) {
288 288
			return false;
289 289
		}
290
		this.worked(10);
290
		this.worked(20);
291 291
		
292
		this.subTask(CooccurrenceCoreMessages.info_buildingLineSignatures);
292
		this.setTask(CooccurrenceCoreMessages.info_buildingLineSignatures);
293 293
		if (!this.stepBuildSignatures()) {
294 294
			return false;
295 295
		}
296
		this.worked(10);
296
		this.worked(20);
297 297
		
298
		this.subTask(CooccurrenceCoreMessages.info_counting);
298
		this.setTask(CooccurrenceCoreMessages.info_counting);
299 299
		if (!this.stepCount()) {
300 300
			return false;
301 301
		}
302
		this.worked(10);
302
		this.worked(20);
303 303
		
304
		this.subTask(CooccurrenceCoreMessages.info_buildingLexicalTable);
304
		this.setTask(CooccurrenceCoreMessages.info_buildingLexicalTable);
305 305
		if (!this.stepBuildLexicalTable()) {
306 306
			return false;
307 307
		}
308 308
		this.worked(10);
309 309
		
310
		this.subTask(CooccurrenceCoreMessages.info_computingSpecificitiesScores);
310
		this.setTask(CooccurrenceCoreMessages.info_computingSpecificitiesScores);
311 311
		if (!this.stepGetScores()) {
312 312
			return false;
313 313
		}
314 314
		
315 315
		this.clearMemory();
316
		this.worked(10);
316
		this.done();
317 317
		
318
		
319 318
		return true;
320 319
	}
321 320
	
......
960 959
				index = new Index(corpus);
961 960
				index.setVisible(false);
962 961
				index.setParameters(new CQLQuery(pCooccurentQueryFilter), pProperties, null, null, null, null);
963
				if (!index.compute(monitor)) {
962
				if (!index.compute(this.splitMonitor(10))) {
964 963
					Log.severe("Cooccurrence internal Index compute failed. Aborting.");
965 964
					return false;
966 965
				}
tmp/org.txm.properties.core/src/org/txm/properties/core/functions/Properties.java (revision 2602)
294 294
	
295 295
	@Override
296 296
	protected boolean _compute() throws Exception {
297
		if (computer._compute(monitor)) {
297
		if (computer._compute(this.splitMonitor(100))) {
298 298
			
299 299
			String txmhome = Toolbox.getTxmHomePath();
300 300
			String filename = computer.getName();
tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/IndexEditor.java (revision 2602)
164 164
	public void _createPartControl() {
165 165
		
166 166
		
167
		this.index = (Index) this.getResult();
167
		this.index = this.getResult();
168 168
		
169 169
		// Computing listeners
170 170
		ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this);
......
214 214
		queryWidget.getQueryWidget().addModifyListener(computeKeyListener);
215 215
		
216 216
		// Word properties selector
217
		propertiesSelector = new PropertiesSelector<WordProperty>(this.getMainParametersComposite(), SWT.NONE);
217
		propertiesSelector = new PropertiesSelector<>(this.getMainParametersComposite(), SWT.NONE);
218 218
		propertiesSelector.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false));
219 219
		propertiesSelector.setLayout(new GridLayout(3, false));
220 220
		try {
......
484 484
			lines = index.getLines(from, to);
485 485
		}
486 486
		else {
487
			lines = new ArrayList<Line>();
487
			lines = new ArrayList<>();
488 488
		}
489 489
		
490 490
		navigationArea.setInfoLineText("" + (from + 1), //$NON-NLS-1$
......
527 527
	 */
528 528
	@Override
529 529
	public void setFocus() {
530
		super.setFocus();
530 531
		if (this.queryWidget != null && !this.queryWidget.isDisposed()) {
531 532
			this.queryWidget.setFocus();
532 533
		}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Partition.java (revision 2602)
136 136
		Log.fine(NLS.bind(SearchEngineCoreMessages.info_creatingNewPartition, this.getParent(), this.userName));
137 137
		long start = System.currentTimeMillis();
138 138
		
139
		this.subTask("Building parts...");
139
		this.setTask("Building parts...");
140 140
		
141 141
		for (int i = 0; i < pQueries.size(); i++) {
142 142
			String queryS = pQueries.get(i);
......
150 150
			}
151 151
			new Part(this, partName, queryS);
152 152
			
153
			this.worked(1);
154 153
		}
155 154
		long end = System.currentTimeMillis();
156 155
		Log.fine(NLS.bind(SearchEngineCoreMessages.info_partitionCreatedInXMs, this.userName, (end - start)));
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 2602)
188 188
		// parts lexicons
189 189
		List<CQPLexicon> partsLexicons = new ArrayList<>();
190 190
		for (int i = 0; i < partition.getPartsCount(); i++) {
191
			partsLexicons.add(CQPLexicon.getLexicon(partition.getParts().get(i), this.property, this.monitor, false));
191
			partsLexicons.add(CQPLexicon.getLexicon(partition.getParts().get(i), this.property, this.splitMonitor(1), false));
192 192
		}
193 193
		
194 194
		// Corpus global lexicon
195
		CQPLexicon corpusLexicon = CQPLexicon.getLexicon(partition.getParent(), this.property, this.monitor, false);
195
		CQPLexicon corpusLexicon = CQPLexicon.getLexicon(partition.getParent(), this.property, this.splitMonitor(1), false);
196 196
		
197 197
		ArrayList<String> filteredForms = new ArrayList<>();
198 198
		// create a copy and filter line with Fmin;
......
351 351
			
352 352
			Subcorpus subcorpus = (Subcorpus) this.parent;
353 353
			CQPCorpus parentCorpus = subcorpus.getCorpusParent();
354
			CQPLexicon l1 = CQPLexicon.getLexicon(parentCorpus, this.property, this.monitor, false);
355
			CQPLexicon l2 = CQPLexicon.getLexicon(subcorpus, this.property, this.monitor, false);
354
			CQPLexicon l1 = CQPLexicon.getLexicon(parentCorpus, this.property, this.splitMonitor(20), false);
355
			CQPLexicon l2 = CQPLexicon.getLexicon(subcorpus, this.property, this.splitMonitor(20), false);
356 356
			
357 357
			this.statsData = new LexicalTableImpl(getNextName(), l1, l2);
358 358
		}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResult.java (revision 2602)
36 36
import org.eclipse.core.runtime.IProgressMonitor;
37 37
import org.eclipse.core.runtime.IStatus;
38 38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.core.runtime.SubMonitor;
39 40
import org.eclipse.jface.viewers.IStructuredSelection;
40 41
import org.eclipse.osgi.util.NLS;
41 42
import org.eclipse.swt.SWT;
......
51 52
import org.txm.rcp.messages.TXMUIMessages;
52 53
import org.txm.rcp.swt.dialog.LastOpened;
53 54
import org.txm.rcp.utils.JobHandler;
55

  
54 56
/**
55 57
 * Exports a result by calling the function toTxt(File f) then opens or not the result in the text editor according to the preferences.
58
 * 
56 59
 * @author mdecorde, sjacquot
57 60
 */
58 61
public class ExportResult extends AbstractHandler {
59

  
62
	
60 63
	private static final String ID = "org.txm.rcp.commands.function.ExportResult"; //$NON-NLS-1$
64
	
61 65
	/** The selection. */
62 66
	private IStructuredSelection selection;
63

  
67
	
64 68
	/** The lastopenedfile. */
65
	//private static String lastopenedfile;
66

  
69
	// private static String lastopenedfile;
70
	
67 71
	/**
68 72
	 * Export a TXM result in a CSV file.
69 73
	 *
......
76 80
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
77 81
		final Object s = selection.getFirstElement();
78 82
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
79

  
80
		//String txmhome = Toolbox.getTxmHomePath();
83
		
84
		// String txmhome = Toolbox.getTxmHomePath();
81 85
		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
82

  
83
		String extensions[] = {"*.csv"}; //$NON-NLS-1$
86
		
87
		String extensions[] = { "*.csv" }; //$NON-NLS-1$
84 88
		if (s instanceof TXMResult) {
85
			extensions = ((TXMResult)s).getExportTXTExtensions(); //$NON-NLS-1$
86
			dialog.setFileName(((TXMResult)s).getValidFileName());
89
			extensions = ((TXMResult) s).getExportTXTExtensions();
90
			dialog.setFileName(((TXMResult) s).getValidFileName());
87 91
		}
88 92
		dialog.setFilterExtensions(extensions);
89

  
93
		
90 94
		if (LastOpened.getFile(ID) != null) {
91 95
			dialog.setFilterPath(LastOpened.getFolder(ID));
92 96
		}
93

  
97
		
94 98
		if (dialog.open() != null) {
95 99
			StatusLine.setMessage(TXMUIMessages.exportingResults);
96 100
			String filepath = dialog.getFilterPath() + "/" + dialog.getFileName(); //$NON-NLS-1$
97 101
			if (!(filepath.endsWith(extensions[0].substring(1))))
98 102
				filepath += extensions[0].substring(1);
99

  
103
			
100 104
			final File outfile = new File(filepath);
101 105
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
102 106
			try {
103 107
				outfile.createNewFile();
104
			} catch (IOException e1) {
108
			}
109
			catch (IOException e1) {
105 110
				System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
106 111
			}
107 112
			if (!outfile.canWrite()) {
......
112 117
				System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
113 118
				return null;
114 119
			}
115

  
120
			
116 121
			final String encoding = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_ENCODING);
117 122
			String _colseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_COL_SEPARATOR);
118 123
			final String colseparator = _colseparator;
119 124
			String _txtseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_TXT_SEPARATOR);
120 125
			final String txtseparator = _txtseparator;
121

  
126
			
122 127
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
128
				
123 129
				@Override
124 130
				protected IStatus run(IProgressMonitor monitor) {
131
					
132
					// convert the monitor into sub-monitor
133
					SubMonitor subMonitor = SubMonitor.convert(monitor, TXMUIMessages.exporting, 100);
134
					
125 135
					try {
126
						this.runInit(monitor);
127
						monitor.beginTask(TXMUIMessages.exporting, 100);
128

  
136
						
137
						this.runInit(subMonitor);
138
						
129 139
						if (s instanceof TXMResult) {
130
							TXMResult r = (TXMResult)s;
140
							TXMResult r = (TXMResult) s;
131 141
							
132 142
							// compute the result if needed
133 143
							if (!r.isAltered()) {
134 144
								r.compute(this);
135 145
							}
136 146
							
137
							r.setCurrentMonitor(this); // Allows Functions to protect themselves from interruption
147
							r.setCurrentMonitor(subMonitor); // Allows Functions to protect themselves from interruption
138 148
							r.toTxt(outfile, encoding, colseparator, txtseparator);
139
						} else {
149
						}
150
						else {
140 151
							System.out.println("Exported object is not a TXMResult result");
141 152
							return Status.CANCEL_STATUS;
142 153
						}
143

  
154
						
144 155
						if (outfile.exists()) {
145 156
							// Open internal editor in the UI thread
146
							if(TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW))	{
157
							if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW)) {
147 158
								this.syncExec(new Runnable() {
159
									
148 160
									@Override
149 161
									public void run() {
150 162
										EditFile.openfile(outfile.getAbsolutePath());
151 163
									}
152 164
								});
153 165
							}
154

  
166
							
155 167
							System.out.println(NLS.bind("", outfile.getAbsolutePath())); //$NON-NLS-1$
156
						} else {
168
						}
169
						else {
157 170
							System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
158 171
						}
159
					} catch (ThreadDeath td) {
172
					}
173
					catch (ThreadDeath td) {
160 174
						return Status.CANCEL_STATUS;
161
					} catch (Exception e) {
175
					}
176
					catch (Exception e) {
162 177
						System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
163 178
						org.txm.utils.logger.Log.printStackTrace(e);
164 179
						return Status.CANCEL_STATUS;
165
					} finally {
166
						if (s instanceof TXMResult)
167
							((TXMResult)s).setCurrentMonitor(null);
168
						monitor.done();
180
					}
181
					finally {
182
						if (s instanceof TXMResult) {
183
							((TXMResult) s).setCurrentMonitor(null);
184
						}
185
						subMonitor.done();
169 186
						JobsTimer.stopAndPrint();
170 187
					}
171 188
					return Status.OK_STATUS;
172 189
				}
173 190
			};
174

  
191
			
175 192
			jobhandler.startJob();
176 193
		}
177 194
		return null;
178 195
	}
179
}
196
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultParameters.java (revision 2602)
36 36
import org.eclipse.core.runtime.IProgressMonitor;
37 37
import org.eclipse.core.runtime.IStatus;
38 38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.core.runtime.SubMonitor;
39 40
import org.eclipse.jface.viewers.IStructuredSelection;
40 41
import org.eclipse.osgi.util.NLS;
41 42
import org.eclipse.swt.SWT;
......
51 52
import org.txm.rcp.messages.TXMUIMessages;
52 53
import org.txm.rcp.swt.dialog.LastOpened;
53 54
import org.txm.rcp.utils.JobHandler;
55

  
54 56
// TODO: Auto-generated Javadoc
55 57
/**
56 58
 * export a result of a result by calling the function toTxt(File f) then show
57 59
 * the result in the text editor @ author mdecorde.
58 60
 */
59 61
public class ExportResultParameters extends AbstractHandler {
60

  
62
	
61 63
	private static final String ID = ExportResultParameters.class.getName();
62

  
64
	
63 65
	/**
64 66
	 * Export a TXM result parameters in the preferences format
65 67
	 *
......
75 77
			return null;
76 78
		}
77 79
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
78

  
79
		//String txmhome = Toolbox.getTxmHomePath();
80
		
81
		// String txmhome = Toolbox.getTxmHomePath();
80 82
		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
81

  
82
		String extensions[] = {"*.parameters"}; //$NON-NLS-1$
83
		
84
		String extensions[] = { "*.parameters" }; //$NON-NLS-1$
83 85
		dialog.setFilterExtensions(extensions);
84
		dialog.setFileName(((TXMResult)s).getValidFileName()+".parameters");
86
		dialog.setFileName(((TXMResult) s).getValidFileName() + ".parameters");
85 87
		if (LastOpened.getFile(ID) != null) {
86 88
			dialog.setFilterPath(LastOpened.getFolder(ID));
87 89
		}
88

  
90
		
89 91
		if (dialog.open() != null) {
90 92
			StatusLine.setMessage(TXMUIMessages.exportingResults);
91 93
			String filepath = dialog.getFilterPath()
92 94
					+ "/" + dialog.getFileName(); //$NON-NLS-1$
93 95
			if (!(filepath.endsWith(extensions[0].substring(1))))
94 96
				filepath += extensions[0].substring(1);
95

  
97
			
96 98
			final File outfile = new File(filepath);
97 99
			LastOpened.set(ID, outfile.getParent(), outfile.getName());
98 100
			try {
99 101
				outfile.createNewFile();
100
			} catch (IOException e1) {
102
			}
103
			catch (IOException e1) {
101 104
				System.err.println(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
102 105
			}
103 106
			if (!outfile.canWrite()) {
......
108 111
				System.out.println("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
109 112
				return null;
110 113
			}
111

  
114
			
112 115
			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
116
				
113 117
				@Override
114 118
				protected IStatus run(IProgressMonitor monitor) {
119
					
120
					// convert the monitor into sub-monitor
121
					SubMonitor subMonitor = SubMonitor.convert(monitor, TXMUIMessages.exporting, 100);
122
					
115 123
					try {
116
						this.runInit(monitor);
117
						monitor.beginTask(TXMUIMessages.exporting, 100);
118

  
119
							TXMResult r = (TXMResult)s;
120
							if (r.isAltered()) {
121
								System.out.println("Warning: only parameters are exported, manual changes are not transfered.");
122
							} else {
123
								r.compute(this); // refresh result
124
							}
125
							r.setCurrentMonitor(this); // Allows Functions to protect themselves from interruption
126
							if (r.toParametersFile(outfile)) {
127
								System.out.println(NLS.bind("Parameters exported to the {0} file.", outfile));
128
							}
129

  
124
						
125
						this.runInit(subMonitor);
126
						
127
						TXMResult r = (TXMResult) s;
128
						if (r.isAltered()) {
129
							System.out.println("Warning: only parameters are exported, manual changes are not transfered.");
130
						}
131
						else {
132
							r.compute(subMonitor); // refresh result
133
						}
134
						r.setCurrentMonitor(subMonitor); // Allows Functions to protect themselves from interruption
135
						if (r.toParametersFile(outfile)) {
136
							System.out.println(NLS.bind("Parameters exported to the {0} file.", outfile));
137
						}
138
						
130 139
						if (outfile.exists()) {
131 140
							// Open internal editor in the UI thread
132
							if(TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW))	{
141
							if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW)) {
133 142
								this.syncExec(new Runnable() {
143
									
134 144
									@Override
135 145
									public void run() {
136 146
										EditFile.openfile(outfile.getAbsolutePath());
137 147
									}
138 148
								});
139 149
							}
140

  
150
							
141 151
							System.out.println(NLS.bind("", outfile.getAbsolutePath())); //$NON-NLS-1$
142
						} else {
152
						}
153
						else {
143 154
							System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
144 155
						}
145
					} catch (ThreadDeath td) {
146
						if (s instanceof TXMResult)
147
							((TXMResult)s).clean();
156
					}
157
					catch (ThreadDeath td) {
158
						if (s instanceof TXMResult) {
159
							((TXMResult) s).clean();
160
						}
148 161
						return Status.CANCEL_STATUS;
149
					} catch (Exception e) {
162
					}
163
					catch (Exception e) {
150 164
						System.out.println(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
151 165
						org.txm.utils.logger.Log.printStackTrace(e);
152 166
						return Status.CANCEL_STATUS;
153
					} finally {
154
						if (s instanceof TXMResult)
155
							((TXMResult)s).setCurrentMonitor(null);
156
						monitor.done();
167
					}
168
					finally {
169
						if (s instanceof TXMResult) {
170
							((TXMResult) s).setCurrentMonitor(null);
171
						}
172
						subMonitor.done();
157 173
						JobsTimer.stopAndPrint();
158 174
					}
159 175
					return Status.OK_STATUS;
160 176
				}
161 177
			};
162

  
178
			
163 179
			jobhandler.startJob();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff