Révision 1181

tmp/org.txm.links.rcp/src/org/txm/links/rcp/handlers/SendSelectionToMatchable.java (revision 1181)
72 72
			
73 73
			// create a local result node in the project node, store in some parameters and call the linked command
74 74
			String resultParametersNodePath = this.getResultParent(event).getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_link"; // FIXME: we can't put the class name here since we does not know the target class
75
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_UUID, this.getResultParent(event).getUUID());
75
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_UUID, this.getResultParent(event).getParametersNodePath());
76 76
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.MATCHES, matches.toString());
77 77
			
78 78
			BaseAbstractHandler.executeSendToCommand(event.getCommand().getId(), resultParametersNodePath);
tmp/org.txm.links.rcp/src/org/txm/links/rcp/handlers/SendSelectionToQueryable.java (revision 1181)
80 80
			
81 81
			// create a local result node in the project node, store in some parameters and call the linked command
82 82
			String resultParametersNodePath = this.getResultParent(event).getProject().getParametersNodeRootPath() + TXMResult.createUUID() + "_link"; // FIXME: we can't put the class name here since we does not know the target class
83
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_UUID, this.getResultParent(event).getUUID());
83
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.PARENT_UUID, this.getResultParent(event).getParametersNodePath());
84 84
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.QUERY, query);
85 85
			TXMPreferences.put(resultParametersNodePath, TXMPreferences.QUERIES, queries);
86 86
			
tmp/org.txm.ahc.core/src/org/txm/ahc/core/functions/AHC.java (revision 1181)
185 185
	@Override
