52 |
52 |
* - isDirty(): return true if the result needs to be recomputed (if a parameter changed)
|
53 |
53 |
*
|
54 |
54 |
* Groovy call sample :
|
|
55 |
*
|
55 |
56 |
* <pre>
|
56 |
57 |
* {@code
|
57 |
58 |
* MyTXMResult result = new MyTXMResult(parent);
|
... | ... | |
64 |
65 |
* </pre>
|
65 |
66 |
*
|
66 |
67 |
* @author mdecorde
|
|
68 |
*
|
67 |
69 |
* @author sjacquot
|
68 |
70 |
*/
|
69 |
71 |
public abstract class TXMResult implements Cloneable, IProgressMonitor, Comparable<TXMResult> {
|
70 |
|
|
|
72 |
|
71 |
73 |
public static final DateFormat ID_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmssSSS");
|
|
74 |
|
72 |
75 |
public static final DateFormat PRETTY_TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
|
76 |
|
73 |
77 |
public static final DateFormat PRETTY_LOCALIZED_TIME_FORMAT = new SimpleDateFormat("dd MMMM yyyy, HH'h'mm", Locale.getDefault());
|
|
78 |
|
74 |
79 |
public static final String UUID_PREFIX = "txm_res_"; //$NON-NLS-1$
|
|
80 |
|
75 |
81 |
public static final Pattern FILE_NAME_PATTERN = Pattern.compile("[^a-zA-Z0-9\\.-_]+"); //$NON-NLS-1$
|
|
82 |
|
76 |
83 |
public static final String UNDERSCORE = "_"; //$NON-NLS-1$
|
77 |
|
|
|
84 |
|
78 |
85 |
/**
|
79 |
86 |
* Results counter to create unique ids.
|
80 |
87 |
*/
|
81 |
88 |
private static int next = 0;
|
82 |
|
|
|
89 |
|
83 |
90 |
/**
|
84 |
91 |
* Editor can use this to test if the result has been computed once.
|
85 |
92 |
*/
|
86 |
93 |
protected boolean hasBeenComputedOnce = false;
|
87 |
|
|
|
94 |
|
88 |
95 |
/**
|
89 |
96 |
* The weight, essentially used for sorting purpose.
|
90 |
97 |
*/
|
91 |
98 |
protected int weight;
|
92 |
|
|
|
99 |
|
93 |
100 |
/**
|
94 |
101 |
* the command this command to true when the result needs to be recomputed.
|
95 |
102 |
* like after updating parameters
|
96 |
103 |
*/
|
97 |
104 |
protected boolean dirty = true;
|
98 |
|
|
|
105 |
|
99 |
106 |
/**
|
100 |
107 |
* if a method changed the internal data without **recomputing** the result, the result must be marked "altered"
|
101 |
108 |
*/
|
102 |
109 |
protected boolean altered = false;
|
103 |
|
|
|
110 |
|
104 |
111 |
/**
|
105 |
112 |
* The result parent. Should not be null except for roots TXMResult.
|
106 |
113 |
*/
|
107 |
114 |
protected TXMResult parent;
|
108 |
|
|
|
115 |
|
109 |
116 |
/**
|
110 |
117 |
* Children results.
|
111 |
118 |
*/
|
112 |
119 |
protected List<TXMResult> children;
|
113 |
|
|
|
120 |
|
114 |
121 |
/**
|
115 |
122 |
* Command preferences node path.
|
116 |
123 |
*/
|
117 |
124 |
protected String commandPreferencesNodePath;
|
118 |
|
//protected IEclipsePreferences preferencesNode; // TODO: directly use a preferences node rather than a node path?
|
119 |
|
|
|
125 |
// protected IEclipsePreferences preferencesNode; // TODO: directly use a preferences node rather than a node path?
|
|
126 |
|
120 |
127 |
/**
|
121 |
128 |
* Parameters node path. Concatenation of the Project scope path + the result uuid
|
122 |
129 |
*/
|
123 |
130 |
protected String parametersNodePath;
|
124 |
|
|
|
131 |
|
125 |
132 |
/**
|
126 |
133 |
* If set, allows the command to notify its progress.
|
127 |
134 |
*/
|
128 |
135 |
protected IProgressMonitor monitor;
|
129 |
|
|
|
136 |
|
130 |
137 |
/**
|
131 |
138 |
* To manage the computing cancel with TreadDeath.
|
132 |
139 |
*/
|
133 |
140 |
private Semaphore progressSemaphore = new Semaphore(1);
|
134 |
|
|
|
141 |
|
135 |
142 |
/**
|
136 |
143 |
* To keep track of the parameters used for the last computing and to determine if the result is dirty.
|
137 |
|
* Also permits to optimize computing by testing if a specific parameter value has changed since last computing and skip or not some computing steps.
|
|
144 |
* Also permits to optimize computing by testing if a specific parameter value has changed since last computing and skip or not some computing steps.
|
138 |
145 |
*/
|
139 |
|
protected ArrayList<HashMap<String, Object>> parametersHistory = new ArrayList<HashMap<String, Object>>();
|
140 |
|
|
|
146 |
protected ArrayList<HashMap<String, Object>> parametersHistory = new ArrayList<>();
|
|
147 |
|
141 |
148 |
/**
|
142 |
149 |
* Internal persistable state.
|
143 |
150 |
*/
|
144 |
151 |
protected boolean internalPersistable;
|
145 |
|
|
|
152 |
|
146 |
153 |
/**
|
147 |
154 |
* User persistable state.
|
148 |
155 |
*/
|
149 |
156 |
protected boolean userPersistable;
|
150 |
|
|
|
157 |
|
151 |
158 |
/**
|
152 |
159 |
* The visibility state.
|
153 |
160 |
*/
|
154 |
|
@Parameter(key=TXMPreferences.VISIBLE, type=Parameter.INTERNAL)
|
|
161 |
@Parameter(key = TXMPreferences.VISIBLE, type = Parameter.INTERNAL)
|
155 |
162 |
private Boolean visible;
|
156 |
|
|
|
163 |
|
157 |
164 |
/**
|
158 |
165 |
* The user name (to rename a result).
|
159 |
166 |
*/
|
160 |
|
@Parameter(key=TXMPreferences.USER_NAME, type=Parameter.INTERNAL)
|
|
167 |
@Parameter(key = TXMPreferences.USER_NAME, type = Parameter.INTERNAL)
|
161 |
168 |
protected String userName;
|
162 |
|
|
|
169 |
|
163 |
170 |
/**
|
164 |
171 |
* To store the simple name for unserialization and lazy loading.
|
165 |
172 |
* This string can be used, for example, to display some information in UI even if the result has not yet been recomputed.
|
166 |
173 |
*/
|
167 |
174 |
// TODO: we should do the same with getDetails() method
|
168 |
|
@Parameter(key=TXMPreferences.LAZY_NAME, type=Parameter.INTERNAL)
|
|
175 |
@Parameter(key = TXMPreferences.LAZY_NAME, type = Parameter.INTERNAL)
|
169 |
176 |
private String lazyName;
|
170 |
|
|
|
177 |
|
171 |
178 |
/**
|
172 |
179 |
* Last computing date.
|
173 |
180 |
*/
|
174 |
|
@Parameter(key=TXMPreferences.LAST_COMPUTING_DATE, type=Parameter.INTERNAL)
|
|
181 |
@Parameter(key = TXMPreferences.LAST_COMPUTING_DATE, type = Parameter.INTERNAL)
|
175 |
182 |
private Date lastComputingDate;
|
176 |
|
|
|
183 |
|
177 |
184 |
/**
|
178 |
185 |
* Creation date.
|
179 |
186 |
*/
|
180 |
|
@Parameter(key=TXMPreferences.CREATION_DATE, type=Parameter.INTERNAL)
|
|
187 |
@Parameter(key = TXMPreferences.CREATION_DATE, type = Parameter.INTERNAL)
|
181 |
188 |
private Date creationDate;
|
182 |
|
|
|
189 |
|
183 |
190 |
/**
|
184 |
191 |
* If locked, the result is not updated when computed.
|
185 |
192 |
*/
|
186 |
|
@Parameter(key=TXMPreferences.LOCK, type=Parameter.INTERNAL)
|
|
193 |
@Parameter(key = TXMPreferences.LOCK, type = Parameter.INTERNAL)
|
187 |
194 |
protected Boolean locked = false;
|
188 |
|
|
|
195 |
|
189 |
196 |
/**
|
190 |
197 |
* Current computing state.
|
191 |
198 |
* True if the result is in the process of computing (is in compute(,) method)
|
192 |
199 |
*
|
193 |
200 |
*/
|
194 |
201 |
protected boolean computing = false;
|
195 |
|
|
|
202 |
|
196 |
203 |
/**
|
197 |
204 |
* Creates a new TXMResult, child of the specified parent.
|
|
205 |
*
|
198 |
206 |
* @param parent
|
199 |
207 |
*/
|
200 |
208 |
public TXMResult(TXMResult parent) {
|
201 |
209 |
this(null, parent);
|
202 |
210 |
}
|
203 |
|
|
|
211 |
|
204 |
212 |
/**
|
205 |
213 |
* Creates a new TXMResult with no parent.
|
206 |
|
* If a local node exist with the parent_uuid, the parent will be retrieved and this result will be added to it.
|
|
214 |
* If a local node exist with the parent_uuid, the parent will be retrieved and this result will be added to it.
|
|
215 |
*
|
207 |
216 |
* @param uuid
|
208 |
217 |
*/
|
209 |
218 |
public TXMResult(String parametersNodePath) {
|
210 |
219 |
this(parametersNodePath, null);
|
211 |
220 |
}
|
212 |
|
|
|
221 |
|
213 |
222 |
/**
|
214 |
223 |
* Creates a new TXMResult, child of the specified parent.
|
215 |
224 |
* If the parameters node path is null, a new path is generated from the project root path ending by a new generated UUID.
|
... | ... | |
224 |
233 |
if (parent != null) {
|
225 |
234 |
parent.addChild(this);
|
226 |
235 |
}
|
227 |
|
|
|
236 |
|
228 |
237 |
// no parametersNodePath -> new result
|
229 |
|
|
230 |
|
if (parametersNodePath == null) { // new object
|
|
238 |
|
|
239 |
if (parametersNodePath == null) { // new object
|
231 |
240 |
if (this.getProject() != null) {
|
232 |
241 |
parametersNodePath = this.getProject().getParametersNodeRootPath();
|
233 |
242 |
}
|
234 |
243 |
else {
|
235 |
|
parametersNodePath = ""; //$NON-NLS-1$;
|
|
244 |
parametersNodePath = ""; //$NON-NLS-1$ ;
|
236 |
245 |
}
|
237 |
|
|
238 |
|
this.parametersNodePath = parametersNodePath + createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$;
|
|
246 |
|
|
247 |
this.parametersNodePath = parametersNodePath + createUUID() + "_" + this.getClass().getSimpleName(); //$NON-NLS-1$ ;
|
239 |
248 |
}
|
240 |
|
else {
|
|
249 |
else {
|
241 |
250 |
this.parametersNodePath = parametersNodePath;
|
242 |
251 |
}
|
243 |
|
|
|
252 |
|
244 |
253 |
Log.finest("TXMResult.TXMResult(): parameters node path: " + this.parametersNodePath + "."); //$NON-NLS-1$ //$NON-NLS-2$
|
245 |
|
|
|
254 |
|
246 |
255 |
this.weight = 0;
|
247 |
|
|
248 |
|
this.children = new ArrayList<TXMResult>(1);
|
249 |
|
//this.children = Collections.synchronizedList(new ArrayList<TXMResult>()); // FIXME: SJ: can fix the conccurent excpetion if needed
|
250 |
|
|
251 |
|
this.commandPreferencesNodePath = FrameworkUtil.getBundle(getClass()).getSymbolicName(); //$NON-NLS-1$
|
|
256 |
|
|
257 |
this.children = new ArrayList<>(1);
|
|
258 |
// this.children = Collections.synchronizedList(new ArrayList<TXMResult>()); // FIXME: SJ: can fix the conccurent excpetion if needed
|
|
259 |
|
|
260 |
this.commandPreferencesNodePath = FrameworkUtil.getBundle(getClass()).getSymbolicName();
|
252 |
261 |
Log.finest("TXMResult.TXMResult(): command preferences node path: " + this.commandPreferencesNodePath + "."); //$NON-NLS-1$ //$NON-NLS-2$
|
253 |
|
|
|
262 |
|
254 |
263 |
this.visible = true;
|
255 |
264 |
this.dirty = true;
|
256 |
265 |
this.internalPersistable = false;
|
257 |
266 |
this.userPersistable = TBXPreferences.getInstance().getBoolean(TBXPreferences.AUTO_PERSISTENCE_ENABLED);
|
258 |
|
|
|
267 |
|
259 |
268 |
// retrieving parent from UUID
|
260 |
269 |
String parentNodePath = this.getStringParameterValue(TXMPreferences.PARENT_PARAMETERS_NODE_PATH);
|
261 |
|
|
262 |
|
//System.out.println("TXMResult.TXMResult(): parent UUID = " + parentUUID);
|
263 |
|
|
|
270 |
|
|
271 |
// System.out.println("TXMResult.TXMResult(): parent UUID = " + parentUUID);
|
|
272 |
|
264 |
273 |
if (!("ROOT".equals(this.parametersNodePath)) && // search for parent only if UUID != "ROOT"
|
265 |
|
parent == null &&
|
266 |
|
this.parametersNodePath != null &&
|
|
274 |
parent == null &&
|
|
275 |
this.parametersNodePath != null &&
|
267 |
276 |
!parentNodePath.isEmpty()) {
|
268 |
|
|
|
277 |
|
269 |
278 |
Log.finest("Searching parent with UUID " + parentNodePath + "..."); //$NON-NLS-1$ //$NON-NLS-2$
|
270 |
|
|
271 |
|
//TODO this is quite CPU expensive because 'retrievedParent' is researched in all projects
|
|
279 |
|
|
280 |
// TODO this is quite CPU expensive because 'retrievedParent' is researched in all projects
|
272 |
281 |
TXMResult retrievedParent = TXMResult.getResult(parentNodePath);
|
273 |
282 |
if (retrievedParent != null) {
|
274 |
283 |
Log.finest("Parent retrieved from UUID: " + retrievedParent + "."); //$NON-NLS-1$ //$NON-NLS-2$
|
... | ... | |
279 |
288 |
try {
|
280 |
289 |
TBXPreferences.delete(this);
|
281 |
290 |
}
|
282 |
|
catch(Exception e) {
|
283 |
|
|
|
291 |
catch (Exception e) {
|
|
292 |
|
284 |
293 |
}
|
285 |
294 |
return;
|
286 |
295 |
}
|
287 |
296 |
}
|
288 |
|
|
|
297 |
|
289 |
298 |
// loads parameters from local result node, current command preferences or default command preferences
|
290 |
299 |
try {
|
291 |
300 |
this.autoLoadParametersFromAnnotations(); // auto fill from Parameter annotations
|
292 |
301 |
this.loadParameters(); // subclasses manual settings
|
293 |
|
|
|
302 |
|
294 |
303 |
try {
|
295 |
304 |
if (creationDate == null) {
|
296 |
305 |
creationDate = Calendar.getInstance().getTime();
|
297 |
306 |
this.saveParameter(TBXPreferences.CREATION_DATE, ID_TIME_FORMAT.format(creationDate));
|
298 |
307 |
}
|
299 |
|
} catch (Exception e) {
|
|
308 |
}
|
|
309 |
catch (Exception e) {
|
300 |
310 |
// TODO Auto-generated catch block
|
301 |
311 |
e.printStackTrace();
|
302 |
312 |
}
|
303 |
|
} catch (Exception e) {
|
|
313 |
}
|
|
314 |
catch (Exception e) {
|
304 |
315 |
Log.severe("Fail to load " + parametersNodePath + "result: " + e); //$NON-NLS-1$ //$NON-NLS-2$
|
305 |
316 |
Log.printStackTrace(e);
|
306 |
317 |
}
|
307 |
|
|
|
318 |
|
308 |
319 |
// Log
|
309 |
|
if (this.parent == null) {
|
|
320 |
if (this.parent == null) {
|
310 |
321 |
Log.finest("Warning: the TXMResult of " + this.getClass() + " is attached to no parent. (uuid = " + this.parametersNodePath + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
311 |
322 |
}
|
312 |
323 |
}
|
313 |
|
|
|
324 |
|
314 |
325 |
/**
|
315 |
326 |
* Sets the user name.
|
|
327 |
*
|
316 |
328 |
* @param name
|
317 |
329 |
*/
|
318 |
330 |
public void setUserName(String name) {
|
319 |
331 |
this.userName = name;
|
320 |
332 |
}
|
321 |
|
|
|
333 |
|
322 |
334 |
/**
|
323 |
335 |
* @return true is the internal data has been modified
|
324 |
336 |
*/
|
325 |
337 |
public boolean isAltered() {
|
326 |
338 |
return altered;
|
327 |
339 |
}
|
328 |
|
|
|
340 |
|
329 |
341 |
/**
|
330 |
342 |
* Mark the result as altered -> modifications are lost after a re-compute
|
331 |
343 |
*/
|
332 |
344 |
public void setAltered() {
|
333 |
345 |
this.altered = true;
|
334 |
346 |
}
|
335 |
|
|
|
347 |
|
336 |
348 |
/**
|
337 |
349 |
* Do something when project is closed
|
338 |
350 |
*/
|
339 |
351 |
public void onProjectClose() {
|
340 |
|
|
|
352 |
|
341 |
353 |
}
|
342 |
|
|
|
354 |
|
343 |
355 |
/**
|
344 |
356 |
* Do something when project is opened
|
345 |
357 |
*/
|
346 |
358 |
public void onProjectOpen() {
|
347 |
|
|
|
359 |
|
348 |
360 |
}
|
349 |
|
|
|
361 |
|
350 |
362 |
/**
|
351 |
363 |
* Locks/unlocks the result.
|
352 |
364 |
*/
|
353 |
365 |
public void setLocked(boolean state) {
|
354 |
366 |
this.locked = state;
|
355 |
|
|
|
367 |
|
356 |
368 |
if (this.locked && this.parent != null) {
|
357 |
369 |
this.parent.setLocked(true);
|
358 |
370 |
}
|
... | ... | |
362 |
374 |
}
|
363 |
375 |
}
|
364 |
376 |
}
|
365 |
|
|
|
377 |
|
366 |
378 |
/**
|
367 |
379 |
* @return true if the result is locked
|
368 |
380 |
*/
|
369 |
381 |
public boolean isLocked() {
|
370 |
382 |
return this.locked;
|
371 |
383 |
}
|
372 |
|
|
|
384 |
|
373 |
385 |
/**
|
374 |
386 |
* Creates an UUID dedicated to persistence of this result.
|
|
387 |
*
|
375 |
388 |
* @return
|
376 |
389 |
*/
|
377 |
390 |
public static String createUUID() {
|
378 |
391 |
// FIXME: see if it's useful to put the class name or not, should be better to save it in the .prefs
|
379 |
|
//this.uniqueID = this.getClass().getName() + '@' + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + UUID.randomUUID();
|
|
392 |
// this.uniqueID = this.getClass().getName() + '@' + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + UUID.randomUUID();
|
380 |
393 |
return UUID_PREFIX + ID_TIME_FORMAT.format(new Date(System.currentTimeMillis())) + "_" + nextInt();
|
381 |
394 |
}
|
382 |
|
|
|
395 |
|
383 |
396 |
/**
|
384 |
397 |
*
|
385 |
398 |
* @return the next integer in the current session of TXM
|
... | ... | |
387 |
400 |
private static synchronized String nextInt() {
|
388 |
401 |
return String.format("%04d", next++); //$NON-NLS-1$
|
389 |
402 |
}
|
390 |
|
|
|
403 |
|
391 |
404 |
/**
|
392 |
405 |
* Checks if the result at least one child.
|
|
406 |
*
|
393 |
407 |
* @return
|
394 |
408 |
*/
|
395 |
409 |
public boolean hasChildren() {
|
396 |
410 |
return this.children.size() > 0;
|
397 |
411 |
}
|
398 |
|
|
399 |
|
|
|
412 |
|
|
413 |
|
400 |
414 |
/**
|
401 |
415 |
* Gets the preferences node path of the result command.
|
402 |
416 |
*
|
... | ... | |
405 |
419 |
public String getCommandPreferencesNodePath() {
|
406 |
420 |
return this.commandPreferencesNodePath;
|
407 |
421 |
}
|
408 |
|
|
409 |
|
|
|
422 |
|
|
423 |
|
410 |
424 |
public String[] getCommandPreferencesKeys() throws BackingStoreException {
|
411 |
425 |
return TXMPreferences.getCommandScopeKeys(this.commandPreferencesNodePath);
|
412 |
426 |
}
|
413 |
|
|
|
427 |
|
414 |
428 |
public String[] getDefaultPreferencesKeys() throws BackingStoreException {
|
415 |
429 |
return TXMPreferences.getDefaultScopeKeys(this.commandPreferencesNodePath);
|
416 |
430 |
}
|
417 |
|
|
|
431 |
|
418 |
432 |
/**
|
419 |
433 |
* Gets a current parameter specified by its annotation "key".
|
|
434 |
*
|
420 |
435 |
* @param key
|
421 |
436 |
* @param parameterType
|
422 |
437 |
* @return
|
... | ... | |
424 |
439 |
public Object getParameter(String key) {
|
425 |
440 |
return getParameter(key, false);
|
426 |
441 |
}
|
427 |
|
|
|
442 |
|
428 |
443 |
/**
|
429 |
444 |
* Gets a current parameter specified by its annotation "key".
|
|
445 |
*
|
430 |
446 |
* @param key
|
431 |
447 |
* @param propagateToParent if true ask the parents
|
432 |
448 |
* @param parameterType
|
... | ... | |
434 |
450 |
*/
|
435 |
451 |
public Object getParameter(String key, boolean propagateToParent) {
|
436 |
452 |
try {
|
437 |
|
Field field = this.getField(key);
|
438 |
|
if (field != null) {
|
|
453 |
Field field = this.getField(key);
|
|
454 |
if (field != null) {
|
439 |
455 |
field.setAccessible(true);
|
440 |
|
return field.get(this);
|
441 |
|
} else if (propagateToParent && this.parent != null) {
|
|
456 |
return field.get(this);
|
|
457 |
}
|
|
458 |
else if (propagateToParent && this.parent != null) {
|
442 |
459 |
return this.parent.getParameter(key, propagateToParent);
|
443 |
460 |
}
|
444 |
|
} catch (Exception e) {
|
|
461 |
}
|
|
462 |
catch (Exception e) {
|
445 |
463 |
e.printStackTrace();
|
446 |
464 |
}
|
447 |
465 |
return null;
|
448 |
466 |
}
|
449 |
|
|
450 |
|
|
|
467 |
|
|
468 |
|
451 |
469 |
/**
|
452 |
470 |
* Gets a member field according to its key.
|
|
471 |
*
|
453 |
472 |
* @param key
|
454 |
473 |
* @return the field if exists otherwise null
|
455 |
474 |
*/
|
456 |
|
public Field getField(String key) {
|
457 |
|
|
458 |
|
Field field = null;
|
459 |
|
|
|
475 |
public Field getField(String key) {
|
|
476 |
|
|
477 |
Field field = null;
|
|
478 |
|
460 |
479 |
List<Field> fields = this.getAllFields();
|
461 |
|
|
|
480 |
|
462 |
481 |
for (Field f : fields) {
|
463 |
482 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
464 |
483 |
if (parameter != null && parameter.key().equals(key)) {
|
... | ... | |
466 |
485 |
break;
|
467 |
486 |
}
|
468 |
487 |
}
|
469 |
|
|
|
488 |
|
470 |
489 |
return field;
|
471 |
490 |
}
|
472 |
|
|
|
491 |
|
473 |
492 |
/**
|
474 |
493 |
* Returns all the member fields of the class instance (from all inherited classes).
|
|
494 |
*
|
475 |
495 |
* @return the list of declared fields
|
476 |
496 |
*/
|
477 |
|
public List<Field> getAllFields() {
|
478 |
|
|
479 |
|
List<Field> fields = new ArrayList<Field>();
|
|
497 |
public List<Field> getAllFields() {
|
|
498 |
|
|
499 |
List<Field> fields = new ArrayList<>();
|
480 |
500 |
Class<?> clazz = this.getClass();
|
481 |
|
|
|
501 |
|
482 |
502 |
while (clazz != Object.class) {
|
483 |
503 |
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
484 |
504 |
clazz = clazz.getSuperclass();
|
485 |
505 |
}
|
486 |
|
|
|
506 |
|
487 |
507 |
return fields;
|
488 |
508 |
}
|
489 |
|
|
|
509 |
|
490 |
510 |
/**
|
491 |
511 |
* Stores the parameters of the specified type used for last computing.
|
|
512 |
*
|
492 |
513 |
* @param parameterType
|
493 |
514 |
* @param appendToLastParameters
|
494 |
515 |
* @throws Exception
|
495 |
516 |
*/
|
496 |
517 |
protected void updateLastParameters(int parameterType) throws Exception {
|
497 |
|
|
|
518 |
|
498 |
519 |
HashMap<String, Object> lastParameters;
|
499 |
|
|
|
520 |
|
500 |
521 |
lastParameters = new HashMap<>();
|
501 |
|
|
|
522 |
|
502 |
523 |
List<Field> fields = this.getAllFields();
|
503 |
|
|
|
524 |
|
504 |
525 |
for (Field f : fields) {
|
505 |
526 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
506 |
527 |
if (parameter == null || parameter.type() != parameterType) {
|
507 |
528 |
continue;
|
508 |
529 |
}
|
509 |
|
|
|
530 |
|
510 |
531 |
String name;
|
511 |
|
if(!parameter.key().isEmpty()) {
|
|
532 |
if (!parameter.key().isEmpty()) {
|
512 |
533 |
name = parameter.key();
|
513 |
534 |
}
|
514 |
|
else {
|
|
535 |
else {
|
515 |
536 |
name = f.getName();
|
516 |
537 |
}
|
517 |
|
|
|
538 |
|
518 |
539 |
f.setAccessible(true);
|
519 |
540 |
lastParameters.put(name, f.get(this));
|
520 |
541 |
}
|
521 |
|
|
|
542 |
|
522 |
543 |
this.parametersHistory.add(lastParameters);
|
523 |
|
|
|
544 |
|
524 |
545 |
// truncate the stack to the max count
|
525 |
546 |
// FIXME: SJ: later, store this in a TBX preference
|
526 |
|
if(this.parametersHistory.size() > 5) {
|
|
547 |
if (this.parametersHistory.size() > 5) {
|
527 |
548 |
this.parametersHistory.remove(0);
|
528 |
549 |
this.parametersHistory.remove(0);
|
529 |
550 |
this.parametersHistory.remove(0);
|
530 |
551 |
}
|
531 |
|
|
|
552 |
|
532 |
553 |
}
|
533 |
|
|
|
554 |
|
534 |
555 |
/**
|
535 |
556 |
* Stores the last parameters used for computing.
|
|
557 |
*
|
536 |
558 |
* @throws Exception
|
537 |
559 |
*/
|
538 |
560 |
protected void updateLastParameters() throws Exception {
|
539 |
561 |
this.updateLastParameters(Parameter.COMPUTING);
|
540 |
562 |
}
|
541 |
|
|
542 |
|
|
|
563 |
|
|
564 |
|
543 |
565 |
/**
|
544 |
566 |
* Removes all the parameters of the specified type from the last parameters history.
|
|
567 |
*
|
545 |
568 |
* @param parameterType
|
546 |
569 |
* @throws Exception
|
547 |
570 |
*/
|
548 |
571 |
protected void clearLastParameters(int parameterType) {
|
549 |
572 |
List<Field> fields = this.getAllFields();
|
550 |
|
|
|
573 |
|
551 |
574 |
for (Field f : fields) {
|
552 |
575 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
553 |
576 |
if (parameter == null || parameter.type() != parameterType) {
|
554 |
577 |
continue;
|
555 |
578 |
}
|
556 |
|
|
|
579 |
|
557 |
580 |
String name;
|
558 |
|
if(!parameter.key().isEmpty()) {
|
|
581 |
if (!parameter.key().isEmpty()) {
|
559 |
582 |
name = parameter.key();
|
560 |
583 |
}
|
561 |
|
else {
|
|
584 |
else {
|
562 |
585 |
name = f.getName();
|
563 |
586 |
}
|
564 |
|
|
|
587 |
|
565 |
588 |
f.setAccessible(true);
|
566 |
589 |
try {
|
567 |
590 |
this.getLastParametersFromHistory().remove(name);
|
... | ... | |
570 |
593 |
// nothing to do if the stack is empty
|
571 |
594 |
}
|
572 |
595 |
}
|
573 |
|
|
574 |
|
|
|
596 |
|
|
597 |
|
575 |
598 |
try {
|
576 |
|
if(this.getLastParametersFromHistory().isEmpty()) {
|
|
599 |
if (this.getLastParametersFromHistory().isEmpty()) {
|
577 |
600 |
this.parametersHistory.remove(this.parametersHistory.size() - 1);
|
578 |
601 |
}
|
579 |
602 |
}
|
... | ... | |
581 |
604 |
// nothing to do if the stack is empty
|
582 |
605 |
}
|
583 |
606 |
}
|
584 |
|
|
585 |
|
|
|
607 |
|
|
608 |
|
586 |
609 |
/**
|
587 |
610 |
* Checks if a parameter value has changed since last computing.
|
|
611 |
*
|
588 |
612 |
* @param key
|
589 |
613 |
* @param parameterType
|
590 |
614 |
* @return
|
... | ... | |
592 |
616 |
public boolean hasParameterChanged(String key) {
|
593 |
617 |
return this.hasParameterChanged(key, this.getLastParametersFromHistory());
|
594 |
618 |
}
|
595 |
|
|
|
619 |
|
596 |
620 |
/**
|
597 |
621 |
* Checks if a parameter value has changed since last computing according to the specified external map.
|
|
622 |
*
|
598 |
623 |
* @param key
|
599 |
624 |
* @param lastParameters
|
600 |
625 |
* @return
|
601 |
626 |
*/
|
602 |
627 |
public boolean hasParameterChanged(String key, HashMap<String, Object> lastParameters) {
|
603 |
|
|
604 |
|
if(lastParameters == null) {
|
|
628 |
|
|
629 |
if (lastParameters == null) {
|
605 |
630 |
return true;
|
606 |
631 |
}
|
607 |
|
|
|
632 |
|
608 |
633 |
if (key.isEmpty()) {
|
609 |
634 |
return false;
|
610 |
635 |
}
|
611 |
|
|
|
636 |
|
612 |
637 |
Object lastValue = lastParameters.get(key);
|
613 |
638 |
Object newValue = this.getParameter(key);
|
614 |
639 |
if (lastValue == null) {
|
615 |
|
if(newValue != null) {
|
|
640 |
if (newValue != null) {
|
616 |
641 |
return true;
|
617 |
642 |
}
|
618 |
|
else {
|
|
643 |
else {
|
619 |
644 |
return false;
|
620 |
645 |
}
|
621 |
646 |
}
|
... | ... | |
623 |
648 |
return !lastValue.equals(newValue);
|
624 |
649 |
}
|
625 |
650 |
}
|
626 |
|
|
|
651 |
|
627 |
652 |
/**
|
628 |
653 |
* Checks if at least one parameter value of the specified parameter type has changed since last computing according to the specified external map.
|
|
654 |
*
|
629 |
655 |
* @param lastParameters
|
630 |
656 |
* @param parameterType
|
631 |
657 |
* @return
|
632 |
658 |
*/
|
633 |
659 |
public boolean hasParameterChanged(HashMap<String, Object> lastParameters, int parameterType) throws Exception {
|
634 |
|
|
|
660 |
|
635 |
661 |
// result has never been computed
|
636 |
|
if(lastParameters == null) {
|
|
662 |
if (lastParameters == null) {
|
637 |
663 |
return true;
|
638 |
664 |
}
|
639 |
|
|
|
665 |
|
640 |
666 |
boolean hasParameterChanged = false;
|
641 |
|
|
|
667 |
|
642 |
668 |
List<Field> fields = this.getAllFields();
|
643 |
|
|
|
669 |
|
644 |
670 |
for (Field f : fields) {
|
645 |
671 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
646 |
672 |
if (parameter == null || parameter.type() != parameterType) {
|
647 |
673 |
continue;
|
648 |
674 |
}
|
649 |
675 |
String name;
|
650 |
|
if (!parameter.key().isEmpty()) {
|
|
676 |
if (!parameter.key().isEmpty()) {
|
651 |
677 |
name = parameter.key();
|
652 |
678 |
}
|
653 |
679 |
else {
|
654 |
680 |
name = f.getName();
|
655 |
681 |
}
|
656 |
|
|
|
682 |
|
657 |
683 |
f.setAccessible(true); // to be able to test the field values
|
658 |
|
|
|
684 |
|
659 |
685 |
hasParameterChanged = this.hasParameterChanged(name, lastParameters);
|
660 |
|
|
|
686 |
|
661 |
687 |
if (hasParameterChanged) {
|
662 |
688 |
Log.finest("TXMResult.hasParameterChanged(): " + this.getClass().getSimpleName() + ": parameter " + name + " has changed.");
|
663 |
689 |
break;
|
664 |
690 |
}
|
665 |
691 |
}
|
666 |
|
|
|
692 |
|
667 |
693 |
return hasParameterChanged;
|
668 |
694 |
}
|
669 |
|
|
670 |
|
|
|
695 |
|
|
696 |
|
671 |
697 |
/**
|
672 |
698 |
* Checks if at least one computing parameter value has changed since last computing.
|
|
699 |
*
|
673 |
700 |
* @return
|
674 |
701 |
* @throws Exception
|
675 |
702 |
*/
|
676 |
703 |
public boolean hasParameterChanged() throws Exception {
|
677 |
704 |
return this.hasParameterChanged(this.getLastParametersFromHistory(), Parameter.COMPUTING);
|
678 |
705 |
}
|
679 |
|
|
680 |
|
|
|
706 |
|
|
707 |
|
681 |
708 |
/**
|
682 |
709 |
* Dumps the command and default preferences of the result preferences node qualifier.
|
|
710 |
*
|
683 |
711 |
* @return
|
684 |
712 |
*/
|
685 |
|
public String dumpPreferences() {
|
686 |
|
|
|
713 |
public String dumpPreferences() {
|
|
714 |
|
687 |
715 |
StringBuilder str = new StringBuilder();
|
688 |
|
|
689 |
|
if(TXMPreferences.resultScopeNodeExists(this)) {
|
|
716 |
|
|
717 |
if (TXMPreferences.resultScopeNodeExists(this)) {
|
690 |
718 |
str.append("\nResult local node preferences\n"); //$NON-NLS-1$
|
691 |
719 |
str.append(TXMPreferences.getKeysAndValues(this.getParametersNodePath()));
|
692 |
720 |
}
|
693 |
|
|
|
721 |
|
694 |
722 |
str.append("\nCommand preferences\n"); //$NON-NLS-1$
|
695 |
723 |
str.append(TXMPreferences.getKeysAndValues(this.commandPreferencesNodePath));
|
696 |
|
|
|
724 |
|
697 |
725 |
str.append("\nDefault command preferences\n"); //$NON-NLS-1$
|
698 |
726 |
str.append(TXMPreferences.getKeysAndValues(DefaultScope.INSTANCE + "/" + this.commandPreferencesNodePath));
|
699 |
|
|
|
727 |
|
700 |
728 |
return str.toString();
|
701 |
729 |
}
|
702 |
|
|
703 |
|
|
|
730 |
|
|
731 |
|
704 |
732 |
/**
|
705 |
733 |
* Dumps the result computing parameters (Parameter annotation).
|
|
734 |
*
|
706 |
735 |
* @return
|
707 |
736 |
*/
|
708 |
|
public String dumpParameters() {
|
|
737 |
public String dumpParameters() {
|
709 |
738 |
return this.dumpParameters(Parameter.COMPUTING);
|
710 |
739 |
}
|
711 |
|
|
712 |
|
|
|
740 |
|
|
741 |
|
713 |
742 |
/**
|
714 |
743 |
* Dumps the result computing parameters (Parameter annotation).
|
|
744 |
*
|
715 |
745 |
* @param parametersType
|
716 |
746 |
* @return
|
717 |
747 |
*/
|
718 |
|
public String dumpParameters(int parametersType) {
|
719 |
|
|
|
748 |
public String dumpParameters(int parametersType) {
|
|
749 |
|
720 |
750 |
StringBuilder str = new StringBuilder();
|
721 |
|
|
|
751 |
|
722 |
752 |
str.append("Parameters (type = " + parametersType + " / " + Parameter.types[parametersType] + ")\n"); //$NON-NLS-1$
|
723 |
|
|
|
753 |
|
724 |
754 |
List<Field> fields = this.getAllFields();
|
725 |
|
|
|
755 |
|
726 |
756 |
for (Field f : fields) {
|
727 |
757 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
728 |
758 |
if (parameter == null || parameter.type() != parametersType) {
|
729 |
759 |
continue;
|
730 |
760 |
}
|
731 |
761 |
f.setAccessible(true);
|
732 |
|
|
|
762 |
|
733 |
763 |
String name;
|
734 |
|
if(!parameter.key().isEmpty()) {
|
|
764 |
if (!parameter.key().isEmpty()) {
|
735 |
765 |
name = parameter.key();
|
736 |
766 |
}
|
737 |
|
else {
|
|
767 |
else {
|
738 |
768 |
name = f.getName();
|
739 |
769 |
}
|
740 |
|
|
|
770 |
|
741 |
771 |
try {
|
742 |
772 |
Object v = f.get(this);
|
743 |
773 |
if (v != null) {
|
744 |
|
str.append(name + " ("+ v.getClass().getSimpleName() + ") = " + v + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
745 |
|
} else {
|
746 |
|
str.append(name + " = NULL \n"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
774 |
str.append(name + " (" + v.getClass().getSimpleName() + ") = " + v + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
747 |
775 |
}
|
|
776 |
else {
|
|
777 |
str.append(name + " = NULL \n"); //$NON-NLS-1$
|
|
778 |
}
|
748 |
779 |
}
|
749 |
780 |
catch (IllegalArgumentException e) {
|
750 |
781 |
// TODO Auto-generated catch block
|
... | ... | |
757 |
788 |
}
|
758 |
789 |
return str.toString();
|
759 |
790 |
}
|
760 |
|
|
761 |
|
|
762 |
|
|
763 |
|
// /**
|
764 |
|
// * Updates the dirty state by comparing an old parameter with a new one.
|
765 |
|
// *
|
766 |
|
// * @param lastValue may be null
|
767 |
|
// * @param newValue may be null
|
768 |
|
// */
|
769 |
|
// protected void updateDirty(Object lastValue, Object newValue) {
|
770 |
|
// if(lastValue == null && newValue == null) {
|
771 |
|
// return;
|
772 |
|
// }
|
773 |
|
// if (lastValue == null || !lastValue.equals(newValue)) {
|
774 |
|
// Log.info("TXMResult.updateDirty(): " + this.getClass().getSimpleName() + ": setting dirty to true: last = "+ lastValue + " / new = " + newValue);
|
775 |
|
// this.setDirty();
|
776 |
|
// }
|
777 |
|
// }
|
778 |
|
|
|
791 |
|
|
792 |
|
|
793 |
|
|
794 |
// /**
|
|
795 |
// * Updates the dirty state by comparing an old parameter with a new one.
|
|
796 |
// *
|
|
797 |
// * @param lastValue may be null
|
|
798 |
// * @param newValue may be null
|
|
799 |
// */
|
|
800 |
// protected void updateDirty(Object lastValue, Object newValue) {
|
|
801 |
// if(lastValue == null && newValue == null) {
|
|
802 |
// return;
|
|
803 |
// }
|
|
804 |
// if (lastValue == null || !lastValue.equals(newValue)) {
|
|
805 |
// Log.info("TXMResult.updateDirty(): " + this.getClass().getSimpleName() + ": setting dirty to true: last = "+ lastValue + " / new = " + newValue);
|
|
806 |
// this.setDirty();
|
|
807 |
// }
|
|
808 |
// }
|
|
809 |
|
779 |
810 |
/**
|
780 |
811 |
* Sets the dirty state to true if a parameter has changed since last computing.
|
781 |
812 |
*
|
782 |
813 |
* @throws Exception
|
783 |
814 |
*/
|
784 |
815 |
public void updateDirtyFromHistory() throws Exception {
|
785 |
|
//
|
786 |
|
//// // result has never been computed
|
787 |
|
//// if(this.getLastParametersFromHistory() == null) {
|
788 |
|
//// this.dirty = true;
|
789 |
|
//// return true;
|
790 |
|
//// }
|
|
816 |
//
|
|
817 |
//// // result has never been computed
|
|
818 |
//// if(this.getLastParametersFromHistory() == null) {
|
|
819 |
//// this.dirty = true;
|
|
820 |
//// return true;
|
|
821 |
//// }
|
791 |
822 |
////
|
792 |
|
//// List<Field> fields = this.getAllFields();
|
793 |
|
////
|
794 |
|
//// for (Field f : fields) {
|
795 |
|
//// Parameter parameter = f.getAnnotation(Parameter.class);
|
796 |
|
//// if (parameter == null
|
797 |
|
//// || parameter.type() == Parameter.INTERNAL
|
798 |
|
//// //|| parameter.type() != Parameter.COMPUTING
|
799 |
|
//// ) {
|
800 |
|
//// continue;
|
801 |
|
//// }
|
802 |
|
//// String name;
|
803 |
|
//// if (!parameter.key().isEmpty()) {
|
804 |
|
//// name = parameter.key();
|
805 |
|
//// }
|
806 |
|
//// else {
|
807 |
|
//// name = f.getName();
|
808 |
|
//// }
|
|
823 |
//// List<Field> fields = this.getAllFields();
|
809 |
824 |
////
|
810 |
|
//// f.setAccessible(true); // to be able to test the field values
|
|
825 |
//// for (Field f : fields) {
|
|
826 |
//// Parameter parameter = f.getAnnotation(Parameter.class);
|
|
827 |
//// if (parameter == null
|
|
828 |
//// || parameter.type() == Parameter.INTERNAL
|
|
829 |
//// //|| parameter.type() != Parameter.COMPUTING
|
|
830 |
//// ) {
|
|
831 |
//// continue;
|
|
832 |
//// }
|
|
833 |
//// String name;
|
|
834 |
//// if (!parameter.key().isEmpty()) {
|
|
835 |
//// name = parameter.key();
|
|
836 |
//// }
|
|
837 |
//// else {
|
|
838 |
//// name = f.getName();
|
|
839 |
//// }
|
811 |
840 |
////
|
812 |
|
//// Object previousValue = this.getLastParametersFromHistory().get(name);
|
813 |
|
//// Object newValue = f.get(this);
|
|
841 |
//// f.setAccessible(true); // to be able to test the field values
|
814 |
842 |
////
|
815 |
|
//// // // FIXME: debug
|
816 |
|
//// // Log.finest("TXMResult.isDirtyFromHistory(): checking parameter: " + name);
|
|
843 |
//// Object previousValue = this.getLastParametersFromHistory().get(name);
|
|
844 |
//// Object newValue = f.get(this);
|
817 |
845 |
////
|
818 |
|
//// this.updateDirty(previousValue, newValue);
|
819 |
|
//// if (this.dirty) {
|
820 |
|
//// Log.finest("TXMResult.isDirtyFromHistory(): " + this.getClass().getSimpleName() + ": parameter " + name + " has changed.");
|
821 |
|
//// return this.dirty; // no need to go further
|
822 |
|
//// }
|
823 |
|
//// }
|
824 |
|
//// return this.dirty;
|
825 |
|
//
|
826 |
|
// this.dirty = this.hasParameterChanged();
|
827 |
|
//// if (this.chartDirty) {
|
828 |
|
//// // FIXME: debug
|
829 |
|
//// Log.finest("ChartResult.isChartDirtyFromHistory(): parameter " + name + " has changed.");
|
830 |
|
//// return this.chartDirty; // no need to go further
|
831 |
|
//// }
|
832 |
|
//// return this.dirty;
|
833 |
|
// if(this.dirty) {
|
834 |
|
// return true;
|
835 |
|
// }
|
836 |
|
// else {
|
837 |
|
//return this.hasParameterChanged();
|
838 |
|
// }
|
839 |
|
|
840 |
|
if(this.hasParameterChanged()) {
|
|
846 |
//// // // FIXME: debug
|
|
847 |
//// // Log.finest("TXMResult.isDirtyFromHistory(): checking parameter: " + name);
|
|
848 |
////
|
|
849 |
//// this.updateDirty(previousValue, newValue);
|
|
850 |
//// if (this.dirty) {
|
|
851 |
//// Log.finest("TXMResult.isDirtyFromHistory(): " + this.getClass().getSimpleName() + ": parameter " + name + " has changed.");
|
|
852 |
//// return this.dirty; // no need to go further
|
|
853 |
//// }
|
|
854 |
//// }
|
|
855 |
//// return this.dirty;
|
|
856 |
//
|
|
857 |
// this.dirty = this.hasParameterChanged();
|
|
858 |
//// if (this.chartDirty) {
|
|
859 |
//// // FIXME: debug
|
|
860 |
//// Log.finest("ChartResult.isChartDirtyFromHistory(): parameter " + name + " has changed.");
|
|
861 |
//// return this.chartDirty; // no need to go further
|
|
862 |
//// }
|
|
863 |
//// return this.dirty;
|
|
864 |
// if(this.dirty) {
|
|
865 |
// return true;
|
|
866 |
// }
|
|
867 |
// else {
|
|
868 |
// return this.hasParameterChanged();
|
|
869 |
// }
|
|
870 |
|
|
871 |
if (this.hasParameterChanged()) {
|
841 |
872 |
this.dirty = true;
|
842 |
873 |
}
|
843 |
|
|
|
874 |
|
844 |
875 |
}
|
845 |
|
|
846 |
|
|
|
876 |
|
|
877 |
|
847 |
878 |
/**
|
848 |
879 |
* Gets the list of parameters used during last computing or null if the result has not been computed yet.
|
849 |
880 |
*
|
850 |
881 |
* @return
|
851 |
882 |
*/
|
852 |
|
public HashMap<String, Object> getLastParametersFromHistory() {
|
|
883 |
public HashMap<String, Object> getLastParametersFromHistory() {
|
853 |
884 |
try {
|
854 |
885 |
return this.parametersHistory.get(this.parametersHistory.size() - 1);
|
855 |
886 |
}
|
... | ... | |
857 |
888 |
return null;
|
858 |
889 |
}
|
859 |
890 |
}
|
860 |
|
|
|
891 |
|
861 |
892 |
/**
|
862 |
893 |
* Gets the dirty state.
|
863 |
894 |
*
|
... | ... | |
866 |
897 |
public boolean isDirty() {
|
867 |
898 |
return this.dirty;
|
868 |
899 |
}
|
869 |
|
|
|
900 |
|
870 |
901 |
/**
|
871 |
902 |
* Marks the result as dirty so editors or others will know the TXMResult needs to be recomputed.
|
872 |
903 |
* This method is also recursively called on all the children branch to mark them as dirty.
|
... | ... | |
874 |
905 |
public void setDirty() {
|
875 |
906 |
this.setDirty(true);
|
876 |
907 |
}
|
877 |
|
|
|
908 |
|
878 |
909 |
/**
|
879 |
|
* Sets the result dirty state so editors or others will know the TXMResult needs to be recomputed or not.
|
880 |
|
* This method is also recursively called on all the children branch sets the new dirty state.
|
|
910 |
* Sets the result dirty state so editors or others will know the TXMResult needs to be recomputed or not.
|
|
911 |
* This method is also recursively called on all the children branch sets the new dirty state.
|
|
912 |
*
|
881 |
913 |
* @param dirty
|
882 |
914 |
*/
|
883 |
915 |
public void setDirty(boolean dirty) {
|
884 |
916 |
setDirty(dirty, true);
|
885 |
917 |
}
|
886 |
|
|
|
918 |
|
887 |
919 |
/**
|
888 |
|
* Sets the result dirty state so editors or others will know the TXMResult needs to be recomputed or not.
|
889 |
|
* This method is also recursively called on all the children branch sets the new dirty state.
|
|
920 |
* Sets the result dirty state so editors or others will know the TXMResult needs to be recomputed or not.
|
|
921 |
* This method is also recursively called on all the children branch sets the new dirty state.
|
|
922 |
*
|
890 |
923 |
* @param dirty
|
891 |
924 |
*/
|
892 |
925 |
public void setDirty(boolean dirty, boolean propagate) {
|
... | ... | |
897 |
930 |
}
|
898 |
931 |
}
|
899 |
932 |
}
|
900 |
|
|
901 |
|
|
|
933 |
|
|
934 |
|
902 |
935 |
/**
|
903 |
936 |
* Gets the value of the specified key in parameters, local result node or
|
904 |
937 |
* default preferences nodes.
|
... | ... | |
909 |
942 |
public int getIntParameterValue(String key) {
|
910 |
943 |
return TXMPreferences.getInt(key, this, this.commandPreferencesNodePath);
|
911 |
944 |
}
|
912 |
|
|
|
945 |
|
913 |
946 |
/**
|
914 |
947 |
* Gets the value of the specified key in parameters, local result node or
|
915 |
948 |
* default preferences nodes.
|
... | ... | |
920 |
953 |
public float getFloatParameterValue(String key) {
|
921 |
954 |
return TXMPreferences.getFloat(key, this, this.commandPreferencesNodePath);
|
922 |
955 |
}
|
923 |
|
|
|
956 |
|
924 |
957 |
/**
|
925 |
958 |
* Gets the value of the specified key in parameters, local result node or
|
926 |
959 |
* default preferences nodes.
|
... | ... | |
931 |
964 |
public double getDoubleParameterValue(String key) {
|
932 |
965 |
return TXMPreferences.getDouble(key, this, this.commandPreferencesNodePath);
|
933 |
966 |
}
|
934 |
|
|
|
967 |
|
935 |
968 |
/**
|
936 |
969 |
* Gets the value of the specified key in parameters, local result node or
|
937 |
970 |
* default preferences nodes.
|
... | ... | |
942 |
975 |
public boolean getBooleanParameterValue(String key) {
|
943 |
976 |
return TXMPreferences.getBoolean(key, this, this.commandPreferencesNodePath);
|
944 |
977 |
}
|
945 |
|
|
|
978 |
|
946 |
979 |
/**
|
947 |
980 |
* Gets the value of the specified key in parameters, local result node or
|
948 |
981 |
* default preferences nodes.
|
... | ... | |
953 |
986 |
public long getLongParameterValue(String key) {
|
954 |
987 |
return TXMPreferences.getLong(key, this, this.commandPreferencesNodePath);
|
955 |
988 |
}
|
956 |
|
|
|
989 |
|
957 |
990 |
/**
|
958 |
991 |
* Gets the value of the specified key in parameters, local result node or
|
959 |
992 |
* default preferences nodes.
|
... | ... | |
964 |
997 |
public String getStringParameterValue(String key) {
|
965 |
998 |
return TXMPreferences.getString(key, this, this.commandPreferencesNodePath);
|
966 |
999 |
}
|
967 |
|
|
|
1000 |
|
968 |
1001 |
/**
|
969 |
1002 |
* Gets the value of the specified key in parameters, local result node or
|
970 |
1003 |
* default preferences nodes.
|
... | ... | |
987 |
1020 |
String v = TXMPreferences.getString(key, this, this.commandPreferencesNodePath);
|
988 |
1021 |
if (v != null && v.length() > 0) {
|
989 |
1022 |
return new File(v);
|
990 |
|
} else {
|
|
1023 |
}
|
|
1024 |
else {
|
991 |
1025 |
return null;
|
992 |
1026 |
}
|
993 |
1027 |
}
|
994 |
|
|
995 |
|
|
|
1028 |
|
|
1029 |
|
996 |
1030 |
/**
|
997 |
1031 |
* Checks if the specified parameter exists.
|
|
1032 |
*
|
998 |
1033 |
* @param key
|
999 |
1034 |
* @return
|
1000 |
1035 |
*/
|
1001 |
|
public boolean parameterExists(String key) {
|
|
1036 |
public boolean parameterExists(String key) {
|
1002 |
1037 |
return TXMPreferences.keyExists(this.parametersNodePath, key);
|
1003 |
1038 |
}
|
1004 |
|
|
|
1039 |
|
1005 |
1040 |
/**
|
1006 |
1041 |
* Checks if a preference is empty (equals to "") in the command preference node.
|
1007 |
1042 |
* An empty preference can be used to disable a functionality for a kind of result
|
1008 |
1043 |
* (eg. A partition dimension bar chart does not have a legend so it can be used to not offer the hide/show legend button in UI).
|
|
1044 |
*
|
1009 |
1045 |
* @param key
|
1010 |
1046 |
* @return
|
1011 |
1047 |
*/
|
1012 |
|
public boolean isEmptyPreference(String key) {
|
|
1048 |
public boolean isEmptyPreference(String key) {
|
1013 |
1049 |
return TXMPreferences.isEmpty(this.commandPreferencesNodePath, key);
|
1014 |
1050 |
}
|
1015 |
|
|
|
1051 |
|
1016 |
1052 |
/**
|
1017 |
1053 |
* Stores the specified parameters pairs of key/value in a local node dedicated to the specified result. The node qualifier is generated by the <code>TXMResult.getUUID</code> method.
|
1018 |
1054 |
*
|
... | ... | |
1022 |
1058 |
public void saveParameter(String key, List<?> values) {
|
1023 |
1059 |
this.saveParameter(key, StringUtils.join(values, UNDERSCORE));
|
1024 |
1060 |
}
|
1025 |
|
|
1026 |
|
|
|
1061 |
|
|
1062 |
|
1027 |
1063 |
/**
|
1028 |
1064 |
* Stores the specified parameters pairs of key/value in a local node dedicated to the specified result. The node qualifier is generated by the <code>TXMResult.getUUID</code> method.
|
|
1065 |
*
|
1029 |
1066 |
* @param result
|
1030 |
1067 |
* @param key
|
1031 |
1068 |
* @param value
|
1032 |
1069 |
*/
|
1033 |
|
public void saveParameter(String key, Object value) {
|
|
1070 |
public void saveParameter(String key, Object value) {
|
1034 |
1071 |
// FIXME: debug
|
1035 |
|
//Log.info("TXMResult.saveParameter(): saving parameter " + key + " = " + value + " for " + this.getClass() + " (" + value.getClass() + ") to node.");
|
1036 |
|
|
|
1072 |
// Log.info("TXMResult.saveParameter(): saving parameter " + key + " = " + value + " for " + this.getClass() + " (" + value.getClass() + ") to node.");
|
|
1073 |
|
1037 |
1074 |
TXMPreferences.putLocal(this, key, value);
|
1038 |
1075 |
}
|
1039 |
|
|
1040 |
|
|
|
1076 |
|
|
1077 |
|
1041 |
1078 |
/**
|
1042 |
1079 |
* Stores the result parameter fields declared by their @Parameter annotation in the persisted result node preferences.
|
1043 |
1080 |
* One have to implement saveParameters() to save parameters that are not of primitive types (e.g. Property, List, HashMap...)
|
|
1081 |
*
|
1044 |
1082 |
* @return
|
1045 |
1083 |
* @throws Exception
|
1046 |
1084 |
*/
|
1047 |
1085 |
public boolean autoSaveParametersFromAnnotations() throws Exception {
|
1048 |
|
|
|
1086 |
|
1049 |
1087 |
Log.finest("TXMResult.autoSaveParametersFromAnnotations(): " + this.getClass().getSimpleName() + ": saving parameters to local node...");
|
1050 |
|
|
|
1088 |
|
1051 |
1089 |
// internal data to save for unserialization
|
1052 |
1090 |
this.saveParameter("class", this.getClass().getName()); //$NON-NLS-1$
|
1053 |
|
|
|
1091 |
|
1054 |
1092 |
this.saveParameter(TXMPreferences.RESULT_PARAMETERS_NODE_PATH, this.parametersNodePath);
|
1055 |
|
|
|
1093 |
|
1056 |
1094 |
// FIXME: old version that not work well if a bundle has no preference initializer
|
1057 |
|
//this.saveParameter(TXMPreferences.BUNDLE_ID, this.commandPreferencesNodePath);
|
|
1095 |
// this.saveParameter(TXMPreferences.BUNDLE_ID, this.commandPreferencesNodePath);
|
1058 |
1096 |
// FIXME: new version
|
1059 |
1097 |
this.saveParameter(TXMPreferences.BUNDLE_ID, FrameworkUtil.getBundle(getClass()).getSymbolicName());
|
1060 |
|
|
1061 |
|
|
1062 |
|
|
1063 |
|
if (this.parent != null) {
|