186 186
	protected boolean _compute()	{
187 187

  
188
		Log.info("Computing CAH...");
188
		Log.info("Computing AHC...");
189 189
		try {
190 190
			CA ca = getParent();
191 191
			LexicalTable table = ca.getLexicalTable();
......
685 685

  
686 686
	@Override
687 687
	public String getName() {
688
		// FIXME: to define
689
		// TMP solution below
690
		try {
691
			return getParent().getName();
692
		}
693
		catch (Exception e) {
694
			return this.getEmptyName();
695
		}
688
		return ""+this.getNumberOfClusters()+" "+(this.columnsComputing?"columns":"rows");
696 689
	}
697 690

  
698 691

  
tmp/org.txm.ca.core/src/org/txm/ca/core/functions/CA.java (revision 1181)
717 717
	@Override
718 718
	public String getSimpleName() {
719 719
		try {
720
			return this.getParent().getSimpleName() + " (" + this.firstDimension + "," + this.secondDimension + ")";
720
			if (this.hasBeenComputedOnce) {
721
				return this.getParent().getSimpleName() + " (" + this.firstDimension + "," + this.secondDimension + ")";
722
			} else {
723
				return "";
724
			}
725
			
721 726
		}
722 727
		catch (Exception e) {
723 728
			return this.getEmptyName();
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/debug/TXMResultDebugView.java (revision 1181)
103 103
		
104 104
		StringBuffer buffer = new StringBuffer();
105 105
		buffer.append("Class: " + this.currentResult.getClass() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
106
		buffer.append("UUID: " + this.currentResult.getUUID() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
106
		//buffer.append("UUID: " + this.currentResult.getUUID() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
107 107
		buffer.append("Node path: " + this.currentResult.getParametersNodePath() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
108 108
		buffer.append("Simple name: " + this.currentResult.getSimpleName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
109 109
		buffer.append("User name: " + this.currentResult.getUserName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
tmp/org.txm.core/src/java/org/txm/core/preferences/TXMPreferences.java (revision 1181)
88 88

  
89 89
	// essentially for Links and Persistence
90 90
	public final static String RESULT_PARAMETERS_NODE_PATH = "result_parameters_node_path"; //$NON-NLS-1$
91
	public final static String RESULT_UUID = "result_uuid"; //$NON-NLS-1$
92
	public final static String PARENT_UUID = "parent_uuid"; //$NON-NLS-1$
91
	//public final static String RESULT_UUID = "result_uuid"; //$NON-NLS-1$
92
	public final static String PARENT_UUID = "parent_parameters_node_path"; //$NON-NLS-1$
93 93
	public final static String BUNDLE_ID = "bundle_id"; //$NON-NLS-1$
94 94
	public final static String USER_NAME = "user_name"; //$NON-NLS-1$
95 95
	public final static String LAZY_NAME = "lazy_name"; //$NON-NLS-1$
......
1225 1225
	 * @param result
1226 1226
	 */
1227 1227
	public static void flush(TXMResult result)	{
1228
		Log.finest("TXMPreferences.flush(): Local preferences for object " + result.getUUID() + " saved to file.");
1228
		Log.finest("TXMPreferences.flush(): Local preferences for object " + result.getParametersNodePath() + " saved to file.");
1229 1229
		flush(result.getParametersNodePath());
1230 1230
	}
1231 1231
	
......
1254 1254
	 */
1255 1255
	public static void delete(TXMResult result)	{
1256 1256
		delete(preferencesRootNode.node(result.getParametersNodePath()));
1257
		Log.finest("TXMPreferences.delete(): Local preferences node for object " + result.getUUID() + " deleted.");
1257
		Log.finest("TXMPreferences.delete(): Local preferences node for object " + result.getParametersNodePath() + " deleted.");
1258 1258
	}
1259 1259

  
1260 1260

  
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 1181)
1 1
package org.txm.core.results;
2 2

  
3 3
import java.io.File;
4
import java.io.FileNotFoundException;
4 5
import java.io.IOException;
6
import java.io.PrintWriter;
7
import java.io.UnsupportedEncodingException;
5 8
import java.lang.reflect.Field;
6 9
import java.text.DateFormat;
7 10
import java.text.SimpleDateFormat;
......
25 28
import org.txm.objects.Project;
26 29
import org.txm.objects.Workspace;
27 30
import org.txm.stat.utils.LogMonitor;
31
import org.txm.utils.io.IOUtils;
28 32
import org.txm.utils.logger.Log;
29 33

  
30 34
// FIXME: At this moment, an empty list is created for children, to not return
......
67 71
	public static final Pattern FILE_NAME_PATTERN = Pattern.compile("[^a-zA-Z0-9\\.-]+"); //$NON-NLS-1$
68 72
	public static final String UNDERSCORE = "_";
69 73

  
70
	/**
71
	 * Unique ID of the result.
72
	 */
73
	protected String uniqueID;
74
//	/**
75
//	 * Unique ID of the result.
76
//	 */
77
//	protected String uniqueID;
74 78

  
75 79
	/**
76 80
	 * Editor can use this to test if the result has been computed once.
......
196 200
		}
197 201

  
198 202
		if (parametersNodePath == null)	{
199
			this.uniqueID = createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$
200 203
			if (this.getProject() != null)	{
201 204
				parametersNodePath = this.getProject().getParametersNodeRootPath();
205
			} else {
206
				parametersNodePath = "";
202 207
			}
203
			this.parametersNodePath = parametersNodePath + this.uniqueID;
208
			this.parametersNodePath = parametersNodePath + createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$;
204 209
		}
205 210
		else	{
206
			try {
207
				this.uniqueID = parametersNodePath.substring(parametersNodePath.lastIndexOf("/") + 1); //$NON-NLS-1$
208
			}
209
			// FIXME: essentially for the UUID "ROOT" defined in the Workspace class, see if we can do it in another way
210
			catch (Exception e) {
211
				this.uniqueID = parametersNodePath;
212
			}
213 211
			this.parametersNodePath = parametersNodePath;
214 212
		}
215 213

  
216 214
		Log.finest("TXMResult.TXMResult(): parameters node path: " + this.parametersNodePath);
217 215

  
218

  
219 216
		this.weight = 0;
220 217

  
221 218
		this.children = new ArrayList<TXMResult>(1);
......
232 229

  
233 230

  
234 231
		// retrieving parent from UUID
235
		String parentUUID = this.getStringParameterValue(TXMPreferences.PARENT_UUID);
232
		String parentNodePath = this.getStringParameterValue(TXMPreferences.PARENT_UUID);
236 233

  
237 234
		//System.out.println("TXMResult.TXMResult(): parent UUID = " + parentUUID);
238 235

  
239
		if (!("ROOT".equals(this.uniqueID)) && // search for parent only if UUID != "ROOT"
236
		if (!("ROOT".equals(this.parametersNodePath)) && // search for parent only if UUID != "ROOT"
240 237
				parent == null && 
241
				this.uniqueID != null && 
242
				!parentUUID.isEmpty()) {
243
			Log.warning("Searching parent with UUID: " + parentUUID + "...");
244
			TXMResult retrievedParent = TXMResult.getResult(parentUUID);
238
				this.parametersNodePath != null && 
239
				!parentNodePath.isEmpty()) {
240
			Log.warning("Searching parent with UUID: " + parentNodePath + "...");
241
			TXMResult retrievedParent = TXMResult.getResult(parentNodePath);
245 242
			if (retrievedParent != null) {
246 243
				Log.warning("Parent retrieved from UUID: " + retrievedParent + ".");
247 244
				retrievedParent.addChild(this);
248 245
			}
249 246
			else {
250
				Log.severe("Warning: no parent was found in project for path=" + parametersNodePath + " and puuid=" + parentUUID + " preferences=" + this.dumpParameters());
247
				Log.severe("Warning: no parent was found in project for path=" + parametersNodePath + " and puuid=" + parentNodePath + " preferences=" + this.dumpParameters());
251 248
				// FIXME: commented for now
252 249
				//TBXPreferences.delete(this);
253 250
				return;
......
259 256
			this.autoLoadParametersFromAnnotations(); // auto fill from Parameter annotations
260 257
			this.loadParameters();  // subclasses manual settings
261 258
		} catch (Exception e) {
262
			Log.severe("Fail to load " + uniqueID + "result: " + e);
259
			Log.severe("Fail to load " + parametersNodePath + "result: " + e);
263 260
			Log.printStackTrace(e);
264 261
		}
265 262

  
266 263
		// Log
267 264
		if (this.parent == null)	{
268
			Log.warning("Warning: the TXMResult of " + this.getClass() + " is attached to no parent. (uuid = " + this.getUUID() + ")");
265
			Log.warning("Warning: the TXMResult of " + this.getClass() + " is attached to no parent. (uuid = " + this.parametersNodePath + ")");
269 266
		}
270 267

  
271 268
		try {
......
294 291
	public static String createUUID() {
295 292
		// FIXME: see if it's useful to put the class name or not, should be better to save it in the .prefs
296 293
		//this.uniqueID = this.getClass().getName() + '@' + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + UUID.randomUUID();
297
		return UUID_PREFIX + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + UUID.randomUUID();
294
		return UUID_PREFIX + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + nextInt();
298 295
	}
296
	
297
	private static int next = 0;
298
	/**
299
	 * 
300
	 * @return the next integer in the current session of TXM
301
	 */
302
	private static synchronized String nextInt() {
303
		return String.format("%04d", next++);
304
	}
299 305

  
300 306
	/**
301 307
	 * Checks if the result at least one child.
......
546 552
		if (key.isEmpty()) {
547 553
			return false;
548 554
		}
549
//		if (this.isDirty()) {
550
//			return true;
551
//		}
555
		//		if (this.isDirty()) {
556
		//			return true;
557
		//		}
552 558

  
553 559
		Object lastValue = lastParameters.get(key);
554 560
		Object newValue = this.getParameter(key);
......
875 881
		this.saveParameter("class", this.getClass().getName()); //$NON-NLS-1$
876 882

  
877 883
		this.saveParameter(TXMPreferences.RESULT_PARAMETERS_NODE_PATH, this.parametersNodePath);
878
		this.saveParameter(TXMPreferences.RESULT_UUID, this.uniqueID);
879 884
		this.saveParameter(TXMPreferences.BUNDLE_ID, this.commandPreferencesNodePath);
880 885
		if (this.parent != null)	{
881
			this.saveParameter(TXMPreferences.PARENT_UUID, this.parent.getUUID());
886
			this.saveParameter(TXMPreferences.PARENT_UUID, this.parent.getParametersNodePath());
882 887
		}
883 888

  
884 889
		this.lazyName = this.getSimpleName();
......
1164 1169
	 * Deletes all non persistent results and saves the results to persist.
1165 1170
	 */
1166 1171
	public static void deleteAllNonPersistentResults() {
1167
		List<TXMResult> results = Toolbox.workspace.getDeepChildren();
1168
		for (int i = 0; i < results.size(); i++) {
1169
			TXMResult r = results.get(i);
1170
			if (r.mustBePersisted())	{ 
1171
				TXMPreferences.flush(r);
1172
		File logs = new File(System.getProperty("user.home"), "logs.txt");
1173
		PrintWriter w = null;
1174
		try {
1175
			w = IOUtils.getWriter(logs);
1176
			List<TXMResult> todo = Toolbox.workspace.getChildren();
1177
			while (todo.size() > 0) {
1178
				TXMResult r = null;
1179
				try {
1180
					r = todo.remove(0);
1181
					todo.addAll(0, r.getChildren());
1182
					w.println("Persisting? "+r);
1183
					if (r.mustBePersisted())	{ 
1184
						w.println(" YES");
1185
						TXMPreferences.flush(r);
1186
					}
1187
					else {
1188
						w.println(" NO");
1189
						Log.finest("TXMResult.deleteAllNonPersistentResults(): Deleting result " + r.getSimpleName() + " of type " + r.getClass().getSimpleName() + ".");
1190
						TXMPreferences.delete(r);
1191
					}
1192
				} catch (Exception e) {
1193
					w.println(" Error: "+e+" with "+r);
1194
				}
1195
				w.println(" OK: "+r);
1172 1196
			}
1173
			else {
1174
				Log.finest("TXMResult.deleteAllNonPersistentResults(): Deleting result " + r.getSimpleName() + " of type " + r.getClass().getSimpleName() + ".");
1175
				TXMPreferences.delete(r);
1176
			}
1197
		} catch (UnsupportedEncodingException e1) {
1198
			// TODO Auto-generated catch block
1199
			e1.printStackTrace();
1200
		} catch (FileNotFoundException e1) {
1201
			// TODO Auto-generated catch block
1202
			e1.printStackTrace();
1203
		} finally {
1204
			if (w != null) w.close();
1177 1205
		}
1178 1206
	}
1179 1207

  
......
1290 1318
	}
1291 1319

  
1292 1320
	/**
1293
	 * Gets all the children results (nor a clone).
1321
	 * Gets all the children results (not a clone).
1294 1322
	 * 
1295 1323
	 * @return
1296 1324
	 */
......
1400 1428
	 * @param UUID
1401 1429
	 * @return
1402 1430
	 */
1403
	public static TXMResult getResult(TXMResult root, String UUID)	{
1431
	public static TXMResult getResult(TXMResult root, String nodePath)	{
1404 1432
		TXMResult result = null;
1405
		if(root.getUUID().equals(UUID))	{
1433
		if(root.getParametersNodePath().equals(nodePath))	{
1406 1434
			result = root;
1407 1435
		}
1408 1436
		else	{
1409 1437
			List<TXMResult> results = root.getDeepChildren();
1410 1438
			for (int i = 0; i < results.size(); i++) {
1411
				if(results.get(i).getUUID().equals(UUID))	{
1439
				if(results.get(i).getParametersNodePath().equals(nodePath))	{
1412 1440
					result = results.get(i);
1413 1441
					break;
1414 1442
				}
......
1422 1450
	 * @param UUID
1423 1451
	 * @return
1424 1452
	 */
1425
	public static TXMResult getResult(String UUID)	{
1426
		return getResult(Toolbox.workspace, UUID);
1453
	public static TXMResult getResult(String nodePath)	{
1454
		return getResult(Toolbox.workspace, nodePath);
1427 1455
	}
1428 1456

  
1429 1457
	/**
......
1643 1671
		return "..."; //$NON-NLS-1$
1644 1672
	}
1645 1673

  
1646
	/**
1647
	 * Returns a string representation of an unique ID for the result.
1648
	 * 
1649
	 * @return
1650
	 */
1651
	public String getUUID() {
1652
		return this.uniqueID;
1653
	}
1674
//	/**
1675
//	 * Returns a string representation of an unique ID for the result.
1676
//	 * 
1677
//	 * @return
1678
//	 */
1679
//	public String getUUID() {
1680
//		return this.uniqueID;
1681
//	}
1654 1682

  
1655 1683
	/**
1656 1684
	 * Gets a string representing the result that can be used as a file name (eg. for exporting in file).
......
1714 1742
		TXMResult clone = null;
1715 1743
		try {
1716 1744
			clone = (TXMResult) super.clone();
1717
			clone.uniqueID = createUUID();
1745
			clone.parametersNodePath = this.getProject().getParametersNodeRootPath()+ createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$;
1718 1746
			this.parent.addChild(clone);
1719 1747
			TXMPreferences.cloneNode(this, clone);
1720 1748
			clone.dirty = true;
......
1973 2001
	 * Checks if the result must be persisted according to the persistence global preference or the user persistable state.
1974 2002
	 * @return
1975 2003
	 */
1976
//	public boolean mustBePersisted()	{
1977
//		if (this.internalPersistable
1978
//				|| this.userPersistable)	{
1979
//			return true;
1980
//		}
1981
//		return false;
1982
//	}
2004
	//	public boolean mustBePersisted()	{
2005
	//		if (this.internalPersistable
2006
	//				|| this.userPersistable)	{
2007
	//			return true;
2008
	//		}
2009
	//		return false;
2010
	//	}
1983 2011

  
1984 2012
	// FIXME: need to prove this code
1985 2013
	public boolean mustBePersisted()	{
......
2153 2181
		if (e1 == null && e2 == null) return 0;
2154 2182
		if (e1 == null) return 1;
2155 2183

  
2156
		return e1.getUUID().compareTo(e2.getUUID());
2184
		return e1.getParametersNodePath().compareTo(e2.getParametersNodePath());
2157 2185
	}
2158 2186

  
2159 2187
	/**
tmp/org.txm.core/src/java/org/txm/objects/Edition.java (revision 1181)
319 319
	@Override
320 320
	public String toString() {
321 321
		try {
322
			return "Edition [name="+userName+" index=" + pIndex + ", \npages=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
322
			return "Edition [name="+userName+" index=" + pIndex + ", pages=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
323 323
					+ pages.size() + "]"; //$NON-NLS-1$
324 324
		}
325 325
		catch (Exception e) {
tmp/org.txm.core/src/java/org/txm/objects/Project.java (revision 1181)
399 399
				Log.finest("\nProject.loadResults(): loading from result node qualifier " + parametersNodePath);
400 400
				//Log.finest("Toolbox.initialize(): class = " + TXMPreferences.getString("class", nodeQualifier));
401 401
				//TXMPreferences.dump();
402

  
403

  
402
				TXMResult result = TXMResult.getResult(this, parametersNodePath);
403
				if (result != null) { // result already restored
404
					continue;
405
				}
404 406
				Log.finest("Project.loadResults(): class = " + className); //$NON-NLS-1$
405 407
				//					Log.finest("Toolbox.initialize(): parent_uuid = " + TXMPreferences.getString(TXMPreferences.PARENT_UUID, nodeQualifier));
406 408
				Log.finest("Project.loadResults(): parent_uuid = " + TXMPreferences.preferencesRootNode.node(parametersNodePath).get(TXMPreferences.PARENT_UUID, "")); //$NON-NLS-1$
......
414 416

  
415 417
				Class<?> cl = bundle.loadClass(className);
416 418
				Constructor<?> cons = cl.getConstructor(String.class);
417
				TXMResult result = (TXMResult) cons.newInstance(parametersNodePath);
419
				result = (TXMResult) cons.newInstance(parametersNodePath);
418 420

  
419 421
				// not an internal persistence (eg. corpus or partition)
420 422
				if (!result.isInternalPersistable())	{
......
1241 1243
	public IProject getRCPProject() {
1242 1244
		return rcpProject;
1243 1245
	}
1246
	
1247
	public String toString() {
1248
		return this.userName+" "+this.rcpProject.getLocation();
1249
	}
1244 1250
}
tmp/org.txm.core/src/java/org/txm/objects/Text.java (revision 1181)
297 297
	public String getResultype() {
298 298
		return "Text";
299 299
	}
300
	
301
	public String toString() {
302
		return userName+" "+pTXMFile;
303
	}
300 304
}
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 1181)
557 557
				strb.append(property.getName() + " ");
558 558
			}
559 559
			try {
560
				strb.append(this.getFMin() + " / " + this.getNRows());
560
				//strb.append(this.getFMin() + " / " + this.getNRows());
561
				strb.append(this.fMinFilter +" / "+this.vMaxFilter);
561 562
			} catch (Exception e) {
562 563
				// TODO Auto-generated catch block
563 564
				e.printStackTrace();

Formats disponibles : Unified diff